Spaces:
Sleeping
Sleeping
WilliamGazeley
commited on
Commit
·
bbded71
1
Parent(s):
3651997
Fix threading issue
Browse files- src/app.py +12 -4
- src/functioncall.py +3 -3
- src/functions.py +3 -3
- src/prompts/output_agent_template.yaml +1 -0
src/app.py
CHANGED
@@ -35,7 +35,7 @@ def question_node(state: GraphState) -> Dict[str, str]:
|
|
35 |
Generate a question for the function agent.
|
36 |
"""
|
37 |
logger.info("Generating question for function agent")
|
38 |
-
config.status.update(label=":question: Breaking down question")
|
39 |
question = state["question"]
|
40 |
logger.info(f"Original question: {question}")
|
41 |
rephrased_question = agents["rephrase_agent"].invoke({"question": question})
|
@@ -49,7 +49,7 @@ def function_agent_node(state: GraphState) -> Literal["finished"]:
|
|
49 |
logger.info("Calling function agent")
|
50 |
question = state["rephrased_question"]
|
51 |
response = agents["function_agent"].invoke({"input": question, "tools": tools_dict}).get("output")
|
52 |
-
config.status.update(label=":brain: Analysing data..")
|
53 |
logger.info(f"Function agent output: {response}")
|
54 |
return {"function_agent_output": response}
|
55 |
|
@@ -58,7 +58,7 @@ def output_node(state: GraphState) -> Dict[str, str]:
|
|
58 |
Generate the final output
|
59 |
"""
|
60 |
logger.info("Generating output")
|
61 |
-
config.status.update(label=":bulb: Preparing response..")
|
62 |
generation = agents["output_agent"].invoke({"context": state["function_agent_output"],
|
63 |
"question": state["rephrased_question"]})
|
64 |
return {"generation": generation}
|
@@ -70,7 +70,7 @@ def route_question(state: GraphState) -> Literal["vectorstore", "websearch"]:
|
|
70 |
Route quesition to web search or RAG
|
71 |
"""
|
72 |
logger.info("Routing question")
|
73 |
-
config.state.update(label=":chart_with_upwards_trend: Routing question")
|
74 |
question = state["question"]
|
75 |
logger.info(f"Question: {question}")
|
76 |
source = agents["router_agent"].invoke({"question": question})
|
@@ -96,6 +96,12 @@ workflow.set_finish_point("output_node")
|
|
96 |
|
97 |
flow = workflow.compile()
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
def main():
|
100 |
st.title("LLM-ADE 9B Demo")
|
101 |
|
@@ -105,8 +111,10 @@ def main():
|
|
105 |
if input_text:
|
106 |
with st.status("Generating response...") as status:
|
107 |
config.status = status
|
|
|
108 |
for output in flow.stream({"question": input_text}):
|
109 |
for key, value in output.items():
|
|
|
110 |
pprint(f"Finished running: {key}")
|
111 |
st.write(value["generation"])
|
112 |
config.status.update(label="Finished!", state="complete", expanded=True)
|
|
|
35 |
Generate a question for the function agent.
|
36 |
"""
|
37 |
logger.info("Generating question for function agent")
|
38 |
+
# config.status.update(label=":question: Breaking down question")
|
39 |
question = state["question"]
|
40 |
logger.info(f"Original question: {question}")
|
41 |
rephrased_question = agents["rephrase_agent"].invoke({"question": question})
|
|
|
49 |
logger.info("Calling function agent")
|
50 |
question = state["rephrased_question"]
|
51 |
response = agents["function_agent"].invoke({"input": question, "tools": tools_dict}).get("output")
|
52 |
+
# config.status.update(label=":brain: Analysing data..")
|
53 |
logger.info(f"Function agent output: {response}")
|
54 |
return {"function_agent_output": response}
|
55 |
|
|
|
58 |
Generate the final output
|
59 |
"""
|
60 |
logger.info("Generating output")
|
61 |
+
# config.status.update(label=":bulb: Preparing response..")
|
62 |
generation = agents["output_agent"].invoke({"context": state["function_agent_output"],
|
63 |
"question": state["rephrased_question"]})
|
64 |
return {"generation": generation}
|
|
|
70 |
Route quesition to web search or RAG
|
71 |
"""
|
72 |
logger.info("Routing question")
|
73 |
+
# config.state.update(label=":chart_with_upwards_trend: Routing question")
|
74 |
question = state["question"]
|
75 |
logger.info(f"Question: {question}")
|
76 |
source = agents["router_agent"].invoke({"question": question})
|
|
|
96 |
|
97 |
flow = workflow.compile()
|
98 |
|
99 |
+
progress_map = {
|
100 |
+
"question_rephrase": ":question: Breaking down question",
|
101 |
+
"function_agent": ":mag: Collecting data",
|
102 |
+
"output_node": ":bulb: Preparing response",
|
103 |
+
}
|
104 |
+
|
105 |
def main():
|
106 |
st.title("LLM-ADE 9B Demo")
|
107 |
|
|
|
111 |
if input_text:
|
112 |
with st.status("Generating response...") as status:
|
113 |
config.status = status
|
114 |
+
config.status.update(label=":brain: Thinking")
|
115 |
for output in flow.stream({"question": input_text}):
|
116 |
for key, value in output.items():
|
117 |
+
config.status.update(label=progress_map[key])
|
118 |
pprint(f"Finished running: {key}")
|
119 |
st.write(value["generation"])
|
120 |
config.status.update(label="Finished!", state="complete", expanded=True)
|
src/functioncall.py
CHANGED
@@ -54,7 +54,7 @@ class ModelInference:
|
|
54 |
raise ValueError("Assistant message is None")
|
55 |
|
56 |
def execute_function_call(self, tool_call):
|
57 |
-
config.status.update(label=":mag: Gathering information..")
|
58 |
function_name = tool_call.get("name")
|
59 |
function_to_call = getattr(functions, function_name, None)
|
60 |
function_args = tool_call.get("arguments", {})
|
@@ -81,7 +81,7 @@ class ModelInference:
|
|
81 |
chat = [{"role": "user", "content": user_message}]
|
82 |
tools = functions.get_openai_tools()
|
83 |
prompt = self.prompter.generate_prompt(chat, tools, num_fewshot)
|
84 |
-
config.status.update(label=":brain: Thinking..")
|
85 |
completion = self.run_inference(prompt)
|
86 |
|
87 |
def recursive_loop(prompt, completion, depth):
|
@@ -115,7 +115,7 @@ class ModelInference:
|
|
115 |
completion = self.run_inference(prompt)
|
116 |
return completion
|
117 |
|
118 |
-
config.status.update(label=":brain: Analysing information..")
|
119 |
completion = self.run_inference(prompt)
|
120 |
return recursive_loop(prompt, completion, depth)
|
121 |
elif error_message:
|
|
|
54 |
raise ValueError("Assistant message is None")
|
55 |
|
56 |
def execute_function_call(self, tool_call):
|
57 |
+
# config.status.update(label=":mag: Gathering information..")
|
58 |
function_name = tool_call.get("name")
|
59 |
function_to_call = getattr(functions, function_name, None)
|
60 |
function_args = tool_call.get("arguments", {})
|
|
|
81 |
chat = [{"role": "user", "content": user_message}]
|
82 |
tools = functions.get_openai_tools()
|
83 |
prompt = self.prompter.generate_prompt(chat, tools, num_fewshot)
|
84 |
+
# config.status.update(label=":brain: Thinking..")
|
85 |
completion = self.run_inference(prompt)
|
86 |
|
87 |
def recursive_loop(prompt, completion, depth):
|
|
|
115 |
completion = self.run_inference(prompt)
|
116 |
return completion
|
117 |
|
118 |
+
# config.status.update(label=":brain: Analysing information..")
|
119 |
completion = self.run_inference(prompt)
|
120 |
return recursive_loop(prompt, completion, depth)
|
121 |
elif error_message:
|
src/functions.py
CHANGED
@@ -113,7 +113,7 @@ def get_current_stock_price(symbol: str) -> float:
|
|
113 |
float: The current stock price, or None if an error occurs.
|
114 |
"""
|
115 |
try:
|
116 |
-
config.status.update(label=":chart_with_upwards_trend: Getting price")
|
117 |
stock = yf.Ticker(symbol)
|
118 |
# Use "regularMarketPrice" for regular market hours, or "currentPrice" for pre/post market
|
119 |
current_price = stock.info.get("regularMarketPrice", stock.info.get("currentPrice"))
|
@@ -199,7 +199,7 @@ def get_key_financial_ratios(symbol: str) -> dict:
|
|
199 |
dict: Dictionary containing key financial ratios.
|
200 |
"""
|
201 |
try:
|
202 |
-
config.status.update(label=":chart_with_upwards_trend: Gathering financial data")
|
203 |
stock = yf.Ticker(symbol)
|
204 |
key_ratios = stock.info
|
205 |
return key_ratios
|
@@ -238,7 +238,7 @@ def get_company_news(symbol: str) -> pd.DataFrame:
|
|
238 |
Returns:
|
239 |
pd.DataFrame: DataFrame containing company news and press releases.
|
240 |
"""
|
241 |
-
config.status.update(label=":newspaper: Getting news")
|
242 |
try:
|
243 |
news = yf.Ticker(symbol).news
|
244 |
return news
|
|
|
113 |
float: The current stock price, or None if an error occurs.
|
114 |
"""
|
115 |
try:
|
116 |
+
# config.status.update(label=":chart_with_upwards_trend: Getting price")
|
117 |
stock = yf.Ticker(symbol)
|
118 |
# Use "regularMarketPrice" for regular market hours, or "currentPrice" for pre/post market
|
119 |
current_price = stock.info.get("regularMarketPrice", stock.info.get("currentPrice"))
|
|
|
199 |
dict: Dictionary containing key financial ratios.
|
200 |
"""
|
201 |
try:
|
202 |
+
# config.status.update(label=":chart_with_upwards_trend: Gathering financial data")
|
203 |
stock = yf.Ticker(symbol)
|
204 |
key_ratios = stock.info
|
205 |
return key_ratios
|
|
|
238 |
Returns:
|
239 |
pd.DataFrame: DataFrame containing company news and press releases.
|
240 |
"""
|
241 |
+
# config.status.update(label=":newspaper: Getting news")
|
242 |
try:
|
243 |
news = yf.Ticker(symbol).news
|
244 |
return news
|
src/prompts/output_agent_template.yaml
CHANGED
@@ -22,6 +22,7 @@ Do not be formal, answer as you would in a conversation with a friend.
|
|
22 |
Keep your response short unless the question requires a longer response.
|
23 |
#Audience:
|
24 |
You are talking to a high net worth individual with high risk tolerance and lots of investing experience - they do not need traditional, generic financial advice.
|
|
|
25 |
\n ------- \n
|
26 |
Your thoughts are as follows:
|
27 |
{context}
|
|
|
22 |
Keep your response short unless the question requires a longer response.
|
23 |
#Audience:
|
24 |
You are talking to a high net worth individual with high risk tolerance and lots of investing experience - they do not need traditional, generic financial advice.
|
25 |
+
Address the user directly.
|
26 |
\n ------- \n
|
27 |
Your thoughts are as follows:
|
28 |
{context}
|