@@ -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