-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (44 loc) · 1.31 KB
/
Copy pathmain.py
File metadata and controls
54 lines (44 loc) · 1.31 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import asyncio
from dotenv import load_dotenv
from agents import (
Agent,
Runner,
AsyncOpenAI,
set_default_openai_api,
set_default_openai_client,
set_tracing_disabled,
)
# Load environment variables
load_dotenv()
# Default values with fallback
BASE_URL = os.getenv("BASE_URL", "https://generativelanguage.googleapis.com/v1beta/openai/")
API_KEY = os.getenv("GEMINI_API_KEY")
MODEL_NAME = os.getenv("MODEL_NAME", "gemini-2.5-flash")
# Validate required settings
if not API_KEY:
raise ValueError("Missing GEMINI_API_KEY. Please set it in your .env file or environment.")
# Create OpenAI client
client = AsyncOpenAI(
base_url=BASE_URL,
api_key=API_KEY,
)
# Configure defaults
set_default_openai_client(client=client, use_for_tracing=True)
set_default_openai_api("chat_completions")
set_tracing_disabled(True)
async def main():
"""Run a simple example agent."""
agent = Agent(
name="Example Agent",
instructions="You are a helpful assistant.",
model=MODEL_NAME,
)
# Run agent with a sample prompt
result = await Runner.run(agent, "Hello! How are you?")
print("Agent Output:\n", result.final_output)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nExecution stopped by user.")