You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get started using the PaLM API in Python. Check out the [developer site](https://developers.generativeai.google/)
9
-
for comprehensive documentation.
7
+
The Google AI Python SDK enables developers to use Google's state-of-the-art generative AI
8
+
models (like Gemini and PaLM) to build AI-powered features and applications. This SDK
9
+
supports use cases like:
10
+
11
+
- Generate text from text-only input
12
+
- Generate text from text-and-images input (multimodal) (for Gemini only)
13
+
- Build multi-turn conversations (chat)
14
+
- Embedding
15
+
16
+
For example, with just a few lines of code, you can access Gemini's multimodal
17
+
capabilities to generate text from text-and-image input:
18
+
19
+
```
20
+
model = genai.GenerativeModel('gemini-pro-vision')
21
+
22
+
cookie_picture = {
23
+
'mime_type': 'image/png',
24
+
'data': Path('cookie.png').read_bytes()
25
+
}
26
+
prompt = "Give me a recipe for this:"
27
+
28
+
response = model.generate_content(
29
+
content=[prompt, cookie_picture]
30
+
)
31
+
print(response.text)
32
+
```
10
33
11
-
## Installation and usage
34
+
35
+
## Try out the API
12
36
13
37
Install from PyPI.
14
-
```bash
15
-
pip install google-generativeai
38
+
39
+
`pip install google-generativeai`
40
+
41
+
[Obtain an API key from AI Studio](https://makersuite.google.com/app/apikey),
42
+
then configure it here.
43
+
44
+
Import the SDK and load a model.
45
+
16
46
```
47
+
import google.generativeai as genai
17
48
18
-
Get an [API key from MakerSuite](https://makersuite.google.com/app/apikey), then configure it here.
19
-
```python
49
+
genai.configure(api_key=os.environ["API_KEY"])
50
+
51
+
model = genai.GenerativeModel('gemini-pro')
52
+
```
53
+
54
+
Use `GenerativeModel.generate_content` to have the model complete some initial text.
55
+
56
+
```
57
+
response = model.generate_content("The opposite of hot is")
58
+
print(response.text) # cold.
59
+
```
60
+
61
+
Use `GenerativeModel.start_chat` to have a discussion with a model.
62
+
63
+
```
64
+
chat = model.start_chat()
65
+
response = chat.send_message('Hello, what should I have for dinner?')
66
+
print(response.text) # 'Here are some suggestions...'
67
+
response = chat.send_message("How do I cook the first one?")
68
+
```
69
+
70
+
71
+
72
+
## Installation and usage
73
+
74
+
Run [`pip install google-generativeai`](https://pypi.org/project/google-generativeai).
75
+
76
+
For detailed instructions, you can find a
77
+
[quickstart](https://ai.google.dev/tutorials/python_quickstart) for the Google AI
78
+
Python SDK in the Google documentation.
79
+
80
+
This quickstart describes how to add your API key and install the SDK in your app,
81
+
initialize the model, and then call the API to access the model. It also describes some
82
+
additional use cases and features, like streaming, embedding, counting tokens, and
83
+
controlling responses.
84
+
85
+
86
+
## Documentation
87
+
88
+
Find complete documentation for the Google AI SDKs and the Gemini model in the Google
89
+
documentation: https://ai.google.dev/docs
90
+
91
+
92
+
## Contributing
93
+
94
+
See [Contributing](https://github.com/google/generative-ai-python/blob/main/CONTRIBUTING.md) for more information on contributing to the Google AI Python SDK.
95
+
96
+
## Developers who use the PaLM API
97
+
98
+
### Migrate to use the Gemini API
99
+
100
+
Check our [migration guide](https://ai.google.dev/docs/migration_guide) in the Google
101
+
documentation.
102
+
103
+
### Installation and usage for the PaLM API
104
+
105
+
Install from PyPI.
106
+
107
+
`pip install google-generativeai`
108
+
109
+
[Obtain an API key from AI Studio](https://makersuite.google.com/app/apikey), then
Checkout the full [API docs](https://developers.generativeai.google/api), the [guide](https://developers.generativeai.google/guide) and [quick starts](https://developers.generativeai.google/tutorials).
0 commit comments