Created
June 9, 2025 20:50
-
-
Save ayqazi/0a3cff574e0a4049706eee8c192a4f21 to your computer and use it in GitHub Desktop.
Gemini Flash with MLflow via OpenAI API layer
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
import os | |
import mlflow | |
from dotenv import load_dotenv | |
from openai import OpenAI | |
load_dotenv() | |
mlflow.openai.autolog() | |
mlflow.set_experiment("genai_openai_example") | |
def ask_gemini_flash(): | |
client = OpenAI( | |
api_key=os.environ["GEMINI_API_KEY"], | |
base_url="https://generativelanguage.googleapis.com/v1beta/openai/" | |
) | |
response = client.chat.completions.create( | |
model="gemini-2.5-flash-preview-05-20", | |
reasoning_effort="low", | |
messages=[ | |
{"role": "system", "content": "You are a helpful assistant."}, | |
{ | |
"role": "user", | |
"content": "Describe a leech as a haiku" | |
} | |
] | |
) | |
print(response.choices[0].message.content) | |
ask_gemini_flash() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment