-
Notifications
You must be signed in to change notification settings - Fork 468
Add additional functions to files & count_tokens. #490
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
MarkDaoust
merged 11 commits into
google-gemini:main
from
shilpakancharla:files_count_tokens_rest
Aug 16, 2024
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cf51b23
Add PDF file function
shilpakancharla 4a121c6
Add rest of count_tokens examples
shilpakancharla 4d9639e
Add context window count
shilpakancharla 6471c41
Tested and fixed count_tokens.sh
shilpakancharla 7c19d7e
Updated files.sh to simplify pdf
shilpakancharla 67321eb
Merge branch 'main' into files_count_tokens_rest
shilpakancharla 73fd445
Update samples.yaml to get basename of file
shilpakancharla 8fe1861
Update samples.yaml to get basename of file
shilpakancharla 852ebf0
Update samples.yaml to get basename of file
shilpakancharla cd3252c
Update samples.yaml to get basename of file
shilpakancharla 492c988
test samples.yaml
shilpakancharla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,11 @@ else | |
B64FLAGS="-w0" | ||
fi | ||
|
||
echo "[START tokens_context_window]" | ||
# [START tokens_context_window] | ||
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:countTokens?key=$GOOGLE_API_KEY | ||
# [END tokens_context_window] | ||
|
||
echo "[START tokens_text_only]" | ||
# [START tokens_text_only] | ||
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:countTokens?key=$GOOGLE_API_KEY \ | ||
|
@@ -170,4 +175,126 @@ curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:c | |
{"file_data":{"mime_type": "video/mp4", "file_uri": '$file_uri'}}] | ||
}] | ||
}' | ||
# [END tokens_multimodal_video_audio_file_api] | ||
# [END tokens_multimodal_video_audio_file_api] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. b/346293525 |
||
echo "[START tokens_cached_content]" | ||
# [START tokens_cached_content] | ||
wget https://storage.googleapis.com/generativeai-downloads/data/a11.txt | ||
shilpakancharla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo '{ | ||
"model": "models/gemini-1.5-flash-001", | ||
"contents":[ | ||
{ | ||
"parts":[ | ||
{ | ||
"inline_data": { | ||
"mime_type":"text/plain", | ||
"data": "'$(base64 $B64FLAGS a11.txt)'" | ||
} | ||
} | ||
], | ||
"role": "user" | ||
} | ||
], | ||
"systemInstruction": { | ||
"parts": [ | ||
{ | ||
"text": "You are an expert at analyzing transcripts." | ||
} | ||
] | ||
}, | ||
"ttl": "300s" | ||
}' > request.json | ||
|
||
curl -X POST "https://generativelanguage.googleapis.com/v1beta/cachedContents?key=$GOOGLE_API_KEY" \ | ||
-H 'Content-Type: application/json' \ | ||
-d @request.json \ | ||
> cache.json | ||
|
||
CACHE_NAME=$(cat cache.json | grep '"name":' | cut -d '"' -f 4 | head -n 1) | ||
|
||
curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:countTokens?key=$GOOGLE_API_KEY" \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ | ||
"contents": [ | ||
{ | ||
"parts":[{ | ||
"text": "Please summarize this transcript" | ||
}], | ||
"role": "user" | ||
}, | ||
], | ||
"cachedContent": "'$CACHE_NAME'" | ||
}' | ||
# [END tokens_cached_content] | ||
|
||
echo "[START tokens_system_instruction]" | ||
# [START tokens_system_instruction] | ||
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:countTokens?key=$GOOGLE_API_KEY" \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{ "system_instruction": { | ||
"parts": | ||
{ "text": "You are a cat. Your name is Neko."}}, | ||
"contents": { | ||
"parts": { | ||
"text": "Hello there"}}}' | ||
# [END tokens_system_instruction] | ||
|
||
echo "[START tokens_tools]" | ||
# [START tokens_tools] | ||
cat > tools.json << EOF | ||
{ | ||
"function_declarations": [ | ||
{ | ||
"name": "enable_lights", | ||
"description": "Turn on the lighting system.", | ||
"parameters": { "type": "object" } | ||
}, | ||
{ | ||
"name": "set_light_color", | ||
"description": "Set the light color. Lights must be enabled for this to work.", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"rgb_hex": { | ||
"type": "string", | ||
"description": "The light color as a 6-digit hex string, e.g. ff0000 for red." | ||
} | ||
}, | ||
"required": [ | ||
"rgb_hex" | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "stop_lights", | ||
"description": "Turn off the lighting system.", | ||
"parameters": { "type": "object" } | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:countTokens?key=$GOOGLE_API_KEY" \ | ||
-H 'Content-Type: application/json' \ | ||
shilpakancharla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-d @<(echo ' | ||
{ | ||
"system_instruction": { | ||
"parts": { | ||
"text": "You are a helpful lighting system bot. You can turn lights on and off, and you can set the color. Do not perform any other tasks." | ||
} | ||
}, | ||
shilpakancharla marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"tools": ['$(source "$tools")'], | ||
|
||
"tool_config": { | ||
"function_calling_config": {"mode": "none"} | ||
}, | ||
|
||
"contents": { | ||
"role": "user", | ||
"parts": { | ||
"text": "What can you do?" | ||
} | ||
} | ||
} | ||
') 2>/dev/null |sed -n '/"content"/,/"finishReason"/p' | ||
# [END tokens_tools] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.