Skip to content

Commit e3bfbc6

Browse files
feat: [google-ai-generativelanguage] Add rest binding for tuned models (#12568)
- [ ] Regenerate this pull request now. BEGIN_COMMIT_OVERRIDE feat(v1): Add rest binding for tuned models feat(v1): Add `QUESTION_ANSWERING` and `FACT_VERIFICATION` to `TaskType` Enum feat(v1): Add `output dimensionality` to `EmbedContentRequest` message docs(v1): Lots of small fixes END_COMMIT_OVERRIDE PiperOrigin-RevId: 624205405 Source-Link: googleapis/googleapis@f758dd6 Source-Link: googleapis/googleapis-gen@658ee1d Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiNjU4ZWUxZGEzYmM3MzkxZDgwYjkxMGMxYTk4MzVjNWUxNzk0YTA4ZCJ9 --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent e2cf0c4 commit e3bfbc6

7 files changed

Lines changed: 62 additions & 34 deletions

File tree

packages/google-ai-generativelanguage/.repo-metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "generativelanguage",
33
"name_pretty": "Generative Language API",
4-
"api_description": "Generative Language API",
5-
"product_documentation": "https://developers.generativeai.google/",
4+
"api_description": "The Gemini API allows developers to build generative AI applications using Gemini models. Gemini is our most capable model, built from the ground up to be multimodal. It can generalize and seamlessly understand, operate across, and combine different types of information including language, images, audio, video, and code. You can use the Gemini API for use cases like reasoning across text and images, content generation, dialogue agents, summarization and classification systems, and more.",
5+
"product_documentation": "https://ai.google.dev/docs",
66
"client_documentation": "https://googleapis.dev/python/generativelanguage/latest",
77
"issue_tracker": "https://github.com/google/generative-ai-python/issues/new",
88
"release_level": "preview",

packages/google-ai-generativelanguage/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Python Client for Generative Language API
33

44
|preview| |pypi| |versions|
55

6-
`Generative Language API`_: Generative Language API
6+
`Generative Language API`_: The Gemini API allows developers to build generative AI applications using Gemini models. Gemini is our most capable model, built from the ground up to be multimodal. It can generalize and seamlessly understand, operate across, and combine different types of information including language, images, audio, video, and code. You can use the Gemini API for use cases like reasoning across text and images, content generation, dialogue agents, summarization and classification systems, and more.
77

88
- `Client Library Documentation`_
99
- `Product Documentation`_
@@ -14,9 +14,9 @@ Python Client for Generative Language API
1414
:target: https://pypi.org/project/google-ai-generativelanguage/
1515
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-ai-generativelanguage.svg
1616
:target: https://pypi.org/project/google-ai-generativelanguage/
17-
.. _Generative Language API: https://developers.generativeai.google/
17+
.. _Generative Language API: https://ai.google.dev/docs
1818
.. _Client Library Documentation: https://googleapis.dev/python/generativelanguage/latest
19-
.. _Product Documentation: https://developers.generativeai.google/
19+
.. _Product Documentation: https://ai.google.dev/docs
2020

2121
Quick Start
2222
-----------
@@ -30,7 +30,7 @@ In order to use this library, you first need to go through the following steps:
3030

3131
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
3232
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
33-
.. _Enable the Generative Language API.: https://developers.generativeai.google/
33+
.. _Enable the Generative Language API.: https://ai.google.dev/docs
3434
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
3535

3636
Installation
@@ -104,5 +104,5 @@ Next Steps
104104
- View this `README`_ to see the full list of Cloud
105105
APIs that we cover.
106106

107-
.. _Generative Language API Product documentation: https://developers.generativeai.google/
107+
.. _Generative Language API Product documentation: https://ai.google.dev/docs
108108
.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,11 @@ def __call__(
739739
"uri": "/v1/{model=models/*}:generateContent",
740740
"body": "*",
741741
},
742+
{
743+
"method": "post",
744+
"uri": "/v1/{model=tunedModels/*}:generateContent",
745+
"body": "*",
746+
},
742747
]
743748
request, metadata = self._interceptor.pre_generate_content(
744749
request, metadata

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

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,21 @@ class TaskType(proto.Enum):
6464
CLUSTERING (5):
6565
Specifies that the embeddings will be used
6666
for clustering.
67+
QUESTION_ANSWERING (6):
68+
Specifies that the given text will be used
69+
for question answering.
70+
FACT_VERIFICATION (7):
71+
Specifies that the given text will be used
72+
for fact verification.
6773
"""
6874
TASK_TYPE_UNSPECIFIED = 0
6975
RETRIEVAL_QUERY = 1
7076
RETRIEVAL_DOCUMENT = 2
7177
SEMANTIC_SIMILARITY = 3
7278
CLASSIFICATION = 4
7379
CLUSTERING = 5
80+
QUESTION_ANSWERING = 6
81+
FACT_VERIFICATION = 7
7482

7583

7684
class GenerateContentRequest(proto.Message):
@@ -147,10 +155,10 @@ class GenerationConfig(proto.Message):
147155
148156
Attributes:
149157
candidate_count (int):
150-
Optional. Number of generated responses to return.
151-
152-
This value must be between [1, 8], inclusive. If unset, this
153-
will default to 1.
158+
Optional. Number of generated responses to
159+
return.
160+
Currently, this value can only be set to 1. If
161+
unset, this will default to 1.
154162
155163
This field is a member of `oneof`_ ``_candidate_count``.
156164
stop_sequences (MutableSequence[str]):
@@ -163,20 +171,19 @@ class GenerationConfig(proto.Message):
163171
Optional. The maximum number of tokens to include in a
164172
candidate.
165173
166-
If unset, this will default to output_token_limit specified
167-
in the ``Model`` specification.
174+
Note: The default value varies by model, see the
175+
``Model.output_token_limit`` attribute of the ``Model``
176+
returned from the ``getModel`` function.
168177
169178
This field is a member of `oneof`_ ``_max_output_tokens``.
170179
temperature (float):
171-
Optional. Controls the randomness of the output. Note: The
172-
default value varies by model, see the ``Model.temperature``
173-
attribute of the ``Model`` returned the ``getModel``
174-
function.
180+
Optional. Controls the randomness of the output.
181+
182+
Note: The default value varies by model, see the
183+
``Model.temperature`` attribute of the ``Model`` returned
184+
from the ``getModel`` function.
175185
176-
Values can range from [0.0,1.0], inclusive. A value closer
177-
to 1.0 will produce responses that are more varied and
178-
creative, while a value closer to 0.0 will typically result
179-
in more straightforward responses from the model.
186+
Values can range from [0.0, 2.0].
180187
181188
This field is a member of `oneof`_ ``_temperature``.
182189
top_p (float):
@@ -192,22 +199,24 @@ class GenerationConfig(proto.Message):
192199
based on the cumulative probability.
193200
194201
Note: The default value varies by model, see the
195-
``Model.top_p`` attribute of the ``Model`` returned the
202+
``Model.top_p`` attribute of the ``Model`` returned from the
196203
``getModel`` function.
197204
198205
This field is a member of `oneof`_ ``_top_p``.
199206
top_k (int):
200207
Optional. The maximum number of tokens to consider when
201208
sampling.
202209
203-
The model uses combined Top-k and nucleus sampling.
204-
205-
Top-k sampling considers the set of ``top_k`` most probable
206-
tokens. Defaults to 40.
210+
Models use nucleus sampling or combined Top-k and nucleus
211+
sampling. Top-k sampling considers the set of ``top_k`` most
212+
probable tokens. Models running with nucleus sampling don't
213+
allow top_k setting.
207214
208215
Note: The default value varies by model, see the
209-
``Model.top_k`` attribute of the ``Model`` returned the
210-
``getModel`` function.
216+
``Model.top_k`` attribute of the ``Model`` returned from the
217+
``getModel`` function. Empty ``top_k`` field in ``Model``
218+
indicates the model doesn't apply top-k sampling and doesn't
219+
allow setting ``top_k`` on requests.
211220
212221
This field is a member of `oneof`_ ``_top_k``.
213222
"""
@@ -446,6 +455,13 @@ class EmbedContentRequest(proto.Message):
446455
provides better quality embeddings for retrieval.
447456
448457
This field is a member of `oneof`_ ``_title``.
458+
output_dimensionality (int):
459+
Optional. Optional reduced dimension for the output
460+
embedding. If set, excessive values in the output embedding
461+
are truncated from the end. Supported by
462+
``models/text-embedding-latest``.
463+
464+
This field is a member of `oneof`_ ``_output_dimensionality``.
449465
"""
450466

451467
model: str = proto.Field(
@@ -468,6 +484,11 @@ class EmbedContentRequest(proto.Message):
468484
number=4,
469485
optional=True,
470486
)
487+
output_dimensionality: int = proto.Field(
488+
proto.INT32,
489+
number=5,
490+
optional=True,
491+
)
471492

472493

473494
class ContentEmbedding(proto.Message):

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ class Model(proto.Message):
9898
9999
Top-k sampling considers the set of ``top_k`` most probable
100100
tokens. This value specifies default to be used by the
101-
backend while making the call to the model.
101+
backend while making the call to the model. If empty,
102+
indicates the model doesn't use top-k sampling, and
103+
``top_k`` isn't allowed as a generation parameter.
102104
103105
This field is a member of `oneof`_ ``_top_k``.
104106
"""

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class HarmCategory(proto.Enum):
4242
Negative or harmful comments targeting
4343
identity and/or protected attribute.
4444
HARM_CATEGORY_TOXICITY (2):
45-
Content that is rude, disrepspectful, or
45+
Content that is rude, disrespectful, or
4646
profane.
4747
HARM_CATEGORY_VIOLENCE (3):
48-
Describes scenarios depictng violence against
49-
an individual or group, or general descriptions
50-
of gore.
48+
Describes scenarios depicting violence
49+
against an individual or group, or general
50+
descriptions of gore.
5151
HARM_CATEGORY_SEXUAL (4):
5252
Contains references to sexual acts or other
5353
lewd content.

packages/google-ai-generativelanguage/scripts/fixup_generativelanguage_v1_keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class generativelanguageCallTransformer(cst.CSTTransformer):
4141
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
4242
'batch_embed_contents': ('model', 'requests', ),
4343
'count_tokens': ('model', 'contents', ),
44-
'embed_content': ('model', 'content', 'task_type', 'title', ),
44+
'embed_content': ('model', 'content', 'task_type', 'title', 'output_dimensionality', ),
4545
'generate_content': ('model', 'contents', 'safety_settings', 'generation_config', ),
4646
'get_model': ('name', ),
4747
'list_models': ('page_size', 'page_token', ),

0 commit comments

Comments
 (0)