Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rag-agent/ango/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions image-agent-payment-protocol/payment_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
67 changes: 36 additions & 31 deletions web3/internet-computer/fetch/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import requests
import aiohttp
import json
from uagents_core.contrib.protocols.chat import (
chat_protocol_spec,
Expand Down Expand Up @@ -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:
Expand All @@ -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", [])
Expand Down Expand Up @@ -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"]
Expand Down
4 changes: 4 additions & 0 deletions web3/internet-computer/fetch/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
uagents
aiohttp
python-dotenv
requests
Loading