Skip to content

Commit d6238e4

Browse files
feat: [google-ai-generativelanguage] Add GoogleSearchRetrieval tool and candidate.grounding_metadata (googleapis#13098)
BEGIN_COMMIT_OVERRIDE feat: Add GoogleSearchRetrieval tool and candidate.grounding_metadata feat: Add Schema.min_items feat: Add GenerationConfig.{presence_penalty, frequency_penalty, logprobs, response_logprobs, logprobs} and Candidate.{avg_logprobs, logprobs_result} feat: Add PredictionService (for Imagen) feat: Add HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY feat: Add HarmBlockThreshold.OFF feat: Add TunedModels.reader_project_numbers docs: Small fixes docs: Tag HarmCategories by the model family they're used on. END_COMMIT_OVERRIDE - [ ] Regenerate this pull request now. feat: Add Schema.min_items feat: Add GenerationConfig.{presence_penalty, frequency_penalty, logprobs, response_logprobs, logprobs} and Candidate.{avg_logprobs, logprobs_result} feat: Add PredictionService (for Imagen) feat: Add HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY feat: Add HarmBlockThreshold.OFF feat: Add TunedModels.reader_project_numbers docs: Small fixes docs: Tag HarmCategories by the model family they're used on. PiperOrigin-RevId: 676982731 Source-Link: googleapis/googleapis@979f71c Source-Link: https://github.com/googleapis/googleapis-gen/commit/f5e280f1d6258abe58a0b910102e97ce8d82d948 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiZjVlMjgwZjFkNjI1OGFiZTU4YTBiOTEwMTAyZTk3Y2U4ZDgyZDk0OCJ9 BEGIN_NESTED_COMMIT feat: [google-ai-generativelanguage] Add GenerationConfig.{presence_penalty, frequency_penalty, logprobs, response_logprobs, logprobs} and Candidate.{avg_logprobs, logprobs_result} feat: Add HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY docs: Tag HarmCategories by the model family they're used on. feat: Add HarmBlockThreshold.OFF docs: Small fixes PiperOrigin-RevId: 676980561 Source-Link: googleapis/googleapis@1cb097e Source-Link: https://github.com/googleapis/googleapis-gen/commit/04d3969939b2bf4e3db9f1aef88d18a9bedc8ae7 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiMDRkMzk2OTkzOWIyYmY0ZTNkYjlmMWFlZjg4ZDE4YTliZWRjOGFlNyJ9 END_NESTED_COMMIT --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: ohmayr <omairnaveed@ymail.com>
1 parent e889809 commit d6238e4

40 files changed

Lines changed: 6100 additions & 51 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
PredictionService
2+
-----------------------------------
3+
4+
.. automodule:: google.ai.generativelanguage_v1beta.services.prediction_service
5+
:members:
6+
:inherited-members:

packages/google-ai-generativelanguage/docs/generativelanguage_v1beta/services_.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Services for Google Ai Generativelanguage v1beta API
99
generative_service
1010
model_service
1111
permission_service
12+
prediction_service
1213
retriever_service
1314
text_service

packages/google-ai-generativelanguage/google/ai/generativelanguage/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
from google.ai.generativelanguage_v1beta.services.permission_service.client import (
5555
PermissionServiceClient,
5656
)
57+
from google.ai.generativelanguage_v1beta.services.prediction_service.async_client import (
58+
PredictionServiceAsyncClient,
59+
)
60+
from google.ai.generativelanguage_v1beta.services.prediction_service.client import (
61+
PredictionServiceClient,
62+
)
5763
from google.ai.generativelanguage_v1beta.services.retriever_service.async_client import (
5864
RetrieverServiceAsyncClient,
5965
)
@@ -84,12 +90,14 @@
8490
CodeExecution,
8591
CodeExecutionResult,
8692
Content,
93+
DynamicRetrievalConfig,
8794
ExecutableCode,
8895
FileData,
8996
FunctionCall,
9097
FunctionCallingConfig,
9198
FunctionDeclaration,
9299
FunctionResponse,
100+
GoogleSearchRetrieval,
93101
GroundingPassage,
94102
GroundingPassages,
95103
Part,
@@ -132,6 +140,13 @@
132140
GenerateContentResponse,
133141
GenerationConfig,
134142
GroundingAttribution,
143+
GroundingChunk,
144+
GroundingMetadata,
145+
GroundingSupport,
146+
LogprobsResult,
147+
RetrievalMetadata,
148+
SearchEntryPoint,
149+
Segment,
135150
SemanticRetrieverConfig,
136151
TaskType,
137152
)
@@ -159,6 +174,10 @@
159174
TransferOwnershipResponse,
160175
UpdatePermissionRequest,
161176
)
177+
from google.ai.generativelanguage_v1beta.types.prediction_service import (
178+
PredictRequest,
179+
PredictResponse,
180+
)
162181
from google.ai.generativelanguage_v1beta.types.retriever import (
163182
Chunk,
164183
ChunkData,
@@ -243,6 +262,8 @@
243262
"ModelServiceAsyncClient",
244263
"PermissionServiceClient",
245264
"PermissionServiceAsyncClient",
265+
"PredictionServiceClient",
266+
"PredictionServiceAsyncClient",
246267
"RetrieverServiceClient",
247268
"RetrieverServiceAsyncClient",
248269
"TextServiceClient",
@@ -260,12 +281,14 @@
260281
"CodeExecution",
261282
"CodeExecutionResult",
262283
"Content",
284+
"DynamicRetrievalConfig",
263285
"ExecutableCode",
264286
"FileData",
265287
"FunctionCall",
266288
"FunctionCallingConfig",
267289
"FunctionDeclaration",
268290
"FunctionResponse",
291+
"GoogleSearchRetrieval",
269292
"GroundingPassage",
270293
"GroundingPassages",
271294
"Part",
@@ -303,6 +326,13 @@
303326
"GenerateContentResponse",
304327
"GenerationConfig",
305328
"GroundingAttribution",
329+
"GroundingChunk",
330+
"GroundingMetadata",
331+
"GroundingSupport",
332+
"LogprobsResult",
333+
"RetrievalMetadata",
334+
"SearchEntryPoint",
335+
"Segment",
306336
"SemanticRetrieverConfig",
307337
"TaskType",
308338
"Model",
@@ -325,6 +355,8 @@
325355
"TransferOwnershipRequest",
326356
"TransferOwnershipResponse",
327357
"UpdatePermissionRequest",
358+
"PredictRequest",
359+
"PredictResponse",
328360
"Chunk",
329361
"ChunkData",
330362
"Condition",

packages/google-ai-generativelanguage/google/ai/generativelanguage/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.6.9" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
GenerateContentRequest,
3838
GenerateContentResponse,
3939
GenerationConfig,
40+
LogprobsResult,
4041
TaskType,
4142
)
4243
from .types.model import Model
@@ -66,6 +67,7 @@
6667
"HarmCategory",
6768
"ListModelsRequest",
6869
"ListModelsResponse",
70+
"LogprobsResult",
6971
"Model",
7072
"ModelServiceClient",
7173
"Part",

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "0.6.9" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/generative_service/transports/rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,10 @@ def __call__(
10571057
"method": "get",
10581058
"uri": "/v1/{name=tunedModels/*/operations/*}",
10591059
},
1060+
{
1061+
"method": "get",
1062+
"uri": "/v1/{name=generatedFiles/*}/operations/*",
1063+
},
10601064
]
10611065

10621066
request, metadata = self._interceptor.pre_get_operation(request, metadata)

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/services/model_service/transports/rest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ def __call__(
572572
"method": "get",
573573
"uri": "/v1/{name=tunedModels/*/operations/*}",
574574
},
575+
{
576+
"method": "get",
577+
"uri": "/v1/{name=generatedFiles/*}/operations/*",
578+
},
575579
]
576580

577581
request, metadata = self._interceptor.pre_get_operation(request, metadata)

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
GenerateContentRequest,
2828
GenerateContentResponse,
2929
GenerationConfig,
30+
LogprobsResult,
3031
TaskType,
3132
)
3233
from .model import Model
@@ -50,6 +51,7 @@
5051
"GenerateContentRequest",
5152
"GenerateContentResponse",
5253
"GenerationConfig",
54+
"LogprobsResult",
5355
"TaskType",
5456
"Model",
5557
"GetModelRequest",

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1/types/generative_service.py

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"GenerationConfig",
3232
"GenerateContentResponse",
3333
"Candidate",
34+
"LogprobsResult",
3435
"EmbedContentRequest",
3536
"ContentEmbedding",
3637
"EmbedContentResponse",
@@ -228,6 +229,58 @@ class GenerationConfig(proto.Message):
228229
doesn't allow setting ``top_k`` on requests.
229230
230231
This field is a member of `oneof`_ ``_top_k``.
232+
presence_penalty (float):
233+
Optional. Presence penalty applied to the next token's
234+
logprobs if the token has already been seen in the response.
235+
236+
This penalty is binary on/off and not dependant on the
237+
number of times the token is used (after the first). Use
238+
[frequency_penalty][google.ai.generativelanguage.v1.GenerationConfig.frequency_penalty]
239+
for a penalty that increases with each use.
240+
241+
A positive penalty will discourage the use of tokens that
242+
have already been used in the response, increasing the
243+
vocabulary.
244+
245+
A negative penalty will encourage the use of tokens that
246+
have already been used in the response, decreasing the
247+
vocabulary.
248+
249+
This field is a member of `oneof`_ ``_presence_penalty``.
250+
frequency_penalty (float):
251+
Optional. Frequency penalty applied to the next token's
252+
logprobs, multiplied by the number of times each token has
253+
been seen in the respponse so far.
254+
255+
A positive penalty will discourage the use of tokens that
256+
have already been used, proportional to the number of times
257+
the token has been used: The more a token is used, the more
258+
dificult it is for the model to use that token again
259+
increasing the vocabulary of responses.
260+
261+
Caution: A *negative* penalty will encourage the model to
262+
reuse tokens proportional to the number of times the token
263+
has been used. Small negative values will reduce the
264+
vocabulary of a response. Larger negative values will cause
265+
the model to start repeating a common token until it hits
266+
the
267+
[max_output_tokens][google.ai.generativelanguage.v1.GenerationConfig.max_output_tokens]
268+
limit: "...the the the the the...".
269+
270+
This field is a member of `oneof`_ ``_frequency_penalty``.
271+
response_logprobs (bool):
272+
Optional. If true, export the logprobs
273+
results in response.
274+
275+
This field is a member of `oneof`_ ``_response_logprobs``.
276+
logprobs (int):
277+
Optional. Only valid if
278+
[response_logprobs=True][google.ai.generativelanguage.v1.GenerationConfig.response_logprobs].
279+
This sets the number of top logprobs to return at each
280+
decoding step in the
281+
[Candidate.logprobs_result][google.ai.generativelanguage.v1.Candidate.logprobs_result].
282+
283+
This field is a member of `oneof`_ ``_logprobs``.
231284
"""
232285

233286
candidate_count: int = proto.Field(
@@ -259,6 +312,26 @@ class GenerationConfig(proto.Message):
259312
number=7,
260313
optional=True,
261314
)
315+
presence_penalty: float = proto.Field(
316+
proto.FLOAT,
317+
number=15,
318+
optional=True,
319+
)
320+
frequency_penalty: float = proto.Field(
321+
proto.FLOAT,
322+
number=16,
323+
optional=True,
324+
)
325+
response_logprobs: bool = proto.Field(
326+
proto.BOOL,
327+
number=17,
328+
optional=True,
329+
)
330+
logprobs: int = proto.Field(
331+
proto.INT32,
332+
number=18,
333+
optional=True,
334+
)
262335

263336

264337
class GenerateContentResponse(proto.Message):
@@ -414,6 +487,11 @@ class Candidate(proto.Message):
414487
foundational LLM's training data.
415488
token_count (int):
416489
Output only. Token count for this candidate.
490+
avg_logprobs (float):
491+
Output only.
492+
logprobs_result (google.ai.generativelanguage_v1.types.LogprobsResult):
493+
Output only. Log-likelihood scores for the
494+
response tokens and top tokens
417495
"""
418496

419497
class FinishReason(proto.Enum):
@@ -494,6 +572,89 @@ class FinishReason(proto.Enum):
494572
proto.INT32,
495573
number=7,
496574
)
575+
avg_logprobs: float = proto.Field(
576+
proto.DOUBLE,
577+
number=10,
578+
)
579+
logprobs_result: "LogprobsResult" = proto.Field(
580+
proto.MESSAGE,
581+
number=11,
582+
message="LogprobsResult",
583+
)
584+
585+
586+
class LogprobsResult(proto.Message):
587+
r"""Logprobs Result
588+
589+
Attributes:
590+
top_candidates (MutableSequence[google.ai.generativelanguage_v1.types.LogprobsResult.TopCandidates]):
591+
Length = total number of decoding steps.
592+
chosen_candidates (MutableSequence[google.ai.generativelanguage_v1.types.LogprobsResult.Candidate]):
593+
Length = total number of decoding steps. The chosen
594+
candidates may or may not be in top_candidates.
595+
"""
596+
597+
class Candidate(proto.Message):
598+
r"""Candidate for the logprobs token and score.
599+
600+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
601+
602+
Attributes:
603+
token (str):
604+
The candidate’s token string value.
605+
606+
This field is a member of `oneof`_ ``_token``.
607+
token_id (int):
608+
The candidate’s token id value.
609+
610+
This field is a member of `oneof`_ ``_token_id``.
611+
log_probability (float):
612+
The candidate's log probability.
613+
614+
This field is a member of `oneof`_ ``_log_probability``.
615+
"""
616+
617+
token: str = proto.Field(
618+
proto.STRING,
619+
number=1,
620+
optional=True,
621+
)
622+
token_id: int = proto.Field(
623+
proto.INT32,
624+
number=3,
625+
optional=True,
626+
)
627+
log_probability: float = proto.Field(
628+
proto.FLOAT,
629+
number=2,
630+
optional=True,
631+
)
632+
633+
class TopCandidates(proto.Message):
634+
r"""Candidates with top log probabilities at each decoding step.
635+
636+
Attributes:
637+
candidates (MutableSequence[google.ai.generativelanguage_v1.types.LogprobsResult.Candidate]):
638+
Sorted by log probability in descending
639+
order.
640+
"""
641+
642+
candidates: MutableSequence["LogprobsResult.Candidate"] = proto.RepeatedField(
643+
proto.MESSAGE,
644+
number=1,
645+
message="LogprobsResult.Candidate",
646+
)
647+
648+
top_candidates: MutableSequence[TopCandidates] = proto.RepeatedField(
649+
proto.MESSAGE,
650+
number=1,
651+
message=TopCandidates,
652+
)
653+
chosen_candidates: MutableSequence[Candidate] = proto.RepeatedField(
654+
proto.MESSAGE,
655+
number=2,
656+
message=Candidate,
657+
)
497658

498659

499660
class EmbedContentRequest(proto.Message):

0 commit comments

Comments
 (0)