Skip to content

Commit d18fbe3

Browse files
committed
refactor
1 parent 55474b7 commit d18fbe3

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lisette/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,17 @@ def mk_msg(content, # Content: str, bytes (image), list of mixed content, o
126126
def _extract_tool(text:str)->tuple[dict,dict]:
127127
"Extract tool call and results from <details> block"
128128
d = json.loads(text.strip())
129-
tc = ChatCompletionMessageToolCall(Function(dumps(d['call']['arguments']),d['call']['function']), d['id'],type='function')
130-
tr = {'role': 'tool','tool_call_id': d['id'],'name': d['call']['function'], 'content': d['result']}
129+
call = d['call']
130+
func = call['function']
131+
tc = ChatCompletionMessageToolCall(Function(dumps(call['arguments']),func), d['id'])
132+
tr = {'role': 'tool','tool_call_id': d['id'],'name': func, 'content': d['result']}
131133
return tc,tr
132134

133135
def fmt2hist(outp:str)->list:
134136
"Transform a formatted output into a LiteLLM compatible history"
135137
lm,hist = Message(),[]
136138
spt = re_tools.split(outp)
137-
for txt,_,tooljson in list(chunked(spt, 3, pad=True)):
139+
for txt,_,tooljson in chunked(spt, 3, pad=True):
138140
if txt.strip(): hist.append(lm:=Message(txt.strip()))
139141
if tooljson:
140142
tcr = _extract_tool(tooljson)

nbs/00_core.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,15 +781,17 @@
781781
"def _extract_tool(text:str)->tuple[dict,dict]:\n",
782782
" \"Extract tool call and results from <details> block\"\n",
783783
" d = json.loads(text.strip())\n",
784-
" tc = ChatCompletionMessageToolCall(Function(dumps(d['call']['arguments']),d['call']['function']), d['id'],type='function')\n",
785-
" tr = {'role': 'tool','tool_call_id': d['id'],'name': d['call']['function'], 'content': d['result']}\n",
784+
" call = d['call']\n",
785+
" func = call['function']\n",
786+
" tc = ChatCompletionMessageToolCall(Function(dumps(call['arguments']),func), d['id'])\n",
787+
" tr = {'role': 'tool','tool_call_id': d['id'],'name': func, 'content': d['result']}\n",
786788
" return tc,tr\n",
787789
"\n",
788790
"def fmt2hist(outp:str)->list:\n",
789791
" \"Transform a formatted output into a LiteLLM compatible history\"\n",
790792
" lm,hist = Message(),[]\n",
791793
" spt = re_tools.split(outp)\n",
792-
" for txt,_,tooljson in list(chunked(spt, 3, pad=True)):\n",
794+
" for txt,_,tooljson in chunked(spt, 3, pad=True):\n",
793795
" if txt.strip(): hist.append(lm:=Message(txt.strip()))\n",
794796
" if tooljson:\n",
795797
" tcr = _extract_tool(tooljson)\n",

0 commit comments

Comments
 (0)