Skip to content

Commit 55474b7

Browse files
committed
mx
1 parent 26d83e2 commit 55474b7

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

lisette/core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,18 @@ def _trunc_str(s, mx=2000, replace="<TRUNCATED>"):
388388
return s[:mx]+replace if len(s)>mx else s
389389

390390
# %% ../nbs/00_core.ipynb
391-
def mk_tr_details(tr, tc):
391+
def mk_tr_details(tr, tc, mx=2000):
392392
"Create <details> block for tool call as JSON"
393-
args = {k:_trunc_str(v) for k,v in json.loads(tc.function.arguments).items()}
393+
args = {k:_trunc_str(v, mx=mx) for k,v in json.loads(tc.function.arguments).items()}
394394
res = {'id':tr['tool_call_id'],
395395
'call':{'function': tc.function.name, 'arguments': args},
396-
'result':_trunc_str(tr.get('content')),}
396+
'result':_trunc_str(tr.get('content'), mx=mx),}
397397
return f"\n\n{detls_tag}\n\n```json\n{dumps(res, indent=2)}\n```\n\n</details>\n\n"
398398

399399
# %% ../nbs/00_core.ipynb
400400
class AsyncStreamFormatter:
401-
def __init__(self, include_usage=False):
402-
self.outp,self.tcs,self.include_usage,self.think = '',{},include_usage,False
401+
def __init__(self, include_usage=False, mx=2000):
402+
self.outp,self.tcs,self.include_usage,self.think,self.mx = '',{},include_usage,False,mx
403403

404404
def format_item(self, o):
405405
"Format a single item from the response stream."
@@ -418,7 +418,7 @@ def format_item(self, o):
418418
if c:=getattr(o.choices[0].message,'tool_calls',None):
419419
self.tcs = {tc.id:tc for tc in c}
420420
elif isinstance(o, dict) and 'tool_call_id' in o:
421-
res += mk_tr_details(o, self.tcs.pop(o['tool_call_id']))
421+
res += mk_tr_details(o, self.tcs.pop(o['tool_call_id']), mx=self.mx)
422422
self.outp+=res
423423
return res
424424

nbs/00_core.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4372,12 +4372,12 @@
43724372
"outputs": [],
43734373
"source": [
43744374
"#| export\n",
4375-
"def mk_tr_details(tr, tc):\n",
4375+
"def mk_tr_details(tr, tc, mx=2000):\n",
43764376
" \"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",
43784378
" res = {'id':tr['tool_call_id'], \n",
43794379
" '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",
43814381
" return f\"\\n\\n{detls_tag}\\n\\n```json\\n{dumps(res, indent=2)}\\n```\\n\\n</details>\\n\\n\""
43824382
]
43834383
},
@@ -4411,8 +4411,8 @@
44114411
"source": [
44124412
"#| export\n",
44134413
"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",
44164416
" \n",
44174417
" def format_item(self, o):\n",
44184418
" \"Format a single item from the response stream.\"\n",
@@ -4431,7 +4431,7 @@
44314431
" if c:=getattr(o.choices[0].message,'tool_calls',None):\n",
44324432
" self.tcs = {tc.id:tc for tc in c}\n",
44334433
" 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",
44354435
" self.outp+=res\n",
44364436
" return res\n",
44374437
" \n",

0 commit comments

Comments
 (0)