|
4372 | 4372 | "outputs": [], |
4373 | 4373 | "source": [ |
4374 | 4374 | "#| export\n", |
4375 | | - "def mk_tr_details(tr, tc):\n", |
| 4375 | + "def mk_tr_details(tr, tc, mx=2000):\n", |
4376 | 4376 | " \"Create <details> block for tool call as JSON\"\n", |
4377 | | - " args = {k:_trunc_str(v) for k,v in json.loads(tc.function.arguments).items()}\n", |
| 4377 | + " args = {k:_trunc_str(v, mx=mx) for k,v in json.loads(tc.function.arguments).items()}\n", |
4378 | 4378 | " res = {'id':tr['tool_call_id'], \n", |
4379 | 4379 | " 'call':{'function': tc.function.name, 'arguments': args},\n", |
4380 | | - " 'result':_trunc_str(tr.get('content')),}\n", |
| 4380 | + " 'result':_trunc_str(tr.get('content'), mx=mx),}\n", |
4381 | 4381 | " return f\"\\n\\n{detls_tag}\\n\\n```json\\n{dumps(res, indent=2)}\\n```\\n\\n</details>\\n\\n\"" |
4382 | 4382 | ] |
4383 | 4383 | }, |
|
4411 | 4411 | "source": [ |
4412 | 4412 | "#| export\n", |
4413 | 4413 | "class AsyncStreamFormatter:\n", |
4414 | | - " def __init__(self, include_usage=False):\n", |
4415 | | - " self.outp,self.tcs,self.include_usage,self.think = '',{},include_usage,False\n", |
| 4414 | + " def __init__(self, include_usage=False, mx=2000):\n", |
| 4415 | + " self.outp,self.tcs,self.include_usage,self.think,self.mx = '',{},include_usage,False,mx\n", |
4416 | 4416 | " \n", |
4417 | 4417 | " def format_item(self, o):\n", |
4418 | 4418 | " \"Format a single item from the response stream.\"\n", |
|
4431 | 4431 | " if c:=getattr(o.choices[0].message,'tool_calls',None):\n", |
4432 | 4432 | " self.tcs = {tc.id:tc for tc in c}\n", |
4433 | 4433 | " elif isinstance(o, dict) and 'tool_call_id' in o:\n", |
4434 | | - " res += mk_tr_details(o, self.tcs.pop(o['tool_call_id']))\n", |
| 4434 | + " res += mk_tr_details(o, self.tcs.pop(o['tool_call_id']), mx=self.mx)\n", |
4435 | 4435 | " self.outp+=res\n", |
4436 | 4436 | " return res\n", |
4437 | 4437 | " \n", |
|
0 commit comments