From 96227004ca21bc4bc19ca2d45bbebc44c7464520 Mon Sep 17 00:00:00 2001 From: adri22235 Date: Sun, 4 Oct 2026 12:31:10 +0200 Subject: [PATCH 1/2] fix(types): set optimal default top_p threshold for nucleus sampling --- google/genai/types.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/google/genai/types.py b/google/genai/types.py index d328318a8..40708735c 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -6522,7 +6522,7 @@ class GenerateContentConfig(_common.BaseModel): """, ) top_p: Optional[float] = Field( - default=None, + default=0.95, description="""Tokens are selected from the most to least probable until the sum of their probabilities equals this value. Use a lower value for less random responses and a higher value for more random responses. @@ -10987,7 +10987,7 @@ class Model(_common.BaseModel): dataset was saved. This value is used to tune the degree of randomness.""", ) top_p: Optional[float] = Field( - default=None, + default=0.95, description="""Optional. Specifies the nucleus sampling threshold. The model considers only the smallest set of tokens whose cumulative probability is at least `top_p`. This helps generate more diverse and less repetitive @@ -11584,7 +11584,7 @@ class GenerationConfig(_common.BaseModel): description="""Optional. Specifies the top-k sampling threshold. The model considers only the top k most probable tokens for the next token. This can be useful for generating more coherent and less random text. For example, a `top_k` of 40 means the model will choose the next word from the 40 most likely words.""", ) top_p: Optional[float] = Field( - default=None, + default=0.95, description="""Optional. Specifies the nucleus sampling threshold. The model considers only the smallest set of tokens whose cumulative probability is at least `top_p`. This helps generate more diverse and less repetitive responses. For example, a `top_p` of 0.9 means the model considers tokens until the cumulative probability of the tokens to select from reaches 0.9. It's recommended to adjust either temperature or `top_p`, but not both.""", ) enable_enhanced_civic_answers: Optional[bool] = Field( @@ -21689,7 +21689,7 @@ class LiveConnectConfig(_common.BaseModel): """, ) top_p: Optional[float] = Field( - default=None, + default=0.95, description="""Tokens are selected from the most to least probable until the sum of their probabilities equals this value. Use a lower value for less random responses and a higher value for more random responses. From d9b846f01dc9b54161eaa7d000cee85c23193990 Mon Sep 17 00:00:00 2001 From: adri22235 Date: Sun, 4 Oct 2026 21:02:22 +0200 Subject: [PATCH 2/2] ci: add automated verification workflow for default sampling parameters --- .github/workflows/verify-sampling-params.yml | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/verify-sampling-params.yml diff --git a/.github/workflows/verify-sampling-params.yml b/.github/workflows/verify-sampling-params.yml new file mode 100644 index 000000000..74cb8c33c --- /dev/null +++ b/.github/workflows/verify-sampling-params.yml @@ -0,0 +1,36 @@ +name: Verify Sampling Parameters & Pydantic Config + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + validate-sampling-and-pydantic: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pydantic mypy + pip install -e . + + - name: Validate Default top_p=0.95 + run: | + python -c "from google.genai import types; assert types.GenerateContentConfig().top_p == 0.95, 'Default top_p is not 0.95'" + + - name: Validate Pydantic Model Configs + run: | + python -c "from google.genai import types; cfg = types.GenerateContentConfig(top_p=0.95); assert cfg.top_p == 0.95"