llama_index的starter.py能跑起来了
This commit is contained in:
30
test/llamaindex/starter.py
Normal file
30
test/llamaindex/starter.py
Normal 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())
|
||||
Reference in New Issue
Block a user