Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -252,20 +252,26 @@ returns the names, SMILES strings, molecular weights and logP values for the rel
|
|
| 252 |
tool_choices = str(res).replace('smilars', 'smiles').split('<|assistant|>')[1].split('#')[0].strip()
|
| 253 |
tool_choices = tool_choices.split(',')
|
| 254 |
print(tool_choices)
|
|
|
|
| 255 |
if len(tool_choices) == 1:
|
| 256 |
-
|
|
|
|
| 257 |
tool_choice = (None, None)
|
| 258 |
else:
|
| 259 |
-
tool_choice = (
|
| 260 |
-
elif len(tool_choices)
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
tool_choice = (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
else:
|
| 266 |
-
tool_choice = (
|
| 267 |
else:
|
| 268 |
-
tool_choice = None
|
| 269 |
|
| 270 |
state["tool_choice"] = tool_choice
|
| 271 |
state["which_tool"] = 0
|
|
@@ -358,14 +364,25 @@ def parser_node(state: State) -> State:
|
|
| 358 |
state["loop_again"] = "finish_gracefully"
|
| 359 |
return state
|
| 360 |
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
to answer the QUERY TASK, respond with "LOOP #" \n \
|
| 364 |
-
QUERY_TASK: {query_task} \n \
|
| 365 |
CONTEXT: {props_string}.\n \
|
| 366 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
res = chat_model.invoke(check_prompt)
|
|
|
|
| 369 |
|
| 370 |
if str(res).split('<|assistant|>')[1].split('#')[0].strip().lower() == "loop":
|
| 371 |
state["loop_again"] = "loop_again"
|
|
@@ -377,14 +394,7 @@ CONTEXT: {props_string}.\n \
|
|
| 377 |
state["loop_again"] = None
|
| 378 |
print('trying to break loop')
|
| 379 |
|
| 380 |
-
|
| 381 |
-
was to answer the QUERY_TASK. End your answer with a "#" \
|
| 382 |
-
CONTEXT: {props_string}.\n \
|
| 383 |
-
QUERY_TASK: {query_task}.\n '
|
| 384 |
-
|
| 385 |
-
res = chat_model.invoke(prompt)
|
| 386 |
-
|
| 387 |
-
return {"messages": res}
|
| 388 |
|
| 389 |
def reflect_node(state: State) -> State:
|
| 390 |
'''
|
|
|
|
| 252 |
tool_choices = str(res).replace('smilars', 'smiles').split('<|assistant|>')[1].split('#')[0].strip()
|
| 253 |
tool_choices = tool_choices.split(',')
|
| 254 |
print(tool_choices)
|
| 255 |
+
|
| 256 |
if len(tool_choices) == 1:
|
| 257 |
+
tool1 = tool_choices[0.strip()
|
| 258 |
+
if tool1.lower() == 'none':
|
| 259 |
tool_choice = (None, None)
|
| 260 |
else:
|
| 261 |
+
tool_choice = (tool1, None)
|
| 262 |
+
elif len(tool_choices) == 2:
|
| 263 |
+
tool1 = agents_list[0]
|
| 264 |
+
tool2 = agents_list[1]
|
| 265 |
+
if tool1.lower() == 'none' and tool2.lower() == 'none':
|
| 266 |
+
tool_choice = (None, None)
|
| 267 |
+
elif tool1.lower() == 'none' and tool2.lower() != 'none':
|
| 268 |
+
tool_choice = (None, tool2)
|
| 269 |
+
elif tool2.lower() == 'none' and tool1.lower() != 'none':
|
| 270 |
+
tool_choice = (tool1, None)
|
| 271 |
else:
|
| 272 |
+
tool_choice = (tool1, tool2)
|
| 273 |
else:
|
| 274 |
+
tool_choice = (None, None)
|
| 275 |
|
| 276 |
state["tool_choice"] = tool_choice
|
| 277 |
state["which_tool"] = 0
|
|
|
|
| 364 |
state["loop_again"] = "finish_gracefully"
|
| 365 |
return state
|
| 366 |
|
| 367 |
+
prompt = f'Using the CONTEXT below, answer the original query, which \
|
| 368 |
+
was to answer the QUERY_TASK. End your answer with a "#" \
|
|
|
|
|
|
|
| 369 |
CONTEXT: {props_string}.\n \
|
| 370 |
+
QUERY_TASK: {query_task}.\n '
|
| 371 |
+
|
| 372 |
+
res = chat_model.invoke(prompt)
|
| 373 |
+
trial_answer = str(res).split('<|assistant|>')[1]
|
| 374 |
+
print('parser 1 ', trial_answer)
|
| 375 |
+
state["messages"] = res
|
| 376 |
+
|
| 377 |
+
check_prompt = f'Determine if the TRIAL ANSWER below answers the original \
|
| 378 |
+
QUERY TASK. If it does, respond with "PROCEED #" . If the TRIAL ANSWER did not \
|
| 379 |
+
answer the QUERY TASK, respond with "LOOP #" \n \
|
| 380 |
+
Only loop again if the TRIAL ANSWER did not answer the QUERY TASK. \
|
| 381 |
+
TRIAL ANSWER: {trial_answer}.\n \
|
| 382 |
+
QUERY_TASK: {query_task}.\n'
|
| 383 |
|
| 384 |
res = chat_model.invoke(check_prompt)
|
| 385 |
+
print('parser, loop again? ', res)
|
| 386 |
|
| 387 |
if str(res).split('<|assistant|>')[1].split('#')[0].strip().lower() == "loop":
|
| 388 |
state["loop_again"] = "loop_again"
|
|
|
|
| 394 |
state["loop_again"] = None
|
| 395 |
print('trying to break loop')
|
| 396 |
|
| 397 |
+
return state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
|
| 399 |
def reflect_node(state: State) -> State:
|
| 400 |
'''
|