Skip to content

Commit 5b50adc

Browse files
sararobcopybara-github
authored andcommitted
docs: Improve docs for google.genai.types
PiperOrigin-RevId: 838885522
1 parent a842721 commit 5b50adc

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

README.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,44 @@ client = genai.Client(
5555
)
5656
```
5757

58+
## Using types
59+
60+
All API methods support Pydantic types and dictionaries, which you can access
61+
from `google.genai.types`. You can import the types module with the following:
62+
63+
```python
64+
from google.genai import types
65+
```
66+
67+
Below is an example `generate_content()` call using types from the types module:
68+
69+
```python
70+
response = client.models.generate_content(
71+
model='gemini-2.0-flash-001',
72+
contents=types.Part.from_text(text='Why is the sky blue?'),
73+
config=types.GenerateContentConfig(
74+
temperature=0,
75+
top_p=0.95,
76+
top_k=20,
77+
),
78+
)
79+
```
80+
81+
Alternatively, you can accomplish the same request using dictionaries instead of
82+
types:
83+
84+
```python
85+
response = client.models.generate_content(
86+
model='gemini-2.0-flash-001',
87+
contents={'text': 'Why is the sky blue?'},
88+
config={
89+
'temperature': 0,
90+
'top_p': 0.95,
91+
'top_k': 20,
92+
},
93+
)
94+
```
95+
5896
**(Optional) Using environment variables:**
5997

6098
You can create a client by configuring the necessary environment variables.
@@ -547,33 +585,6 @@ response = client.models.generate_content(
547585
print(response.text)
548586
```
549587

550-
### Typed Config
551-
552-
All API methods support Pydantic types for parameters as well as
553-
dictionaries. You can get the type from `google.genai.types`.
554-
555-
```python
556-
from google.genai import types
557-
558-
response = client.models.generate_content(
559-
model='gemini-2.0-flash-001',
560-
contents=types.Part.from_text(text='Why is the sky blue?'),
561-
config=types.GenerateContentConfig(
562-
temperature=0,
563-
top_p=0.95,
564-
top_k=20,
565-
candidate_count=1,
566-
seed=5,
567-
max_output_tokens=100,
568-
stop_sequences=['STOP!'],
569-
presence_penalty=0.0,
570-
frequency_penalty=0.0,
571-
),
572-
)
573-
574-
print(response.text)
575-
```
576-
577588
### List Base Models
578589

579590
To retrieve tuned models, see [list tuned models](#list-tuned-models).

0 commit comments

Comments
 (0)