Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import requests
|
|
| 6 |
import pandas as pd
|
| 7 |
import base64
|
| 8 |
import librosa
|
| 9 |
-
import
|
| 10 |
|
| 11 |
from typing import TypedDict, Annotated
|
| 12 |
from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage
|
|
@@ -65,7 +65,7 @@ def search_web(query: str) -> str:
|
|
| 65 |
"""Retrieves information about the topic."""
|
| 66 |
results = DuckDuckGoSearchRun().invoke(query)
|
| 67 |
if results:
|
| 68 |
-
return "\n\n".join([doc.text for doc in results[:
|
| 69 |
else:
|
| 70 |
return "No matching content found."
|
| 71 |
|
|
@@ -85,6 +85,8 @@ def extract_text_from_image(img_path: str) -> str:
|
|
| 85 |
print(error_msg)
|
| 86 |
return ""
|
| 87 |
|
|
|
|
|
|
|
| 88 |
|
| 89 |
# Initialize the tool
|
| 90 |
get_file_path_tool = Tool(
|
|
@@ -111,7 +113,13 @@ extract_text_tool = Tool(
|
|
| 111 |
description="Retrieves text from an image."
|
| 112 |
)
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
chat_with_tools = chat.bind_tools(tools, parallel_tool_calls=True)
|
| 116 |
|
| 117 |
|
|
@@ -131,7 +139,7 @@ builder = StateGraph(AgentState)
|
|
| 131 |
|
| 132 |
# Define nodes: these do the work
|
| 133 |
builder.add_node("assistant", assistant)
|
| 134 |
-
builder.add_node("tools", ToolNode([get_file_path_tool, get_content_tool, extract_text_tool, search_web_tool]))
|
| 135 |
|
| 136 |
# Define edges: these determine how the control flow moves
|
| 137 |
builder.add_edge(START, "assistant")
|
|
|
|
| 6 |
import pandas as pd
|
| 7 |
import base64
|
| 8 |
import librosa
|
| 9 |
+
import chess
|
| 10 |
|
| 11 |
from typing import TypedDict, Annotated
|
| 12 |
from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage
|
|
|
|
| 65 |
"""Retrieves information about the topic."""
|
| 66 |
results = DuckDuckGoSearchRun().invoke(query)
|
| 67 |
if results:
|
| 68 |
+
return "\n\n".join([doc.text for doc in results[:2]])
|
| 69 |
else:
|
| 70 |
return "No matching content found."
|
| 71 |
|
|
|
|
| 85 |
print(error_msg)
|
| 86 |
return ""
|
| 87 |
|
| 88 |
+
def play_chess()
|
| 89 |
+
return chess.Board()
|
| 90 |
|
| 91 |
# Initialize the tool
|
| 92 |
get_file_path_tool = Tool(
|
|
|
|
| 113 |
description="Retrieves text from an image."
|
| 114 |
)
|
| 115 |
|
| 116 |
+
play_chess_tool = Tool(
|
| 117 |
+
name="chess_board_retriever",
|
| 118 |
+
func=play_chess,
|
| 119 |
+
description="Sets a chess board."
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
tools = [get_file_path_tool, get_content_tool, extract_text_tool, search_web_tool, play_chess_tool]
|
| 123 |
chat_with_tools = chat.bind_tools(tools, parallel_tool_calls=True)
|
| 124 |
|
| 125 |
|
|
|
|
| 139 |
|
| 140 |
# Define nodes: these do the work
|
| 141 |
builder.add_node("assistant", assistant)
|
| 142 |
+
builder.add_node("tools", ToolNode([get_file_path_tool, get_content_tool, extract_text_tool, search_web_tool, play_chess_tool]))
|
| 143 |
|
| 144 |
# Define edges: these determine how the control flow moves
|
| 145 |
builder.add_edge(START, "assistant")
|