Skip to content

Commit ed14ec3

Browse files
react: instruct=False support
1 parent 5ea5557 commit ed14ec3

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

src/lmql/lib/actions.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ async def eval_or_acc(last_line, code_env, acc):
306306
return "", None
307307

308308
@lmql.query
309-
async def reAct(fcts):
309+
async def reAct(fcts, instruct=True):
310310
'''lmql
311-
incontext
311+
if instruct:
312312
"""
313313
Instructions: In your reasoning adhere to the following structure:
314314
@@ -324,41 +324,39 @@ async def reAct(fcts):
324324
325325
for fct in action_fcts.values():
326326
" - {fct.name}: {fct.description}. Usage: {fct.example}. Observation: {fct.example_result}\n"
327-
327+
328328
"Now you can start reasoning.\n"
329-
330-
offset = len(context.prompt)
331329
332-
while True:
333-
"[SEGMENT]"
330+
offset = len(context.prompt)
331+
332+
while True:
333+
"[SEGMENT]" where STOPS_AT(SEGMENT, "Action:")
334334
335-
if not SEGMENT.endswith("Action:"):
336-
break
335+
if not SEGMENT.endswith("Action:"):
336+
break
337+
else:
338+
"[CALL]" where STOPS_AT(CALL, "\n")
339+
340+
if not CALL.endswith("\n") or not "(" in CALL:
341+
continue
337342
else:
338-
"[CALL]"
339-
340-
if not CALL.endswith("\n") or not "(" in CALL:
341-
continue
343+
"Observation:"
344+
action, args = CALL.split("(", 1)
345+
action = action.strip()
346+
if action not in action_fcts.keys():
347+
print("unknown action", [action], list(action_fcts.keys()))
348+
" Unknown action: {action}\n"
349+
result = ""
342350
else:
343-
"Observation:"
344-
action, args = CALL.split("(", 1)
345-
action = action.strip()
346-
if action not in action_fcts.keys():
347-
print("unknown action", [action], list(action_fcts.keys()))
348-
" Unknown action: {action}\n"
349-
result = ""
350-
else:
351-
try:
352-
result = await action_fcts[action].call("(" + args)
353-
if type(result) is float:
354-
result = round(result, 2)
355-
" {result}\n"
356-
except Exception:
357-
" Error. Try differently.\n"
358-
359-
return "\n" + context.prompt[offset:]
360-
where
361-
STOPS_AT(SEGMENT, "Action:") and STOPS_AT(CALL, "\n")
351+
try:
352+
result = await action_fcts[action].call("(" + args)
353+
if type(result) is float:
354+
result = round(result, 2)
355+
" {result}\n"
356+
except Exception:
357+
" Error. Try differently.\n"
358+
359+
return "\n" + context.prompt[offset:]
362360
'''
363361

364362

0 commit comments

Comments
 (0)