agent
: display http errors nicely
This commit is contained in:
parent
f5320af02a
commit
0f5d63943f
1 changed files with 89 additions and 82 deletions
|
@ -14,10 +14,10 @@ from functools import wraps
|
|||
import json
|
||||
from openapi import discover_tools
|
||||
import os
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field, Json
|
||||
import sys
|
||||
import typer
|
||||
from typing import Annotated, Literal, Optional
|
||||
from typing import Annotated, Dict, Literal, Optional
|
||||
import urllib.parse
|
||||
|
||||
|
||||
|
@ -81,6 +81,8 @@ async def main(
|
|||
|
||||
sys.stdout.write(f'🛠️ Tools: {", ".join(tool_map.keys()) if tool_map else "<none>"}\n')
|
||||
|
||||
try:
|
||||
|
||||
messages = []
|
||||
if system:
|
||||
messages.append(dict(
|
||||
|
@ -134,6 +136,7 @@ async def main(
|
|||
|
||||
name = tool_call['function']['name']
|
||||
args = json.loads(tool_call['function']['arguments'])
|
||||
print(f'tool_call: {json.dumps(tool_call, indent=2)}', file=sys.stderr)
|
||||
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)
|
||||
sys.stdout.flush()
|
||||
|
@ -169,6 +172,10 @@ async def main(
|
|||
content=input('💬 ')
|
||||
))
|
||||
|
||||
except aiohttp.ClientResponseError as e:
|
||||
sys.stdout.write(f'💥 {e}\n')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
typer.run(main)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue