-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall.py
More file actions
38 lines (30 loc) · 960 Bytes
/
call.py
File metadata and controls
38 lines (30 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
import logging
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
from pydantic_ai.toolsets.fastmcp import FastMCPToolset
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)s: %(message)s',
)
logging.getLogger('httpcore').setLevel(logging.INFO)
async def main():
toolset = FastMCPToolset('http://localhost:8000/mcp')
model = OpenAIChatModel(
'qwen',
provider=OpenAIProvider(
base_url='http://localhost:8080/v1',
api_key='whatever'
)
)
agent = Agent(model, toolsets=[toolset])
print("\n|-->\n")
result = await agent.run('Add two numbers: 2109 and 9137.')
print("\n<--|\n")
print(result.output)
print("\n<-->\n")
for message in result.all_messages():
print(message)
if __name__ == '__main__':
asyncio.run(main())