-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_agent.py
More file actions
29 lines (26 loc) · 1023 Bytes
/
run_agent.py
File metadata and controls
29 lines (26 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from dotenv import load_dotenv
from galileo import galileo_context
from galileo.openai import openai
# Load environment variables from .env
load_dotenv()
def call_openai():
# This call will be automatically traced by Galileo
client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": "Say this is a test"}],
model="gpt-4o"
)
return chat_completion.choices[0].message.content
if __name__ == "__main__":
# Initialize Galileo context globally using env vars
galileo_context.init(
project=os.environ.get("GALILEO_PROJECT"),
log_stream=os.environ.get("GALILEO_LOG_STREAM")
)
# Optionally, wrap your main logic in a Galileo context for a single trace
with galileo_context():
result = call_openai()
print("OpenAI result:", result)
# Only call flush if you want to force-upload traces in a script
galileo_context.flush()