Skip to content

feat: Add user defined openai model provider (#124) #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
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 .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL_DEPLOYMENT=gpt-4o
ANTHROPIC_API_KEY=your_anthropic_api_key_here
DEEPSEEK_API_KEY=your_deepseek_api_key_here
GOOGLE_API_KEY=your_google_api_key_here
AZURE_OPENAI_API_KEY=your_azure_openai_api_key_here
AZURE_OPENAI_MODEL_DEPLOYMENT=gpt-4o-ms
SILICONFLOW_API_KEY=your_siliconflow_api_key_here
SILICONFLOW_API_KEY=your_siliconflow_api_key_here
10 changes: 6 additions & 4 deletions tools/llm_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env /workspace/tmp_windsurf/venv/bin/python3
#!/usr/bin/env python3

import google.generativeai as genai
from openai import OpenAI, AzureOpenAI
Expand Down Expand Up @@ -68,10 +68,12 @@ def encode_image_file(image_path: str) -> tuple[str, str]:
def create_llm_client(provider="openai"):
if provider == "openai":
api_key = os.getenv('OPENAI_API_KEY')
base_url = os.getenv('OPENAI_BASE_URL', "https://api.openai.com/v1")
if not api_key:
raise ValueError("OPENAI_API_KEY not found in environment variables")
return OpenAI(
api_key=api_key
api_key=api_key,
base_url=base_url
)
elif provider == "azure":
api_key = os.getenv('AZURE_OPENAI_API_KEY')
Expand Down Expand Up @@ -140,7 +142,7 @@ def query_llm(prompt: str, client=None, model=None, provider="openai", image_pat
# Set default model
if model is None:
if provider == "openai":
model = "gpt-4o"
model = os.getenv('OPENAI_MODEL_DEPLOYMENT', 'gpt-4o')
elif provider == "azure":
model = os.getenv('AZURE_OPENAI_MODEL_DEPLOYMENT', 'gpt-4o-ms') # Get from env with fallback
elif provider == "deepseek":
Expand Down Expand Up @@ -269,4 +271,4 @@ def main():
print("Failed to get response from LLM")

if __name__ == "__main__":
main()
main()
4 changes: 2 additions & 2 deletions tools/web_scraper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env /workspace/tmp_windsurf/venv/bin/python3
#!/usr/bin/env python3

import asyncio
import argparse
Expand Down Expand Up @@ -204,4 +204,4 @@ def main():
sys.exit(1)

if __name__ == '__main__':
main()
main()