From 75ae2c5fd5a43b0608e67634dbbae58a86115474 Mon Sep 17 00:00:00 2001 From: kexsh <769014005@qq.com> Date: Wed, 27 Aug 2025 22:20:51 +0800 Subject: [PATCH] =?UTF-8?q?llama=5Findex=E7=9A=84starter.py=E8=83=BD?= =?UTF-8?q?=E8=B7=91=E8=B5=B7=E6=9D=A5=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/llamaindex/starter.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/llamaindex/starter.py diff --git a/test/llamaindex/starter.py b/test/llamaindex/starter.py new file mode 100644 index 0000000..ae01079 --- /dev/null +++ b/test/llamaindex/starter.py @@ -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()) \ No newline at end of file