Spaces:
Runtime error
Runtime error
init
Browse files- app.py +34 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Chat agent using LlamaIndex SimpleChatEngine + Gradio
|
| 2 |
+
from llama_index.core.agent.workflow import {
|
| 3 |
+
AgentWorkflow,
|
| 4 |
+
FunctionAgent,
|
| 5 |
+
ReactAgent,
|
| 6 |
+
}
|
| 7 |
+
from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
|
| 8 |
+
|
| 9 |
+
def add(a: int, b: int) -> int:
|
| 10 |
+
"""Adds two numbers together and returns the result."""
|
| 11 |
+
return a + b
|
| 12 |
+
|
| 13 |
+
def subtract(a: int, b: int) -> int:
|
| 14 |
+
"""Subtracts the second number from the first and returns the result."""
|
| 15 |
+
return a - b
|
| 16 |
+
|
| 17 |
+
llm = HuggingFaceInferenceAPI(
|
| 18 |
+
model_name="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
calculator_agent = ReActAgent(
|
| 22 |
+
name="calculator_agent",
|
| 23 |
+
description="A calculator agent that can add and subtract numbers.",
|
| 24 |
+
tools=[add, subtract],
|
| 25 |
+
llm=llm,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
agent = AgentWorkflow(
|
| 29 |
+
agents=[calculator_agent],
|
| 30 |
+
root_agent="calculator_agent",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
response = agent.chat(user_msg="What is 10 + 5?")
|
| 34 |
+
print(response)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
llama-index
|
| 2 |
+
llama-index-vector-stores-chroma
|
| 3 |
+
llama-index-llms-huggingface-api
|
| 4 |
+
llama-index-embeddings-huggingface
|