Skip to content

Commit b47b039

Browse files
authored
Add examples of the Text service to README/init (#17)
This adds the Text service as the first example seen. It balances the Chat service, which will always come first alphabetically.
1 parent 7321a45 commit b47b039

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ Get an [API key from MakerSuite](https://makersuite.google.com/app/apikey), then
1818
```python
1919
import google.generativeai as palm
2020

21-
palm.configure(api_key=os.environ['PALM_API_KEY'])
21+
palm.configure(api_key=os.environ["PALM_API_KEY"])
2222
```
2323

24-
Use the `palm.chat` function to have a discussion with a model.
24+
Use [`palm.generate_text`](https://developers.generativeai.google/api/python/google/generativeai/generate_text)
25+
to have the model complete some initial text.
26+
```python
27+
response = palm.generate_text(prompt="The opposite of hot is")
28+
print(response.result) # cold.
29+
```
30+
31+
Use [`palm.chat`](https://developers.generativeai.google/api/python/google/generativeai/chat)
32+
to have a discussion with a model.
2533
```python
2634
response = palm.chat(messages=["Hello."])
2735
print(response.last) # 'Hello! What can I help you with?'

google/generativeai/__init__.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,27 @@
2121
```
2222
2323
```
24-
import google.generativeai as genai
24+
import google.generativeai as palm
2525
26-
genai.configure(api_key=os.environ['API_KEY'])
26+
palm.configure(api_key=os.environ['API_KEY'])
27+
```
28+
29+
## Text
30+
31+
Use the `palm.generate_text` function to have the model complete some initial
32+
text.
33+
34+
```
35+
response = palm.generate_text(prompt="The opposite of hot is")
36+
print(response.result) # 'cold.'
2737
```
2838
2939
## Chat
3040
31-
Use the `genai.chat` function to have a discussion with a model:
41+
Use the `palm.chat` function to have a discussion with a model:
3242
3343
```
34-
response = genai.chat(messages=["Hello."])
44+
response = palm.chat(messages=["Hello."])
3545
print(response.last) # 'Hello! What can I help you with?'
3646
response.reply("Can you tell me a joke?")
3747
```
@@ -40,17 +50,17 @@
4050
4151
Use the model service discover models and find out more about them:
4252
43-
Use `genai.get_model` to get details if you know a model's name:
53+
Use `palm.get_model` to get details if you know a model's name:
4454
4555
```
46-
model = genai.get_model('chat-bison-001') # 🦬
56+
model = palm.get_model('chat-bison-001') # 🦬
4757
```
4858
49-
Use `genai.list_models` to discover models:
59+
Use `palm.list_models` to discover models:
5060
5161
```
5262
import pprint
53-
for model in genai.list_models():
63+
for model in palm.list_models():
5464
pprint.pprint(model) # 🦎🦦🦬🦄
5565
```
5666

0 commit comments

Comments
 (0)