-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (50 loc) · 1.58 KB
/
Copy pathapp.py
File metadata and controls
60 lines (50 loc) · 1.58 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import asyncio
from dotenv import load_dotenv # Add this import
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStdio
from pydantic_ai.models.openai import OpenAIModel
from pydantic_ai.models.anthropic import AnthropicModel
from pydantic_ai.models.google import GoogleModel
load_dotenv() # Call this at the beginning of your script
# Use model based on environment variable
model_type = os.getenv("AI_MODEL", "openai").lower()
if model_type == "claude":
model = AnthropicModel(model_name="claude-3-opus-20240229")
elif model_type == "gemini":
model = GoogleModel(model_name="gemini-1.5-flash")
elif model_type == "deepseek":
model = OpenAIModel(
model_name="deepseek-chat",
base_url="https://api.deepseek.com/v1"
)
else:
model = OpenAIModel(model_name="gpt-4o-mini")
# Define the MCP Servers
brave_server = MCPServerStdio(
'python',
['brave_search.py']
)
python_tools_server = MCPServerStdio(
'python',
['python_tools.py']
)
# Define the Agent with both MCP servers
agent = Agent(
model,
mcp_servers=[brave_server, python_tools_server],
retries=3
)
# Main async function
async def main():
async with agent.run_mcp_servers():
print("Web Recon Chatbot Ready! Type 'exit' to quit.\n")
while True:
user_input = input("You: ")
if user_input.lower() == 'exit':
break
result = await agent.run(user_input)
print(f"\nBot: {result.output}\n")
# Run the async function
if __name__ == "__main__":
asyncio.run(main())