RuaZhou commited on
Commit
4c4b402
·
verified ·
1 Parent(s): 6b96d56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -3
app.py CHANGED
@@ -7,7 +7,8 @@ from langchain_core.documents import Document
7
  import base64
8
  from langchain_core.messages import HumanMessage
9
  from langchain_openai import ChatOpenAI
10
- from langchain_community.tools.ddg_search.tool import DuckDuckGoSearchTool
 
11
  # (Keep Constants as is)
12
  # --- Constants ---
13
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -41,7 +42,7 @@ tools = [
41
  add,
42
  subtract,
43
  search,
44
- DuckDuckGoSearchTool()
45
  ]
46
  ###### state and behavior
47
  from typing import TypedDict, Annotated, Optional
@@ -52,7 +53,51 @@ from langgraph.graph.message import add_messages
52
  class AgentState(TypedDict):
53
  # The input document
54
  messages: Annotated[list[AnyMessage], add_messages]
55
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  ################ state
57
  class BasicAgent:
58
  def __init__(self):
 
7
  import base64
8
  from langchain_core.messages import HumanMessage
9
  from langchain_openai import ChatOpenAI
10
+ from langchain_community.tools import DuckDuckGoSearchResults
11
+
12
  # (Keep Constants as is)
13
  # --- Constants ---
14
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
42
  add,
43
  subtract,
44
  search,
45
+ DuckDuckGoSearchResults()
46
  ]
47
  ###### state and behavior
48
  from typing import TypedDict, Annotated, Optional
 
53
  class AgentState(TypedDict):
54
  # The input document
55
  messages: Annotated[list[AnyMessage], add_messages]
56
+
57
+ from langchain_core.messages import HumanMessage, SystemMessage
58
+
59
+ # from langchain_core.tools import tool # non necessary with toolNode
60
+
61
+ # @tool
62
+ # def multiply(a: int, b: int) -> int:
63
+ # """Multiply a and b."""
64
+ # return a * b
65
+
66
+ def assistant(state: AgentState):
67
+ # System message
68
+ textual_description_of_tool = """
69
+ DuckDuckGoSearchResults():
70
+ Search for information in the internet through DuckDuckGo engine
71
+
72
+ Returns:
73
+ Snipnet of information from search engine.
74
+
75
+ divide(a: int|float, b: int|float) -> float:
76
+ Divide a and b.
77
+ Returns:
78
+ The result of A divided by B if B!=0
79
+
80
+ multiply(a: int|float, b: int|float) -> float:
81
+ Multiply a with b.
82
+ Returns:
83
+ The result of A multiplied by B
84
+
85
+ add(a: int|float, b: int|float) -> float:
86
+ Add a and b.
87
+ Returns:
88
+ The result of A adding B.
89
+
90
+ Substract(a: int|float, b: int|float) -> float:
91
+ Substract a with b.
92
+ Returns:
93
+ The result of a minus b.
94
+
95
+ """
96
+ previous_message = state["messages"]
97
+ sys_msg = SystemMessage(content=f"You are an helpful agent that can analyse some images and run some computatio without provided tools :\n{textual_description_of_tool} \n You have access to some otpional images. Currently the loaded images is : {image}")
98
+
99
+ return {"messages": [llm_with_tools.invoke([sys_msg] + state["messages"])], "input_file": state["input_file"]}
100
+
101
  ################ state
102
  class BasicAgent:
103
  def __init__(self):