-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_agent.py
More file actions
63 lines (51 loc) · 2.36 KB
/
run_agent.py
File metadata and controls
63 lines (51 loc) · 2.36 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
61
62
63
#!/usr/bin/env python3
"""
Run script for the local AI agent component that uses Azure OpenAI.
"""
import os
import sys
import logging
import asyncio
# Set up logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger("run_agent")
async def main():
# Check if .env file exists
if not os.path.exists('.env'):
if os.path.exists('.env.example'):
logger.warning("No .env file found. Copying from .env.example...")
# Copy .env.example to .env
with open('.env.example', 'r') as example_file:
example_content = example_file.read()
with open('.env', 'w') as env_file:
env_file.write(example_content)
logger.info("Created .env file from example. Please edit it with your configuration.")
logger.info("Please set your AZURE_OPENAI_API_KEY and other settings in the .env file.")
# Prompt user to update the .env file
user_input = input("Would you like to proceed with default settings? (y/n): ")
if user_input.lower() != 'y':
logger.info("Please update the .env file and run the script again.")
sys.exit(0)
else:
logger.error("No .env or .env.example file found. Please create a .env file.")
sys.exit(1)
# Check for Azure OpenAI configuration
from config import AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_DEPLOYMENT_NAME
if not AZURE_OPENAI_API_KEY or not AZURE_OPENAI_ENDPOINT or not AZURE_OPENAI_DEPLOYMENT_NAME:
logger.error("Azure OpenAI configuration is incomplete. Please check your .env file.")
logger.error("Make sure AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, and AZURE_OPENAI_DEPLOYMENT_NAME are set.")
sys.exit(1)
# Run the local agent
logger.info("Starting the local agent with Azure OpenAI...")
try:
from local_agent import main as agent_main
await agent_main()
except ImportError as e:
logger.error(f"Failed to import the local_agent module: {e}")
sys.exit(1)
except Exception as e:
logger.error(f"Error running the local agent: {e}")
sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())