30 lines
700 B
Python
30 lines
700 B
Python
import asyncio
|
|
from llama_index.core.agent import ReActAgent
|
|
from llama_index.core.tools import FunctionTool
|
|
from llama_index.llms.dashscope import DashScope
|
|
|
|
|
|
# Define a simple calculator tool
|
|
def multiply(a: float, b: float) -> float:
|
|
"""Useful for multiplying two numbers."""
|
|
return a * b
|
|
|
|
|
|
# Create an agent workflow with our calculator tool
|
|
llm = DashScope(model_name="qwen-max")
|
|
agent = ReActAgent.from_tools(
|
|
tools=[FunctionTool.from_defaults(fn=multiply)],
|
|
llm=llm,
|
|
verbose=True,
|
|
)
|
|
|
|
|
|
async def main():
|
|
# Run the agent
|
|
response = await agent.achat("What is 1234 * 4567?")
|
|
print(str(response))
|
|
|
|
|
|
# Run the agent
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |