Skip to content

Commit 0cd555b

Browse files
MarkDaoustmarkmcd
andauthored
Update README.md (#107)
* Update README.md * Update README.md * Updated Gemini sample code in README * Update docs/build_docs.py --------- Co-authored-by: Mark McDonald <[email protected]>
1 parent 4f05500 commit 0cd555b

File tree

2 files changed

+124
-20
lines changed

2 files changed

+124
-20
lines changed

README.md

Lines changed: 123 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,154 @@
1-
Google Generative AI Python Client
2-
==================================
1+
# Google AI Python SDK
32

43
[![PyPI version](https://badge.fury.io/py/google-generativeai.svg)](https://badge.fury.io/py/google-generativeai)
54
![Python support](https://img.shields.io/pypi/pyversions/google-generativeai)
65
![PyPI - Downloads](https://img.shields.io/pypi/dd/google-generativeai)
76

8-
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+
```
1033

11-
## Installation and usage
34+
35+
## Try out the API
1236

1337
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+
1646
```
47+
import google.generativeai as genai
48+
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).
1775

18-
Get an [API key from MakerSuite](https://makersuite.google.com/app/apikey), then configure it here.
19-
```python
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 JavaScript 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
110+
configure it here.
111+
112+
```
20113
import google.generativeai as palm
21114
22115
palm.configure(api_key=os.environ["PALM_API_KEY"])
23116
```
24117

25-
Use [`palm.generate_text`](https://developers.generativeai.google/api/python/google/generativeai/generate_text)
26-
to have the model complete some initial text.
27-
```python
118+
Use `palm.generate_text` to have the model complete some initial text.
119+
120+
```
28121
response = palm.generate_text(prompt="The opposite of hot is")
29122
print(response.result) # cold.
30123
```
31124

32-
Use [`palm.chat`](https://developers.generativeai.google/api/python/google/generativeai/chat)
33-
to have a discussion with a model.
34-
```python
125+
Use `palm.chat` to have a discussion with a model.
126+
127+
```
35128
response = palm.chat(messages=["Hello."])
36129
print(response.last) # 'Hello! What can I help you with?'
37130
response.reply("Can you tell me a joke?")
38131
```
39132

40-
## Documentation
133+
### Documentation for the PaLM API
134+
135+
- [General PaLM documentation](https://ai.google.dev/docs/palm_api_overview)
136+
137+
- [Text quickstart](https://github.com/google/generative-ai-docs/tree/main/site/en/tutorials/text_quickstart.ipynb)
138+
139+
- [Chat quickstart](https://github.com/google/generative-ai-docs/tree/main/site/en/tutorials/chat_quickstart.ipynb)
41140

42-
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).
141+
- [Tuning quickstart](https://github.com/google/generative-ai-docs/blob/main/site/en/tutorials/tuning_quickstart_python.ipynb)
43142

44-
## Colab magics
143+
### Colab magics
45144

46-
Once installed, use the Python client via the `%%palm` Colab magic. Read the full guide [here](https://developers.generativeai.google/tools/notebook_magic).
145+
Once installed, use the Python client via the `%%palm` Colab magic. Read the [full guide](https://github.com/google/generative-ai-docs/blob/main/site/en/tools/notebook_magic.ipynb).
47146

48-
```python
147+
```
49148
%%palm
50149
The best thing since sliced bread is
51150
```
151+
152+
## License
153+
154+
The contents of this repository are licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).

docs/build_docs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import textwrap
2727
import typing
2828

29+
# For showing the conditional imports and types in `content_types.py`
2930
typing.TYPE_CHECKING = True
3031

3132
from absl import app

0 commit comments

Comments
 (0)