Use OpenAI client with Gemini endpoint.
Obtain an API Key from Google AI Studio: https://aistudio.google.com/app/apikey
Use the OpenAI client to interact with the Gemini endpoint.
from openai import OpenAI
MODEL = "models/gemini-pro"
client = OpenAI(base_url="http://0.0.0.0:8080", api_key="<your_api_key>")
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Say this is a test",
}
],
model=MODEL,
)
print(chat_completion.choices[0].message.content)