Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,6 +69,7 @@ class State(TypedDict):
|
|
| 69 |
props_string: str
|
| 70 |
loop_again: str
|
| 71 |
which_pdbs: int
|
|
|
|
| 72 |
#(Literal["lipinski_tool", "substitution_tool", "pharm_feature_tool"],
|
| 73 |
# Literal["lipinski_tool", "substitution_tool", "pharm_feature_tool"])
|
| 74 |
|
|
@@ -626,6 +627,7 @@ def first_node(state: State) -> State:
|
|
| 626 |
state["props_string"] = props_string
|
| 627 |
state["loop_again"] = None
|
| 628 |
state['which_pdbs'] = 0
|
|
|
|
| 629 |
|
| 630 |
raw_input = state["messages"][-1].content
|
| 631 |
parts = raw_input.split(',')
|
|
@@ -722,7 +724,7 @@ should be called before this tool.
|
|
| 722 |
else:
|
| 723 |
tool_choice = (None, None)
|
| 724 |
if (len(tool_choice) == 2) and (tool_choice[1] == tool_choice[0]):
|
| 725 |
-
tool_choice = (
|
| 726 |
|
| 727 |
state["tool_choice"] = tool_choice
|
| 728 |
state["which_tool"] = 0
|
|
@@ -853,7 +855,10 @@ def parser_node(state: State) -> State:
|
|
| 853 |
elif type(tool_choice) == tuple and (tool_choice[0] == None) and (tool_choice[1] == None):
|
| 854 |
state["loop_again"] = "finish_gracefully"
|
| 855 |
return state
|
| 856 |
-
|
|
|
|
|
|
|
|
|
|
| 857 |
prompt = f'Using the CONTEXT below, answer the original query, which \
|
| 858 |
was to answer the QUERY_TASK. Remember that novel molecules generated in the CONTEXT \
|
| 859 |
were made using a fine-tuned GPT. End your answer with a "#" \
|
|
@@ -877,6 +882,7 @@ QUERY_TASK: {query_task}.\n'
|
|
| 877 |
|
| 878 |
if str(res).split('<|assistant|>')[1].split('#')[0].strip().lower() == "loop":
|
| 879 |
state["loop_again"] = "loop_again"
|
|
|
|
| 880 |
return state
|
| 881 |
elif str(res).split('<|assistant|>')[1].split('#')[0].strip().lower() == "proceed":
|
| 882 |
state["loop_again"] = None
|
|
@@ -885,6 +891,8 @@ QUERY_TASK: {query_task}.\n'
|
|
| 885 |
state["loop_again"] = None
|
| 886 |
print('trying to break loop')
|
| 887 |
|
|
|
|
|
|
|
| 888 |
return state
|
| 889 |
|
| 890 |
def reflect_node(state: State) -> State:
|
|
|
|
| 69 |
props_string: str
|
| 70 |
loop_again: str
|
| 71 |
which_pdbs: int
|
| 72 |
+
recursion_count: int
|
| 73 |
#(Literal["lipinski_tool", "substitution_tool", "pharm_feature_tool"],
|
| 74 |
# Literal["lipinski_tool", "substitution_tool", "pharm_feature_tool"])
|
| 75 |
|
|
|
|
| 627 |
state["props_string"] = props_string
|
| 628 |
state["loop_again"] = None
|
| 629 |
state['which_pdbs'] = 0
|
| 630 |
+
state['recursion_count'] = 0
|
| 631 |
|
| 632 |
raw_input = state["messages"][-1].content
|
| 633 |
parts = raw_input.split(',')
|
|
|
|
| 724 |
else:
|
| 725 |
tool_choice = (None, None)
|
| 726 |
if (len(tool_choice) == 2) and (tool_choice[1] == tool_choice[0]):
|
| 727 |
+
tool_choice = (tool_choice[0], None)
|
| 728 |
|
| 729 |
state["tool_choice"] = tool_choice
|
| 730 |
state["which_tool"] = 0
|
|
|
|
| 855 |
elif type(tool_choice) == tuple and (tool_choice[0] == None) and (tool_choice[1] == None):
|
| 856 |
state["loop_again"] = "finish_gracefully"
|
| 857 |
return state
|
| 858 |
+
elif state['recursion_count'] > 20:
|
| 859 |
+
state["loop_again"] = "finish_gracefully"
|
| 860 |
+
return state
|
| 861 |
+
|
| 862 |
prompt = f'Using the CONTEXT below, answer the original query, which \
|
| 863 |
was to answer the QUERY_TASK. Remember that novel molecules generated in the CONTEXT \
|
| 864 |
were made using a fine-tuned GPT. End your answer with a "#" \
|
|
|
|
| 882 |
|
| 883 |
if str(res).split('<|assistant|>')[1].split('#')[0].strip().lower() == "loop":
|
| 884 |
state["loop_again"] = "loop_again"
|
| 885 |
+
state['recursion_count'] += 1
|
| 886 |
return state
|
| 887 |
elif str(res).split('<|assistant|>')[1].split('#')[0].strip().lower() == "proceed":
|
| 888 |
state["loop_again"] = None
|
|
|
|
| 891 |
state["loop_again"] = None
|
| 892 |
print('trying to break loop')
|
| 893 |
|
| 894 |
+
state['recursion_count'] += 1
|
| 895 |
+
|
| 896 |
return state
|
| 897 |
|
| 898 |
def reflect_node(state: State) -> State:
|