-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into build-on-helicone
- Loading branch information
Showing
6 changed files
with
848 additions
and
362 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: "Gemini Python SDK Integration" | ||
sidebarTitle: "Python" | ||
description: "Use Gemini's Python SDK to integrate with Helicone to log your Gemini AI usage." | ||
"twitter:title": "Gemini Python SDK Integration - Helicone OSS LLM Observability" | ||
icon: "python" | ||
iconType: "solid" | ||
--- | ||
|
||
<Steps> | ||
<Step title="Create an account + Generate an API Key"> | ||
Log into [Helicone](https://www.helicone.ai) or create an account. Once you have an account, you can generate an [API key](https://helicone.ai/developer). | ||
</Step> | ||
<Step title="Create Google Generative AI API Key"> | ||
Visit the [Google Generative AI API Key](https://aistudio.google.com/app/apikey) page. Follow the instructions to create a new API key. Make sure to save the key as you will need it for the next steps. | ||
</Step> | ||
<Step title="Set API keys as environment variables"> | ||
```bash | ||
export HELICONE_API_KEY=<your Helicone API key> | ||
export GOOGLE_GENERATIVE_API_KEY=<your Google Generative AI API key> | ||
``` | ||
</Step> | ||
<Step title="Install the Google Generative AI SDK"> | ||
Ensure you have the necessary packages installed in your Python environment: | ||
```bash | ||
pip install google-generativeai | ||
``` | ||
</Step> | ||
<Step title="Import and configure the client"> | ||
```python | ||
import google.generativeai as genai | ||
import os | ||
genai.configure( | ||
api_key=os.environ.get('GOOGLE_GENERATIVE_API_KEY'), | ||
client_options={ | ||
'api_endpoint': 'gateway.helicone.ai', | ||
}, | ||
default_metadata=[ | ||
('helicone-auth', f'Bearer {os.environ.get("HELICONE_API_KEY")}'), | ||
('helicone-target-url', 'https://generativelanguage.googleapis.com') | ||
], | ||
transport="rest" | ||
) | ||
``` | ||
|
||
</Step> | ||
<Step title="Generate content using the model"> | ||
```python | ||
model = genai.GenerativeModel('gemini-1.5-flash') | ||
response = model.generate_content("The opposite of hot is") | ||
print(response.result) | ||
``` | ||
</Step> | ||
</Steps> |
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
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
Oops, something went wrong.