llama_index的starter.py能跑起来了

This commit is contained in:
2025-08-27 22:20:51 +08:00
parent b35e44f27d
commit 75ae2c5fd5

View File

@@ -0,0 +1,30 @@
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())