diff --git a/Rag-agent/ango/agent.py b/Rag-agent/ango/agent.py index 0d3f29f7..15c855d2 100644 --- a/Rag-agent/ango/agent.py +++ b/Rag-agent/ango/agent.py @@ -196,7 +196,7 @@ async def generate_rag_response(self, query: str) -> str: return "I encountered an error while searching my knowledge base. Please try again." # Use the Agno agent to generate a response - response = self.rag_agent.run(query) + response = await self.rag_agent.arun(query) response_content = response.content if hasattr(response, 'content') else str(response) # Add a note if the response seems generic diff --git a/image-agent-payment-protocol/payment_proto.py b/image-agent-payment-protocol/payment_proto.py index 0423e128..36065d9d 100644 --- a/image-agent-payment-protocol/payment_proto.py +++ b/image-agent-payment-protocol/payment_proto.py @@ -116,16 +116,17 @@ def _sanitize_prompt(raw: str) -> str: ctx.logger.info(f"Generating image via Pollinations for prompt: {clean_prompt}") try: - import requests as _r + import aiohttp as _a pollinations_url = f"https://image.pollinations.ai/prompt/{quote(clean_prompt)}?width=512&height=512" - resp = _r.get(pollinations_url, timeout=90) - ctype = resp.headers.get("Content-Type", "") - if resp.status_code != 200 or not resp.content or not ctype.startswith("image/"): - await ctx.send(user_address, create_text_chat("Image generation failed")) - return - - image_bytes: bytes = resp.content - mime_type: str = ctype or "image/png" + async with _a.ClientSession() as session: + async with session.get(pollinations_url, timeout=90) as resp: + ctype = resp.headers.get("Content-Type", "") + if resp.status != 200 or not ctype.startswith("image/"): + await ctx.send(user_address, create_text_chat("Image generation failed")) + return + + image_bytes: bytes = await resp.read() + mime_type: str = ctype or "image/png" # Upload to Agentverse External Storage and send as resource api_key = os.getenv("AGENTVERSE_API_KEY") diff --git a/web3/internet-computer/fetch/agent.py b/web3/internet-computer/fetch/agent.py index fa148c50..fbcba41e 100644 --- a/web3/internet-computer/fetch/agent.py +++ b/web3/internet-computer/fetch/agent.py @@ -1,4 +1,4 @@ -import requests +import aiohttp import json from uagents_core.contrib.protocols.chat import ( chat_protocol_spec, @@ -107,22 +107,25 @@ ] async def call_icp_endpoint(func_name: str, args: dict): - if func_name == "get_current_fee_percentiles": - url = f"{BASE_URL}/get-current-fee-percentiles" - response = requests.post(url, headers=HEADERS, json={}) - elif func_name == "get_balance": - url = f"{BASE_URL}/get-balance" - response = requests.post(url, headers=HEADERS, json={"address": args["address"]}) - elif func_name == "get_utxos": - url = f"{BASE_URL}/get-utxos" - response = requests.post(url, headers=HEADERS, json={"address": args["address"]}) - elif func_name == "send": - url = f"{BASE_URL}/send" - response = requests.post(url, headers=HEADERS, json=args) - else: - raise ValueError(f"Unsupported function call: {func_name}") - response.raise_for_status() - return response.json() + async with aiohttp.ClientSession() as session: + if func_name == "get_current_fee_percentiles": + url = f"{BASE_URL}/get-current-fee-percentiles" + json_data = {} + elif func_name == "get_balance": + url = f"{BASE_URL}/get-balance" + json_data = {"address": args["address"]} + elif func_name == "get_utxos": + url = f"{BASE_URL}/get-utxos" + json_data = {"address": args["address"]} + elif func_name == "send": + url = f"{BASE_URL}/send" + json_data = args + else: + raise ValueError(f"Unsupported function call: {func_name}") + + async with session.post(url, headers=HEADERS, json=json_data) as response: + response.raise_for_status() + return await response.json() async def process_query(query: str, ctx: Context) -> str: try: @@ -138,13 +141,14 @@ async def process_query(query: str, ctx: Context) -> str: "temperature": 0.7, "max_tokens": 1024 } - response = requests.post( - f"{ASI1_BASE_URL}/chat/completions", - headers=ASI1_HEADERS, - json=payload - ) - response.raise_for_status() - response_json = response.json() + async with aiohttp.ClientSession() as session: + async with session.post( + f"{ASI1_BASE_URL}/chat/completions", + headers=ASI1_HEADERS, + json=payload + ) as response: + response.raise_for_status() + response_json = await response.json() # Step 2: Parse tool calls from response tool_calls = response_json["choices"][0]["message"].get("tool_calls", []) @@ -185,13 +189,14 @@ async def process_query(query: str, ctx: Context) -> str: "temperature": 0.7, "max_tokens": 1024 } - final_response = requests.post( - f"{ASI1_BASE_URL}/chat/completions", - headers=ASI1_HEADERS, - json=final_payload - ) - final_response.raise_for_status() - final_response_json = final_response.json() + async with aiohttp.ClientSession() as session: + async with session.post( + f"{ASI1_BASE_URL}/chat/completions", + headers=ASI1_HEADERS, + json=final_payload + ) as final_response: + final_response.raise_for_status() + final_response_json = await final_response.json() # Step 5: Return the model's final answer return final_response_json["choices"][0]["message"]["content"] diff --git a/web3/internet-computer/fetch/requirements.txt b/web3/internet-computer/fetch/requirements.txt new file mode 100644 index 00000000..97de1290 --- /dev/null +++ b/web3/internet-computer/fetch/requirements.txt @@ -0,0 +1,4 @@ +uagents +aiohttp +python-dotenv +requests