Skip to content

Commit 05f16fe

Browse files
google-genai-botcopybara-github
authored andcommitted
feat(interaction-api): Add presence_penalty, frequency_penalty, and cached_content to models.proto
PiperOrigin-RevId: 927640166
1 parent 3900799 commit 05f16fe

5 files changed

Lines changed: 90 additions & 0 deletions

File tree

google/genai/_interactions/resources/interactions.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def create(
8080
input: interaction_create_params.Input,
8181
model: ModelParam,
8282
background: bool | Omit = omit,
83+
cached_content: str | Omit = omit,
8384
environment: interaction_create_params.Environment | Omit = omit,
8485
generation_config: GenerationConfigParam | Omit = omit,
8586
previous_interaction_id: str | Omit = omit,
@@ -109,6 +110,12 @@ def create(
109110
110111
background: Input only. Whether to run the model interaction in the background.
111112
113+
cached_content:
114+
The name of the cached content used as context to serve the prediction. Note:
115+
only used in explicit caching, where users can have control over caching (e.g.
116+
what content to cache) and enjoy guaranteed cost savings. Format:
117+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
118+
112119
environment: The environment configuration for the interaction. Can be an object specifying
113120
remote environment sources or a string referencing an existing environment ID.
114121
@@ -155,6 +162,7 @@ def create(
155162
model: ModelParam,
156163
stream: Literal[True],
157164
background: bool | Omit = omit,
165+
cached_content: str | Omit = omit,
158166
environment: interaction_create_params.Environment | Omit = omit,
159167
generation_config: GenerationConfigParam | Omit = omit,
160168
previous_interaction_id: str | Omit = omit,
@@ -185,6 +193,12 @@ def create(
185193
186194
background: Input only. Whether to run the model interaction in the background.
187195
196+
cached_content:
197+
The name of the cached content used as context to serve the prediction. Note:
198+
only used in explicit caching, where users can have control over caching (e.g.
199+
what content to cache) and enjoy guaranteed cost savings. Format:
200+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
201+
188202
environment: The environment configuration for the interaction. Can be an object specifying
189203
remote environment sources or a string referencing an existing environment ID.
190204
@@ -393,6 +407,7 @@ def create(
393407
model: ModelParam,
394408
stream: bool,
395409
background: bool | Omit = omit,
410+
cached_content: str | Omit = omit,
396411
environment: interaction_create_params.Environment | Omit = omit,
397412
generation_config: GenerationConfigParam | Omit = omit,
398413
previous_interaction_id: str | Omit = omit,
@@ -423,6 +438,12 @@ def create(
423438
424439
background: Input only. Whether to run the model interaction in the background.
425440
441+
cached_content:
442+
The name of the cached content used as context to serve the prediction. Note:
443+
only used in explicit caching, where users can have control over caching (e.g.
444+
what content to cache) and enjoy guaranteed cost savings. Format:
445+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
446+
426447
environment: The environment configuration for the interaction. Can be an object specifying
427448
remote environment sources or a string referencing an existing environment ID.
428449
@@ -466,6 +487,7 @@ def create(
466487
input: interaction_create_params.Input,
467488
model: ModelParam | Omit = omit,
468489
background: bool | Omit = omit,
490+
cached_content: str | Omit = omit,
469491
environment: interaction_create_params.Environment | Omit = omit,
470492
generation_config: GenerationConfigParam | Omit = omit,
471493
previous_interaction_id: str | Omit = omit,
@@ -526,6 +548,7 @@ def create(
526548
"input": input,
527549
"model": model,
528550
"background": background,
551+
"cached_content": cached_content,
529552
"environment": environment,
530553
"generation_config": generation_config,
531554
"previous_interaction_id": previous_interaction_id,
@@ -827,6 +850,7 @@ async def create(
827850
input: interaction_create_params.Input,
828851
model: ModelParam,
829852
background: bool | Omit = omit,
853+
cached_content: str | Omit = omit,
830854
environment: interaction_create_params.Environment | Omit = omit,
831855
generation_config: GenerationConfigParam | Omit = omit,
832856
previous_interaction_id: str | Omit = omit,
@@ -856,6 +880,12 @@ async def create(
856880
857881
background: Input only. Whether to run the model interaction in the background.
858882
883+
cached_content:
884+
The name of the cached content used as context to serve the prediction. Note:
885+
only used in explicit caching, where users can have control over caching (e.g.
886+
what content to cache) and enjoy guaranteed cost savings. Format:
887+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
888+
859889
environment: The environment configuration for the interaction. Can be an object specifying
860890
remote environment sources or a string referencing an existing environment ID.
861891
@@ -902,6 +932,7 @@ async def create(
902932
model: ModelParam,
903933
stream: Literal[True],
904934
background: bool | Omit = omit,
935+
cached_content: str | Omit = omit,
905936
environment: interaction_create_params.Environment | Omit = omit,
906937
generation_config: GenerationConfigParam | Omit = omit,
907938
previous_interaction_id: str | Omit = omit,
@@ -932,6 +963,12 @@ async def create(
932963
933964
background: Input only. Whether to run the model interaction in the background.
934965
966+
cached_content:
967+
The name of the cached content used as context to serve the prediction. Note:
968+
only used in explicit caching, where users can have control over caching (e.g.
969+
what content to cache) and enjoy guaranteed cost savings. Format:
970+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
971+
935972
environment: The environment configuration for the interaction. Can be an object specifying
936973
remote environment sources or a string referencing an existing environment ID.
937974
@@ -1140,6 +1177,7 @@ async def create(
11401177
model: ModelParam,
11411178
stream: bool,
11421179
background: bool | Omit = omit,
1180+
cached_content: str | Omit = omit,
11431181
environment: interaction_create_params.Environment | Omit = omit,
11441182
generation_config: GenerationConfigParam | Omit = omit,
11451183
previous_interaction_id: str | Omit = omit,
@@ -1170,6 +1208,12 @@ async def create(
11701208
11711209
background: Input only. Whether to run the model interaction in the background.
11721210
1211+
cached_content:
1212+
The name of the cached content used as context to serve the prediction. Note:
1213+
only used in explicit caching, where users can have control over caching (e.g.
1214+
what content to cache) and enjoy guaranteed cost savings. Format:
1215+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
1216+
11731217
environment: The environment configuration for the interaction. Can be an object specifying
11741218
remote environment sources or a string referencing an existing environment ID.
11751219
@@ -1213,6 +1257,7 @@ async def create(
12131257
input: interaction_create_params.Input,
12141258
model: ModelParam | Omit = omit,
12151259
background: bool | Omit = omit,
1260+
cached_content: str | Omit = omit,
12161261
environment: interaction_create_params.Environment | Omit = omit,
12171262
generation_config: GenerationConfigParam | Omit = omit,
12181263
previous_interaction_id: str | Omit = omit,
@@ -1269,6 +1314,7 @@ async def create(
12691314
"input": input,
12701315
"model": model,
12711316
"background": background,
1317+
"cached_content": cached_content,
12721318
"environment": environment,
12731319
"generation_config": generation_config,
12741320
"previous_interaction_id": previous_interaction_id,

google/genai/_interactions/types/generation_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,26 @@
3333
class GenerationConfig(BaseModel):
3434
"""Configuration parameters for model interactions."""
3535

36+
frequency_penalty: Optional[float] = None
37+
"""
38+
Penalizes tokens based on their frequency in the generated text. A positive
39+
value helps to reduce the repetition of words and phrases. Valid values can
40+
range from [-2.0, 2.0].
41+
"""
42+
3643
image_config: Optional[ImageConfig] = None
3744
"""Configuration for image interaction."""
3845

3946
max_output_tokens: Optional[int] = None
4047
"""The maximum number of tokens to include in the response."""
4148

49+
presence_penalty: Optional[float] = None
50+
"""Penalizes tokens that have already appeared in the generated text.
51+
52+
A positive value encourages the model to generate more diverse and less
53+
repetitive text. Valid values can range from [-2.0, 2.0].
54+
"""
55+
4256
seed: Optional[int] = None
4357
"""Seed used in decoding for reproducibility."""
4458

google/genai/_interactions/types/generation_config_param.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,26 @@
3535
class GenerationConfigParam(TypedDict, total=False):
3636
"""Configuration parameters for model interactions."""
3737

38+
frequency_penalty: float
39+
"""
40+
Penalizes tokens based on their frequency in the generated text. A positive
41+
value helps to reduce the repetition of words and phrases. Valid values can
42+
range from [-2.0, 2.0].
43+
"""
44+
3845
image_config: ImageConfigParam
3946
"""Configuration for image interaction."""
4047

4148
max_output_tokens: int
4249
"""The maximum number of tokens to include in the response."""
4350

51+
presence_penalty: float
52+
"""Penalizes tokens that have already appeared in the generated text.
53+
54+
A positive value encourages the model to generate more diverse and less
55+
repetitive text. Valid values can range from [-2.0, 2.0].
56+
"""
57+
4458
seed: int
4559
"""Seed used in decoding for reproducibility."""
4660

google/genai/_interactions/types/interaction.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ class Interaction(BaseModel):
260260
agent_config: Optional[AgentConfig] = None
261261
"""Configuration parameters for the agent interaction."""
262262

263+
cached_content: Optional[str] = None
264+
"""
265+
The name of the cached content used as context to serve the prediction. Note:
266+
only used in explicit caching, where users can have control over caching (e.g.
267+
what content to cache) and enjoy guaranteed cost savings. Format:
268+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
269+
"""
270+
263271
environment: Optional[Environment] = None
264272
"""The environment configuration for the interaction.
265273

google/genai/_interactions/types/interaction_create_params.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ class BaseCreateModelInteractionParams(TypedDict, total=False):
7171
background: bool
7272
"""Input only. Whether to run the model interaction in the background."""
7373

74+
cached_content: str
75+
"""
76+
The name of the cached content used as context to serve the prediction. Note:
77+
only used in explicit caching, where users can have control over caching (e.g.
78+
what content to cache) and enjoy guaranteed cost savings. Format:
79+
`projects/{project}/locations/{location}/cachedContents/{cachedContent}`
80+
"""
81+
7482
environment: Environment
7583
"""The environment configuration for the interaction.
7684

0 commit comments

Comments
 (0)