Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -153,31 +153,20 @@ def transcribe_audio(file_path: str, language: str = "en") -> str:
|
|
| 153 |
|
| 154 |
|
| 155 |
@tool
|
| 156 |
-
def
|
| 157 |
-
"""
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
@tool
|
| 161 |
-
def add(a: int, b: int) -> int:
|
| 162 |
-
"""Adds two numbers."""
|
| 163 |
-
return a + b
|
| 164 |
-
|
| 165 |
-
@tool
|
| 166 |
-
def subtract(a: int, b: int) -> int:
|
| 167 |
-
"""Subtracts two numbers."""
|
| 168 |
-
return a - b
|
| 169 |
-
|
| 170 |
-
@tool
|
| 171 |
-
def divide(a: int, b: int) -> float:
|
| 172 |
-
"""Divides two numbers."""
|
| 173 |
-
if b == 0:
|
| 174 |
-
raise ValueError("Cannot divide by zero.")
|
| 175 |
-
return a / b
|
| 176 |
-
|
| 177 |
-
@tool
|
| 178 |
-
def modulo(a: int, b: int) -> int:
|
| 179 |
-
"""Returns the remainder of dividing two numbers."""
|
| 180 |
-
return a % b
|
| 181 |
|
| 182 |
@tool
|
| 183 |
def wiki_search(query: str) -> str:
|
|
@@ -250,8 +239,7 @@ llm = ChatGoogleGenerativeAI(
|
|
| 250 |
model="gemini-2.0-flash",
|
| 251 |
google_api_key=GOOGLE_API_KEY,
|
| 252 |
temperature=0,
|
| 253 |
-
max_output_tokens=2048
|
| 254 |
-
system_message=system_prompt,
|
| 255 |
)
|
| 256 |
|
| 257 |
# === Tools in LLM einbinden ===
|
|
@@ -292,11 +280,10 @@ def safe_llm_invoke(messages):
|
|
| 292 |
|
| 293 |
# === Nodes für LangGraph ===
|
| 294 |
def assistant(state: MessagesState):
|
| 295 |
-
""
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
return {"messages": [result_msg]}
|
| 300 |
|
| 301 |
# === LangGraph bauen ===
|
| 302 |
builder = StateGraph(MessagesState)
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
@tool
|
| 156 |
+
def simple_calculator(operation: str, a: float, b: float) -> float:
|
| 157 |
+
"""Basic maths: add, subtract, multiply, divide and modulo."""
|
| 158 |
+
if operation == "add":
|
| 159 |
+
return a + b
|
| 160 |
+
if operation == "subtract":
|
| 161 |
+
return a - b
|
| 162 |
+
if operation == "multiply":
|
| 163 |
+
return a * b
|
| 164 |
+
if operation == "divide":
|
| 165 |
+
return a / b if b else float("inf")
|
| 166 |
+
if operation == "modulo":
|
| 167 |
+
return a % b
|
| 168 |
+
return 0.0
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
@tool
|
| 172 |
def wiki_search(query: str) -> str:
|
|
|
|
| 239 |
model="gemini-2.0-flash",
|
| 240 |
google_api_key=GOOGLE_API_KEY,
|
| 241 |
temperature=0,
|
| 242 |
+
max_output_tokens=2048
|
|
|
|
| 243 |
)
|
| 244 |
|
| 245 |
# === Tools in LLM einbinden ===
|
|
|
|
| 280 |
|
| 281 |
# === Nodes für LangGraph ===
|
| 282 |
def assistant(state: MessagesState):
|
| 283 |
+
msgs = state["messages"]
|
| 284 |
+
if not msgs or msgs[0].type != "system":
|
| 285 |
+
msgs = [system_prompt] + msgs
|
| 286 |
+
return {"messages": [llm_with_tools.invoke(msgs)]}
|
|
|
|
| 287 |
|
| 288 |
# === LangGraph bauen ===
|
| 289 |
builder = StateGraph(MessagesState)
|