From aa0605264c6c085c51a187eff14b4276b31433f6 Mon Sep 17 00:00:00 2001 From: zhangqianze Date: Tue, 3 Dec 2024 20:56:31 +0800 Subject: [PATCH] fix property.json --- agents/examples/default/property.json | 19 +++++++++---- .../weatherapi_tool_python/extension.py | 27 +++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/agents/examples/default/property.json b/agents/examples/default/property.json index e6bce7ec..ed3fe1cb 100644 --- a/agents/examples/default/property.json +++ b/agents/examples/default/property.json @@ -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}" } }, { @@ -169,6 +169,15 @@ "extension": "tts" } ] + }, + { + "name": "tool_call", + "dest": [ + { + "extension_group": "default", + "extension": "weatherapi_tool_python" + } + ] } ], "data": [ diff --git a/agents/ten_packages/extension/weatherapi_tool_python/extension.py b/agents/ten_packages/extension/weatherapi_tool_python/extension.py index 8614914a..8f36098a 100644 --- a/agents/ten_packages/extension/weatherapi_tool_python/extension.py +++ b/agents/ten_packages/extension/weatherapi_tool_python/extension.py @@ -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") @@ -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: