Skip to content

Use flash more often. #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/samples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:

for file in ${NEW_FILES}; do
echo "Testing $file"
name=$(basename $file)
if [[ -f ${file} ]]; then
# File exists, so needs to be listed.
if ! grep -q $name ${README}; then
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ genai.configure(api_key=os.environ["GEMINI_API_KEY"])
3. Create a model and run a prompt.

```python
model = genai.GenerativeModel('gemini-1.0-pro-latest')
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content("The opposite of hot is")
print(response.text)
```
Expand Down
30 changes: 15 additions & 15 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ Each file is structured as a runnable test case, ensuring that samples are execu

## Contents

| File | Description |
| ---- | ----------- |
| [cache.py](./cache.py) | Context caching |
| [chat.py](./chat.py) | Multi-turn chat conversations |
| [code_execution.py](./code_execution.py) | Executing code |
| File | Description |
|----------------------------------------------------------| ----------- |
| [cache.py](./cache.py) | Context caching |
| [chat.py](./chat.py) | Multi-turn chat conversations |
| [code_execution.py](./code_execution.py) | Executing code |
| [configure_model_parameters.py](./configure_model_parameters.py) | Setting model parameters |
| [controlled_generation.py](./controlled_generation.py) | Generating content with output constraints (e.g. JSON mode) |
| [count_tokens.py](./count_tokens.py) | Counting input and output tokens |
| [embed.py](./embed.py) | Generating embeddings |
| [files.py](./files.py) | Managing files with the File API |
| [function_calling.py](./function_calling.py) | Using function calling |
| [models.py](./models.py) | Listing models and model metadata |
| [safety_settings.py](./safety_settings.py) | Setting and using safety controls |
| [system_instruction.py](./system_instruction.py) | Setting system instructions |
| [text_generation.py](./text_generation.py) | Generating text |
| [tuned_models.py](./tuned_models.py) | Creating and managing tuned models |
| [controlled_generation.py](./controlled_generation.py) | Generating content with output constraints (e.g. JSON mode) |
| [count_tokens.py](./count_tokens.py) | Counting input and output tokens |
| [embed.py](./embed.py) | Generating embeddings |
| [files.py](./files.py) | Managing files with the File API |
| [function_calling.py](./function_calling.py) | Using function calling |
| [models.py](./models.py) | Listing models and model metadata |
| [safety_settings.py](./safety_settings.py) | Setting and using safety controls |
| [system_instruction.py](./system_instruction.py) | Setting system instructions |
| [text_generation.py](./text_generation.py) | Generating text |
| [tuned_models.py](./tuned_models.py) | Creating and managing tuned models |
6 changes: 3 additions & 3 deletions samples/code_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_code_execution_basic(self):
)

# Each `part` either contains `text`, `executable_code` or an `execution_result`
for part in result.candidates[0].content.parts:
for part in response.candidates[0].content.parts:
print(part, "\n")

print("-" * 80)
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_code_execution_basic(self):

def test_code_execution_request_override(self):
# [START code_execution_request_override]
model = genai.GenerativeModel(model_name="gemini-1.5-pro")
model = genai.GenerativeModel(model_name="gemini-1.5-flash")
response = model.generate_content(
(
"What is the sum of the first 50 prime numbers? "
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_code_execution_request_override(self):

def test_code_execution_chat(self):
# [START code_execution_chat]
model = genai.GenerativeModel(model_name="gemini-1.5-pro", tools="code_execution")
model = genai.GenerativeModel(model_name="gemini-1.5-flash", tools="code_execution")
chat = model.start_chat()
response = chat.send_message('Can you print "Hello world!"?')
response = chat.send_message(
Expand Down
6 changes: 3 additions & 3 deletions samples/count_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class UnitTests(absltest.TestCase):
def test_tokens_context_window(self):
# [START tokens_context_window]
model_info = genai.get_model("models/gemini-1.0-pro-001")
model_info = genai.get_model("models/gemini-1.5-flash")

# Returns the "context window" for the model,
# which is the combined input and output token limits.
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_tokens_multimodal_image_inline(self):
model = genai.GenerativeModel("models/gemini-1.5-flash")

prompt = "Tell me about this image"
your_image_file = PIL.Image.open("image.jpg")
your_image_file = PIL.Image.open(media / "organ.jpg")

# Call `count_tokens` to get the input token count
# of the combined text and file (`total_tokens`).
Expand All @@ -115,7 +115,7 @@ def test_tokens_multimodal_image_file_api(self):
model = genai.GenerativeModel("models/gemini-1.5-flash")

prompt = "Tell me about this image"
your_image_file = genai.upload_file(path="image.jpg")
your_image_file = genai.upload_file(path=media / "organ.jpg")

# Call `count_tokens` to get the input token count
# of the combined text and file (`total_tokens`).
Expand Down
4 changes: 2 additions & 2 deletions samples/rest/code_execution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set -eu

echo "[START code_execution_basic]"
# [START code_execution_basic]
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-d ' {"tools": [{'code_execution': {}}],
"contents": {
Expand All @@ -16,7 +16,7 @@ curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-lat

echo "[START code_execution_chat]"
# [START code_execution_chat]
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"tools": [{'code_execution': {}}],
"contents": [
Expand Down
4 changes: 2 additions & 2 deletions samples/rest/controlled_generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set -eu

echo "json_controlled_generation"
# [START json_controlled_generation]
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"contents": [{
Expand All @@ -27,7 +27,7 @@ curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-lat

echo "json_no_schema"
# [START json_no_schema]
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"contents": [{
Expand Down
2 changes: 1 addition & 1 deletion samples/rest/models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ curl https://generativelanguage.googleapis.com/v1beta/models?key=$GOOGLE_API_KEY

echo "[START models_get]"
# [START models_get]
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-pro?key=$GOOGLE_API_KEY
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash?key=$GOOGLE_API_KEY
# [END models_get]
32 changes: 14 additions & 18 deletions samples/rest/safety_settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,33 @@ set -eu

echo "[START safety_settings]"
# [START safety_settings]
echo '{
echo '{
"safetySettings": [
{'category': HARM_CATEGORY_HARASSMENT, 'threshold': BLOCK_ONLY_HIGH}
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH"}
],
"contents": [{
"parts":[{
"text": "'I support Martians Soccer Club and I think Jupiterians Football Club sucks! Write a ironic phrase about them.'"}]}]}' > request.json

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$GOOGLE_API_KEY" \
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d @request.json 2> /dev/null > tee response.json

jq .promptFeedback > response.json
-d @request.json 2> /dev/null
# [END safety_settings]

echo "[START safety_settings_multi]"
# [START safety_settings_multi]
echo '{
"safetySettings": [
{'category': HARM_CATEGORY_HARASSMENT, 'threshold': BLOCK_ONLY_HIGH},
{'category': HARM_CATEGORY_HATE_SPEECH, 'threshold': BLOCK_MEDIUM_AND_ABOVE}
],
"contents": [{
"parts":[{
"text": "'I support Martians Soccer Club and I think Jupiterians Football Club sucks! Write a ironic phrase about them.'"}]}]}' > request.json
echo '{
"safetySettings": [
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH"},
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}
],
"contents": [{
"parts":[{
"text": "'I support Martians Soccer Club and I think Jupiterians Football Club sucks! Write a ironic phrase about them.'"}]}]}' > request.json

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$GOOGLE_API_KEY" \
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d @request.json 2> /dev/null > response.json

jq .promptFeedback > response.json
-d @request.json 2> /dev/null
# [END safety_settings_multi]
2 changes: 1 addition & 1 deletion samples/rest/system_instruction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set -eu

echo "[START system_instruction]"
# [START system_instruction]
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{ "system_instruction": {
"parts":
Expand Down
4 changes: 2 additions & 2 deletions samples/tuned_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_tuned_models_create(self):
# [START tuned_models_create]
import time

base_model = "models/gemini-1.0-pro-001"
base_model = "models/gemini-1.5-flash-001-tuning"
training_data = [
{"text_input": "1", "output": "2"},
# ... more examples ...
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_tuned_models_list(self):
def test_tuned_models_delete(self):
import time

base_model = "models/gemini-1.0-pro-001"
base_model = "models/gemini-1.5-flash-001-tuning"
training_data = samples / "increment_tuning_data.json"
try:
operation = genai.create_tuned_model(
Expand Down
Loading