-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tool): add web_search_vertexai.sh (#93)
- Loading branch information
Showing
3 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# @describe Perform a web search using VertexAI Gemini API to get up-to-date information or additional context. | ||
# Use this when you need current information or feel a search could provide a better answer. | ||
|
||
# @env VERTEXAI_PROJECT_ID! The project id | ||
# @env VERTEXAI_LOCATION! The location | ||
# @env VERTEXAI_WEB_SEARCH_MODEL=gemini-1.5-pro-001 The LLM model for web search | ||
# @option --query! The query to search for. | ||
# @meta require-tools gcloud | ||
|
||
main() { | ||
curl -fsSL https://$VERTEXAI_LOCATION-aiplatform.googleapis.com/v1beta1/projects/$VERTEXAI_PROJECT_ID/locations/$VERTEXAI_LOCATION/publishers/google/models/$VERTEXAI_WEB_SEARCH_MODEL:generateContent \ | ||
-X POST \ | ||
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ | ||
-H "Content-Type: application/json" \ | ||
-d ' | ||
{ | ||
"contents": [{ | ||
"role": "user", | ||
"parts": [{ | ||
"text": "'"$argc_query"'" | ||
}] | ||
}], | ||
"safetySettings": [ | ||
{ | ||
"category": "HARM_CATEGORY_HARASSMENT", | ||
"threshold": "BLOCK_ONLY_HIGH" | ||
}, | ||
{ | ||
"category": "HARM_CATEGORY_HATE_SPEECH", | ||
"threshold": "BLOCK_ONLY_HIGH" | ||
}, | ||
{ | ||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", | ||
"threshold": "BLOCK_ONLY_HIGH" | ||
}, | ||
{ | ||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT", | ||
"threshold": "BLOCK_ONLY_HIGH" | ||
} | ||
], | ||
"tools": [{ | ||
"googleSearchRetrieval": {} | ||
}] | ||
}' | \ | ||
jq -r '.candidates[0].content.parts[0].text' >> "$LLM_OUTPUT" | ||
} | ||
|
||
eval "$(argc --argc-eval "$0" "$@")" |