patricksamuel commited on
Commit
4fb86fe
·
verified ·
1 Parent(s): b5afdf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -15,6 +15,7 @@ from pydantic import BaseModel, Field
15
  import nest_asyncio
16
  import requests
17
  import os, re
 
18
  #from agents.extensions.models.litellm_model import LitellmModel
19
 
20
  os.getenv("OPENAI_API_KEY")
@@ -133,7 +134,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
133
  class BasicAgent:
134
  def __init__(self):
135
  print("BasicAgent initialized.")
136
- def __call__(self, question: str) -> str:
137
  print(f"Agent received question (first 50 chars): {question[:50]}...")
138
 
139
  instructions = """
@@ -194,7 +195,9 @@ When you've found the answer, stop reasoning and return ONLY the answer.
194
 
195
  result = Runner.run_streamed(my_agent, input=question, max_turns=25)
196
 
197
- for event in result.stream_events():
 
 
198
  # We'll ignore the raw responses event deltas
199
  if event.type == "raw_response_event":
200
  continue
@@ -213,6 +216,8 @@ When you've found the answer, stop reasoning and return ONLY the answer.
213
  else:
214
  pass # Ignore other event types
215
 
 
 
216
  print(f"Agent gave answer (first 50 chars): {result.final_output[:50]}...")
217
  return result.final_output
218
 
 
15
  import nest_asyncio
16
  import requests
17
  import os, re
18
+ import asyncio
19
  #from agents.extensions.models.litellm_model import LitellmModel
20
 
21
  os.getenv("OPENAI_API_KEY")
 
134
  class BasicAgent:
135
  def __init__(self):
136
  print("BasicAgent initialized.")
137
+ async def __call__(self, question: str) -> str:
138
  print(f"Agent received question (first 50 chars): {question[:50]}...")
139
 
140
  instructions = """
 
195
 
196
  result = Runner.run_streamed(my_agent, input=question, max_turns=25)
197
 
198
+ print("=== Run starting ===")
199
+
200
+ async for event in result.stream_events():
201
  # We'll ignore the raw responses event deltas
202
  if event.type == "raw_response_event":
203
  continue
 
216
  else:
217
  pass # Ignore other event types
218
 
219
+
220
+
221
  print(f"Agent gave answer (first 50 chars): {result.final_output[:50]}...")
222
  return result.final_output
223