File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 3131from google .adk .tools import FunctionTool
3232import requests
3333import json
34+ import urllib .parse
3435from src .utils .logger import setup_logger
3536
3637logger = setup_logger (__name__ )
@@ -70,7 +71,9 @@ def http_tool(**kwargs):
7071 url = endpoint
7172 for param , value in path_params .items ():
7273 if param in all_values :
73- url = url .replace (f"{{{ param } }}" , str (all_values [param ]))
74+ # URL encode the value for URL safe characters
75+ replacement_value = urllib .parse .quote (str (all_values [param ]), safe = '' )
76+ url = url .replace (f"{{{ param } }}" , replacement_value )
7477
7578 # Process query parameters
7679 query_params_dict = {}
@@ -119,8 +122,12 @@ def http_tool(**kwargs):
119122 f"Error in the request: { response .status_code } - { response .text } "
120123 )
121124
122- # Always returns the response as a string
123- return json .dumps (response .json ())
125+ # Try to parse the response as JSON, if it fails, return the text content
126+ try :
127+ return json .dumps (response .json ())
128+ except ValueError :
129+ # Response is not JSON, return the text content
130+ return json .dumps ({"content" : response .text })
124131
125132 except Exception as e :
126133 logger .error (f"Error executing tool { name } : { str (e )} " )
You can’t perform that action at this time.
0 commit comments