Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,6 @@ from google.genai import types as genai_types
|
|
13 |
from google.adk.tools import ToolContext, FunctionTool
|
14 |
import logging
|
15 |
#from google.adk.tools import built_in_code_execution
|
16 |
-
from google.adk.code_executors import BuiltInCodeExecutor
|
17 |
from google.adk.tools import agent_tool
|
18 |
|
19 |
|
@@ -24,35 +23,34 @@ from google.adk.tools import agent_tool
|
|
24 |
|
25 |
|
26 |
logging.basicConfig(level=logging.ERROR)
|
27 |
-
from google.adk.tools import agent_tool
|
28 |
url = 'https://agents-course-unit4-scoring.hf.space/questions'
|
29 |
headers = {'accept': 'application/json'}
|
30 |
response = requests.get(url, headers=headers)
|
31 |
|
32 |
-
class responses_api(BaseAgent):
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
|
58 |
|
@@ -95,14 +93,14 @@ def submit_questions(answers: list[str]) -> Dict[str, Any]:
|
|
95 |
responses_api = FunctionTool(func= answer_questions)
|
96 |
submit_api = FunctionTool(func=submit_questions)
|
97 |
|
98 |
-
class QuestionAnswerer(LlmAgent):
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
-
qa = QuestionAnswerer(name = 'qa_1', model="gemini-2.0-flash", description="Question Answerer")
|
106 |
|
107 |
|
108 |
|
@@ -132,9 +130,9 @@ code_agent = LlmAgent(
|
|
132 |
)
|
133 |
|
134 |
,
|
135 |
-
#tools=[built_in_code_execution],
|
136 |
# Add the responses_api agent as a tool
|
137 |
-
sub_agents=[responses_api]
|
138 |
)
|
139 |
|
140 |
|
@@ -151,7 +149,7 @@ search_agent = LlmAgent(
|
|
151 |
,
|
152 |
tools=[google_search],
|
153 |
# Add the responses_api agent as a tool
|
154 |
-
sub_agents=[responses_api]
|
155 |
)
|
156 |
|
157 |
image_agent = LlmAgent(
|
@@ -162,8 +160,11 @@ image_agent = LlmAgent(
|
|
162 |
),
|
163 |
instruction = (
|
164 |
"Get the image file from the link associated in the prompt use Gemini to watch the video and answer the provided question ")
|
|
|
165 |
,
|
166 |
-
tools=[google_search],
|
|
|
|
|
167 |
)
|
168 |
|
169 |
|
@@ -177,7 +178,9 @@ youtube_agent = LlmAgent(
|
|
177 |
"Get the youtube link associated use Gemini to watch the video and answer the provided question ")
|
178 |
|
179 |
,
|
180 |
-
tools=[google_search],
|
|
|
|
|
181 |
)
|
182 |
|
183 |
root_agent = LlmAgent(
|
@@ -199,27 +202,27 @@ root_agent = LlmAgent(
|
|
199 |
tools=[responses_api,submit_api,agent_tool.AgentTool(agent = code_agent),\
|
200 |
agent_tool.AgentTool(agent = search_agent), agent_tool.AgentTool(youtube_agent), agent_tool.AgentTool(image_agent)],
|
201 |
# Add the responses_api agent as a tool
|
202 |
-
sub_agents=[responses_api]
|
203 |
)
|
204 |
|
205 |
-
root_agent = LlmAgent(
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
)
|
217 |
-
|
218 |
-
,
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
)
|
223 |
|
224 |
session_service = InMemorySessionService()
|
225 |
session = session_service.create_session(app_name=APP_NAME, \
|
@@ -227,16 +230,16 @@ session = session_service.create_session(app_name=APP_NAME, \
|
|
227 |
session_id=SESSION_ID)
|
228 |
|
229 |
runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)
|
230 |
-
def send_query_to_agent(root_agent, query, session):
|
231 |
-
|
232 |
-
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
-
async def main():
|
238 |
-
|
239 |
|
240 |
-
if __name__ == "__main__":
|
241 |
-
|
242 |
-
|
|
|
13 |
from google.adk.tools import ToolContext, FunctionTool
|
14 |
import logging
|
15 |
#from google.adk.tools import built_in_code_execution
|
|
|
16 |
from google.adk.tools import agent_tool
|
17 |
|
18 |
|
|
|
23 |
|
24 |
|
25 |
logging.basicConfig(level=logging.ERROR)
|
26 |
+
#from google.adk.tools import agent_tool
|
27 |
url = 'https://agents-course-unit4-scoring.hf.space/questions'
|
28 |
headers = {'accept': 'application/json'}
|
29 |
response = requests.get(url, headers=headers)
|
30 |
|
31 |
+
# class responses_api(BaseAgent):
|
32 |
+
# async def _run_async_impl(self, ctx: InvocationContext)-> AsyncGenerator[Event, None]:
|
33 |
+
# # This method is called when the agent is run
|
34 |
+
# # You can implement your logic here
|
35 |
+
# # For example, you can call an external API or perform some calculations
|
36 |
+
# # and return the result
|
37 |
+
# url = 'https://agents-course-unit4-scoring.hf.space/questions'
|
38 |
+
# headers = {'accept': 'application/json'}
|
39 |
+
# response = requests.get(url, headers=headers)
|
40 |
+
# for i in response.json():
|
41 |
+
# if i['file_name'] != '':
|
42 |
+
# url_file = f"https://agents-course-unit4-scoring.hf.space/files/{i['task_id']}"
|
43 |
+
# question = i['question']
|
44 |
+
# prompt = f"{question} and the file is {url_file}, give the final answer only"
|
45 |
+
# else:
|
46 |
+
# question = i['question']
|
47 |
+
# prompt = f"{question} give the final answer only"
|
48 |
+
# existing_responses = ctx.session.state.get("user:responses", [])
|
49 |
+
# existing_responses.append(prompt)
|
50 |
+
# ctx.session_state["user:responses"] = existing_responses
|
51 |
+
|
52 |
+
# # Optionally, yield a single event to indicate completion or provide some output
|
53 |
+
# yield Event(author=self.name, content=types.Content(parts=[types.Part(text=f"Fetched {len(questions_data)} questions."))])
|
|
|
54 |
|
55 |
|
56 |
|
|
|
93 |
responses_api = FunctionTool(func= answer_questions)
|
94 |
submit_api = FunctionTool(func=submit_questions)
|
95 |
|
96 |
+
# class QuestionAnswerer(LlmAgent):
|
97 |
+
# async def _run_async_impl(self, ctx: InvocationContext) -> AsyncGenerator[Event, None]:
|
98 |
+
# questions_to_answer = ctx.session_service.get('fetched_questions', [])
|
99 |
+
# for q in questions_to_answer:
|
100 |
+
# answer = await self._llm(messages=[types.ChatMessage(role="user", parts=[types.Part(text=q)])])
|
101 |
+
# yield Event(author=self.name, content=answer.content)
|
102 |
|
103 |
+
# qa = QuestionAnswerer(name = 'qa_1', model="gemini-2.0-flash", description="Question Answerer")
|
104 |
|
105 |
|
106 |
|
|
|
130 |
)
|
131 |
|
132 |
,
|
133 |
+
# tools=[built_in_code_execution],
|
134 |
# Add the responses_api agent as a tool
|
135 |
+
#sub_agents=[responses_api]
|
136 |
)
|
137 |
|
138 |
|
|
|
149 |
,
|
150 |
tools=[google_search],
|
151 |
# Add the responses_api agent as a tool
|
152 |
+
#sub_agents=[responses_api]
|
153 |
)
|
154 |
|
155 |
image_agent = LlmAgent(
|
|
|
160 |
),
|
161 |
instruction = (
|
162 |
"Get the image file from the link associated in the prompt use Gemini to watch the video and answer the provided question ")
|
163 |
+
|
164 |
,
|
165 |
+
# tools=[google_search],
|
166 |
+
# Add the responses_api agent as a tool
|
167 |
+
#sub_agents=[responses_api]
|
168 |
)
|
169 |
|
170 |
|
|
|
178 |
"Get the youtube link associated use Gemini to watch the video and answer the provided question ")
|
179 |
|
180 |
,
|
181 |
+
# tools=[google_search],
|
182 |
+
# Add the responses_api agent as a tool
|
183 |
+
#sub_agents=[responses_api]
|
184 |
)
|
185 |
|
186 |
root_agent = LlmAgent(
|
|
|
202 |
tools=[responses_api,submit_api,agent_tool.AgentTool(agent = code_agent),\
|
203 |
agent_tool.AgentTool(agent = search_agent), agent_tool.AgentTool(youtube_agent), agent_tool.AgentTool(image_agent)],
|
204 |
# Add the responses_api agent as a tool
|
205 |
+
#sub_agents=[responses_api]
|
206 |
)
|
207 |
|
208 |
+
# root_agent = LlmAgent(
|
209 |
+
# name='gaiaAgent',
|
210 |
+
# model="gemini-2.5-pro-preview-05-06",
|
211 |
+
# description=(
|
212 |
+
# "You are a smart agent that can answer any questions provided access the given files and answer"
|
213 |
+
# ),
|
214 |
+
# instruction = (
|
215 |
+
# "You are a helpful agent. When the user asks to get the questions or makes a similar request, "
|
216 |
+
# "invoke base agent. "
|
217 |
+
# "Once you the answers check if are in correct format. "
|
218 |
+
# #"Collect all such dictionaries in a list (do not include any backslashes), and pass this list to the 'submit_api' tool to submit the answers."
|
219 |
+
# )
|
220 |
+
|
221 |
+
# ,
|
222 |
+
# #tools=[submit_api],
|
223 |
+
# # Add the responses_api agent as a tool
|
224 |
+
# sub_agents=[base_agent]
|
225 |
+
# )
|
226 |
|
227 |
session_service = InMemorySessionService()
|
228 |
session = session_service.create_session(app_name=APP_NAME, \
|
|
|
230 |
session_id=SESSION_ID)
|
231 |
|
232 |
runner = Runner(agent=root_agent, app_name=APP_NAME, session_service=session_service)
|
233 |
+
# # def send_query_to_agent(root_agent, query, session):
|
234 |
+
# # session = session
|
235 |
+
# # content = types.Content(role='user', parts=[types.Part(text=query)])
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
+
# # async def main():
|
241 |
+
# # await process_questions_and_answer()
|
242 |
|
243 |
+
# # if __name__ == "__main__":
|
244 |
+
# # import asyncio
|
245 |
+
# # asyncio.run(main())
|