Skip to content

Commit

Permalink
fix property.json
Browse files Browse the repository at this point in the history
  • Loading branch information
plutoless committed Dec 3, 2024
1 parent 47b1929 commit aa06052
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
19 changes: 14 additions & 5 deletions agents/examples/default/property.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
"addon": "openai_chatgpt_python",
"extension_group": "chatgpt",
"property": {
"base_url": "",
"api_key": "${env:OPENAI_API_KEY}",
"base_url": "",
"frequency_penalty": 0.9,
"model": "gpt-4o",
"greeting": "TEN Agent connected. How can I help you today?",
"max_memory_length": 10,
"max_tokens": 512,
"model": "${env:OPENAI_MODEL}",
"prompt": "",
"proxy_url": "${env:OPENAI_PROXY_URL|}",
"greeting": "TEN Agent connected. How can I help you today?",
"max_memory_length": 10
"proxy_url": "${env:OPENAI_PROXY_URL}"
}
},
{
Expand Down Expand Up @@ -169,6 +169,15 @@
"extension": "tts"
}
]
},
{
"name": "tool_call",
"dest": [
{
"extension_group": "default",
"extension": "weatherapi_tool_python"
}
]
}
],
"data": [
Expand Down
27 changes: 16 additions & 11 deletions agents/ten_packages/extension/weatherapi_tool_python/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def get_tool_metadata(self, ten_env: AsyncTenEnv) -> list[LLMToolMetadata]:
]

async def run_tool(self, ten_env: AsyncTenEnv, name: str, args: dict) -> LLMToolResult:
ten_env.log_info(f"run_tool name: {name}, args: {args}")
if name == CURRENT_TOOL_NAME:
result = await self._get_current_weather(args)
# result = LLMCompletionContentItemText(text="I see something")
Expand All @@ -183,17 +184,21 @@ async def _get_current_weather(self, args: dict) -> Any:
if "location" not in args:
raise Exception("Failed to get property")

location = args["location"]
url = f"http://api.weatherapi.com/v1/current.json?key={self.config.api_key}&q={location}&aqi=no"

async with self.session.get(url) as response:
result = await response.json()
return {
"location": result.get("location", {}).get("name", ""),
"temperature": result.get("current", {}).get("temp_c", ""),
"humidity": result.get("current", {}).get("humidity", ""),
"wind_speed": result.get("current", {}).get("wind_kph", ""),
}
try:
location = args["location"]
url = f"http://api.weatherapi.com/v1/current.json?key={self.config.api_key}&q={location}&aqi=no"

async with self.session.get(url) as response:
result = await response.json()
return {
"location": result.get("location", {}).get("name", ""),
"temperature": result.get("current", {}).get("temp_c", ""),
"humidity": result.get("current", {}).get("humidity", ""),
"wind_speed": result.get("current", {}).get("wind_kph", ""),
}
except Exception as e:
self.ten_env.log_error(f"Failed to get current weather: {e}")
return None

async def _get_past_weather(self, args: dict) -> Any:
if "location" not in args or "datetime" not in args:
Expand Down

0 comments on commit aa06052

Please sign in to comment.