Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Byte-compiled / optimized / DLL files
__pycache__/
ai_env/
*.py[cod]
*$py.class

# C extensions
*.so

*.md
*.patch
# Distribution / packaging
.Python
build/
Expand Down
38 changes: 37 additions & 1 deletion operate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from openai import OpenAI
import anthropic
from prompt_toolkit.shortcuts import input_dialog

from openai import AzureOpenAI

class Config:
"""
Expand Down Expand Up @@ -46,6 +46,18 @@ def __init__(self):
self.qwen_api_key = (
None # instance variables are backups in case saving to a `.env` fails
)
self.azure_openai_api_key = (
None # instance variables are backups in case saving to a `.env` fails
)
self.azure_openai_endpoint = (
None # instance variables are backups in case saving to a `.env` fails
)
self.azure_openai_deployment = (
None # instance variables are backups in case saving to a `.env` fails
)
self.azure_openai_api_version = (
None # instance variables are backups in case saving to a `.env` fails
)

def initialize_openai(self):
if self.verbose:
Expand All @@ -69,6 +81,30 @@ def initialize_openai(self):
client.base_url = os.getenv("OPENAI_API_BASE_URL", client.base_url)
return client

def initialize_azure_openai(self):
if self.verbose:
print("[Config][initialize_azure_openai]")

if self.azure_openai_api_key:
if self.verbose:
print("[Config][initialize_openai] using cached openai_api_key")
api_key = self.azure_openai_api_key
else:
if self.verbose:
print(
"[Config][initialize_azure_openai] no cached azure_openai_api_key, try to get from env."
)
api_key = os.getenv("AZURE_OPENAI_API_KEY")

azure_client = AzureOpenAI(
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
api_version=os.getenv("AZURE_OPENAI_API_VERSION"),
)
azure_client.api_key = api_key
azure_client.base_url = os.getenv("OPENAI_API_BASE_URL", azure_client.base_url)
return azure_client

def initialize_qwen(self):
if self.verbose:
print("[Config][initialize_qwen]")
Expand Down
4 changes: 3 additions & 1 deletion operate/models/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ async def call_gpt_4_1_with_ocr(messages, objective, model):

try:
time.sleep(1)
client = config.initialize_openai()
# client = config.initialize_openai()
client = config.initialize_azure_openai()


confirm_system_prompt(messages, objective, model)
screenshots_dir = "screenshots"
Expand Down