duroodia commited on
Commit
859cd63
·
verified ·
1 Parent(s): da749f2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +49 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from agents import Agent, Runner, AsyncOpenAI, OpenAIChatCompletionsModel
4
+ from agents.run import RunConfig
5
+ import asyncio
6
+
7
+ # Load the environment variables from the .env file
8
+ load_dotenv()
9
+
10
+ gemini_api_key = os.getenv("GEMINI_API_KEY")
11
+
12
+ # Check if the API key is present; if not, raise an error
13
+ if not gemini_api_key:
14
+ raise ValueError("GEMINI_API_KEY is not set. Please ensure it is defined in your .env file.")
15
+
16
+ #Reference: https://ai.google.dev/gemini-api/docs/openai
17
+ external_client = AsyncOpenAI(
18
+ api_key=gemini_api_key,
19
+ base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
20
+ )
21
+
22
+ model = OpenAIChatCompletionsModel(
23
+ model="gemini-2.0-flash",
24
+ openai_client=external_client
25
+ )
26
+
27
+ config = RunConfig(
28
+ model=model,
29
+ model_provider=external_client,
30
+ tracing_disabled=True
31
+ )
32
+
33
+
34
+ async def main():
35
+ agent = Agent(
36
+ name="Translator",
37
+ instructions="you always translate Urdu sentences to simple English language.",
38
+ model=model
39
+ )
40
+
41
+ result = await Runner.run(agent, "اچھے لوگوں کا ملنا ہی اچھے مستقبل کی ضمانت ہے",run_config=config)
42
+ print(result.final_output)
43
+ # Function calls itself,
44
+ # Looping in smaller pieces,
45
+ # Endless by design.
46
+
47
+
48
+ if __name__ == "__main__":
49
+ asyncio.run(main())
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ openai-agents
3
+ python-dotenv