Skip to content
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

Feat: Add Option to Specify Other LLM Providers in .env #43

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
24 changes: 23 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
# Current Azure OpenAI Config
AZURE_OPENAI_API_KEY=YOURKEY
AZURE_OPENAI_ENDPOINT=https://YOURENDPOINT.openai.azure.com
AZURE_OPENAI_API_VERSION=2024-02-01

# Default Model Configuration
MODEL=gpt-4o-mini
EMBEDDING=text-embedding-3-small
EMBEDDING_MODEL_MAX_TOKENS=8192

# GitHub Integration
GITHUB_TOKEN=YOURTOKEN

# Supabase Config
SUPABASE_URL=https://YOURLINK.supabase.co
SUPABASE_KEY=your_supabase_key
SUPABASE_DB_URL=your_supabase_db_url # use transaction pooler, example: postgresql://postgres.pnewjmyiuazlkssdmhsc:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require
SUPABASE_DB_URL=your_supabase_db_url # use transaction pooler, example: postgresql://postgres.pnewjmyiuazlkssdmhsc:[YOUR-PASSWORD]@aws-0-us-east-1.pooler.supabase.com:6543/postgres?sslmode=require

# New Environment Variables for Multi-Provider Support
LLM_PROVIDER=AzureOpenAI

# OpenAI API
OPENAI_API_KEY=your_openai_api_key

# Anthropic API
ANTHROPIC_API_KEY=your_anthropic_api_key

# Google Generative AI
GOOGLE_API_KEY=your_google_api_key

# Groq API
GROQ_API_KEY=your_groq_api_key
51 changes: 47 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,62 @@

def check_env_vars():
required_vars = [
"AZURE_OPENAI_ENDPOINT",
"AZURE_OPENAI_API_KEY",
"AZURE_OPENAI_API_VERSION",
"LLM_PROVIDER",
"MODEL",
"GITHUB_TOKEN",
"SUPABASE_URL",
"SUPABASE_KEY",
]

# Check if required environment variables are set
provider = os.getenv("LLM_PROVIDER", "")
if not provider:
print("Error: LLM_PROVIDER is not specified. Please set LLM_PROVIDER in your environment variables.")
return False

# Add provider-specific checks
if provider == "AzureOpenAI":
required_vars.extend(["AZURE_OPENAI_ENDPOINT", "AZURE_OPENAI_API_KEY", "AZURE_OPENAI_API_VERSION"])
elif provider == "OpenAI":
required_vars.append("OPENAI_API_KEY")
elif provider == "Anthropic":
required_vars.append("ANTHROPIC_API_KEY")
elif provider == "Google":
required_vars.append("GOOGLE_API_KEY")
elif provider == "Groq":
required_vars.append("GROQ_API_KEY")
else:
print(f"Error: Unsupported LLM_PROVIDER '{provider}'. Supported providers are: AzureOpenAI, OpenAI, Anthropic, Google, Groq.")
return False

missing_vars = [var for var in required_vars if not os.environ.get(var)]
if missing_vars:
print(f"Missing environment variables: {', '.join(missing_vars)}. Please configure the env vars file properly.")
return False
return True

def initialize_llm_client():
provider = os.getenv("LLM_PROVIDER", "AzureOpenAI") # Default to AzureOpenAI

if provider == "AzureOpenAI":
from helpers.openai_helpers import setup_azure_openai
return setup_azure_openai()
elif provider == "OpenAI":
from openai import OpenAI
return OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
elif provider == "Anthropic":
from anthropic import Anthropic
return Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
elif provider == "Google":
from google.generativeai import GoogleAI
return GoogleAI(api_key=os.getenv("GOOGLE_API_KEY"))
elif provider == "Groq":
from groq.client import GroqClient
return GroqClient(api_key=os.getenv("GROQ_API_KEY"))
else:
raise ValueError(f"Unsupported LLM provider: {provider}")


hdrs = [
Script(src="https://www.googletagmanager.com/gtag/js?id=G-Q22LCTCW8Y", aync=True),
Script("""
Expand Down Expand Up @@ -202,7 +244,8 @@ async def get(fname:str, ext:str):

# Initialize clients
if check_env_vars():
openai_client = setup_azure_openai()
logging.info("Initializing LLM client...")
openai_client = initialize_llm_client()
instructor_client = setup_instructor(openai_client)

if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ websockets==12.0
wheel==0.44.0
yarl==1.9.4
psycopg2-binary==2.9.10
openai==1.40.2
anthropic==0.42.0
google-generativeai==0.4.0
groq