Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,8 +17,11 @@ class Command:
|
|
| 17 |
# Set the API key from Hugging Face secrets
|
| 18 |
os.environ["ANTHROPIC_API_KEY"] = os.getenv("ANTHROPIC_API_KEY")
|
| 19 |
|
| 20 |
-
# Claude 3.5 Sonnet model
|
| 21 |
-
llm = ChatAnthropic(
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Utility to build system prompts
|
| 24 |
def make_system_prompt(suffix: str) -> str:
|
|
@@ -37,10 +40,8 @@ def research_node(state):
|
|
| 37 |
)
|
| 38 |
result = agent.invoke(state)
|
| 39 |
last_msg = result["messages"][-1]
|
| 40 |
-
|
| 41 |
# Determine next step
|
| 42 |
goto = "chart_generator" if "FINAL ANSWER" not in last_msg.content else "__end__"
|
| 43 |
-
|
| 44 |
result["messages"][-1] = HumanMessage(
|
| 45 |
content=last_msg.content,
|
| 46 |
name="researcher"
|
|
@@ -73,15 +74,13 @@ graph = workflow.compile()
|
|
| 73 |
# LangGraph runner
|
| 74 |
def run_langgraph(input_text):
|
| 75 |
try:
|
| 76 |
-
events = graph.stream({"messages": [(
|
| 77 |
output = list(events)
|
| 78 |
final_response = output[-1]["messages"][-1].content
|
| 79 |
-
|
| 80 |
if "FINAL ANSWER" in final_response:
|
| 81 |
# Dummy chart generation
|
| 82 |
years = [2020, 2021, 2022, 2023, 2024]
|
| 83 |
gdp = [21.4, 22.0, 23.1, 24.8, 26.2]
|
| 84 |
-
|
| 85 |
plt.figure()
|
| 86 |
plt.plot(years, gdp, marker="o")
|
| 87 |
plt.title("USA GDP Over Last 5 Years")
|
|
@@ -90,7 +89,6 @@ def run_langgraph(input_text):
|
|
| 90 |
plt.grid(True)
|
| 91 |
plt.tight_layout()
|
| 92 |
plt.savefig("gdp_chart.png")
|
| 93 |
-
|
| 94 |
return "Chart generated based on FINAL ANSWER.", "gdp_chart.png"
|
| 95 |
else:
|
| 96 |
return final_response, None
|
|
@@ -110,4 +108,4 @@ interface = gr.Interface(
|
|
| 110 |
)
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
-
interface.launch()
|
|
|
|
| 17 |
# Set the API key from Hugging Face secrets
|
| 18 |
os.environ["ANTHROPIC_API_KEY"] = os.getenv("ANTHROPIC_API_KEY")
|
| 19 |
|
| 20 |
+
# Claude 3.5 Sonnet model - remove any default parameters that might be causing issues
|
| 21 |
+
llm = ChatAnthropic(
|
| 22 |
+
model="claude-3-5-sonnet-20240229",
|
| 23 |
+
# No additional parameters that might cause conflicts
|
| 24 |
+
)
|
| 25 |
|
| 26 |
# Utility to build system prompts
|
| 27 |
def make_system_prompt(suffix: str) -> str:
|
|
|
|
| 40 |
)
|
| 41 |
result = agent.invoke(state)
|
| 42 |
last_msg = result["messages"][-1]
|
|
|
|
| 43 |
# Determine next step
|
| 44 |
goto = "chart_generator" if "FINAL ANSWER" not in last_msg.content else "__end__"
|
|
|
|
| 45 |
result["messages"][-1] = HumanMessage(
|
| 46 |
content=last_msg.content,
|
| 47 |
name="researcher"
|
|
|
|
| 74 |
# LangGraph runner
|
| 75 |
def run_langgraph(input_text):
|
| 76 |
try:
|
| 77 |
+
events = graph.stream({"messages": [HumanMessage(content=input_text)]})
|
| 78 |
output = list(events)
|
| 79 |
final_response = output[-1]["messages"][-1].content
|
|
|
|
| 80 |
if "FINAL ANSWER" in final_response:
|
| 81 |
# Dummy chart generation
|
| 82 |
years = [2020, 2021, 2022, 2023, 2024]
|
| 83 |
gdp = [21.4, 22.0, 23.1, 24.8, 26.2]
|
|
|
|
| 84 |
plt.figure()
|
| 85 |
plt.plot(years, gdp, marker="o")
|
| 86 |
plt.title("USA GDP Over Last 5 Years")
|
|
|
|
| 89 |
plt.grid(True)
|
| 90 |
plt.tight_layout()
|
| 91 |
plt.savefig("gdp_chart.png")
|
|
|
|
| 92 |
return "Chart generated based on FINAL ANSWER.", "gdp_chart.png"
|
| 93 |
else:
|
| 94 |
return final_response, None
|
|
|
|
| 108 |
)
|
| 109 |
|
| 110 |
if __name__ == "__main__":
|
| 111 |
+
interface.launch()
|