Last active
November 9, 2024 06:47
-
-
Save up1/9b0a4251016c0d70663678a13aa24b56 to your computer and use it in GitHub Desktop.
Gemini model with OpenAI library
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
$export GEMINI_API_KEY=your-key | |
$python demo.py | |
ChatCompletionMessage( | |
content='I can definitely help you find a restaurant in Thailand! To give you the best recommendations, | |
I need a little more information. Tell me:\n\n* **Where in Thailand are you looking?** | |
(e.g., Bangkok, Chiang Mai, Phuket, etc.) \n* **What kind of cuisine are you interested in?** | |
(e.g., Thai, Italian, Japanese, street food, etc.)\n* **What is your budget?** | |
(e.g., budget-friendly, mid-range, high-end)\n* **What kind of atmosphere are you looking for?** | |
(e.g., romantic, lively, casual, etc.)\n\nOnce I have this information, | |
I can give you some personalized recommendations! \n', | |
refusal=None, role='model', audio=None, function_call=None, tool_calls=[]) |
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
from openai import OpenAI | |
import os | |
# GET YOUR API KEY from environment variable | |
API_KEY = os.getenv("GEMINI_API_KEY") | |
client = OpenAI( | |
api_key=API_KEY, | |
base_url="https://generativelanguage.googleapis.com/v1beta/" | |
) | |
response = client.chat.completions.create( | |
model="gemini-1.5-flash", | |
n=1, | |
messages=[ | |
{"role": "system", "content": "You are a helpful assistant."}, | |
{ | |
"role": "user", | |
"content": "Hello, I am looking for a restaurant in Thailand. Can you help me?" | |
} | |
] | |
) | |
print(response.choices[0].message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment