mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-01-13 12:10:18 +00:00
agent
: handle function errors and dont' stringify str outputs
This commit is contained in:
parent
21a3c90a1c
commit
a151ddcd5a
@ -97,6 +97,8 @@ class OpenAPIMethod:
|
|||||||
url = f'{self.url}?{params}'
|
url = f'{self.url}?{params}'
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.post(url, json=body) as response:
|
async with session.post(url, json=body) as response:
|
||||||
|
if response.status == 500:
|
||||||
|
raise Exception(await response.text())
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
response_json = await response.json()
|
response_json = await response.json()
|
||||||
|
|
||||||
@ -240,12 +242,15 @@ async def main(
|
|||||||
pretty_call = f'{name}({", ".join(f"{k}={v.model_dump_json() if isinstance(v, BaseModel) else json.dumps(v)}" for k, v in args.items())})'
|
pretty_call = f'{name}({", ".join(f"{k}={v.model_dump_json() if isinstance(v, BaseModel) else json.dumps(v)}" for k, v in args.items())})'
|
||||||
print(f'⚙️ {pretty_call}', file=sys.stderr, end=None)
|
print(f'⚙️ {pretty_call}', file=sys.stderr, end=None)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
tool_result = await tool_map[name](**args)
|
try:
|
||||||
tool_result_str = json.dumps(tool_result)
|
tool_result = await tool_map[name](**args)
|
||||||
def describe(res, res_str):
|
except Exception as e:
|
||||||
|
tool_result = 'ERROR: ' + str(e)
|
||||||
|
tool_result_str = tool_result if isinstance(tool_result, str) else json.dumps(tool_result)
|
||||||
|
def describe(res, res_str, max_len = 1000):
|
||||||
if isinstance(res, list):
|
if isinstance(res, list):
|
||||||
return f'{len(res)} items'
|
return f'{len(res)} items'
|
||||||
return f'{len(res_str)} chars\n {res_str[:1000]}'
|
return f'{len(res_str)} chars\n {res_str[:1000] if len(res_str) > max_len else res_str}...'
|
||||||
print(f' → {describe(tool_result, tool_result_str)}', file=sys.stderr)
|
print(f' → {describe(tool_result, tool_result_str)}', file=sys.stderr)
|
||||||
if verbose:
|
if verbose:
|
||||||
print(tool_result_str, file=sys.stderr)
|
print(tool_result_str, file=sys.stderr)
|
||||||
|
@ -7,7 +7,12 @@
|
|||||||
#
|
#
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [[ -z "${BRAVE_SEARCH_API_KEY:-}" ]]; then
|
||||||
|
echo "Please set BRAVE_SEARCH_API_KEY environment variable in order to enable the brave_search tool" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
PORT=${PORT:-8088}
|
PORT=${PORT:-8088}
|
||||||
|
BRAVE_SEARCH_API_KEY=${BRAVE_SEARCH_API_KEY:-}
|
||||||
|
|
||||||
docker run -p $PORT:$PORT \
|
docker run -p $PORT:$PORT \
|
||||||
-w /src \
|
-w /src \
|
||||||
|
Loading…
Reference in New Issue
Block a user