Skip to content

Replace hand-rolled provider functions with LiteLLM - #118

Open
RheagalFire wants to merge 2 commits into
LuckyOne7777:mainfrom
RheagalFire:feat/litellm-provider
Open

RheagalFire wants to merge 2 commits into
LuckyOne7777:mainfrom
RheagalFire:feat/litellm-provider

Conversation

@RheagalFire

@RheagalFire RheagalFire commented Jun 29, 2026 •

Copy link
Copy Markdown

Motivation

prompt_models.py contains four separate provider functions (prompt_chatgpt, prompt_claude, prompt_deepseek, prompt_grok) plus three identical if/elif dispatcher chains that route by model name substring. Adding a new provider means writing a new function, updating all three dispatchers, and adding a new SDK dependency.

LiteLLM is an open-source AI gateway that provides a unified completion() interface for 100+ LLM providers using the OpenAI format. Replacing the hand-rolled functions with a single litellm.completion() call:

  • Cuts prompt_models.py from 130 lines to 52
  • Removes three copy-pasted if/elif dispatcher chains
  • Makes adding a new provider zero-code (just add the model name to MODELS in workflow.py)
  • Replaces direct openai + anthropic SDK dependencies with one dependency (litellm)

Changes

File Change
prompt_orchestration/prompt_models.py Replaced 4 provider functions + 3 dispatchers with single prompt_model() using litellm.completion()
requirements.txt Removed openai==2.32.0 and anthropic==0.107.1, added litellm>=1.80.0,<1.87.0 (litellm installs both as transitive deps)

How provider routing works

LiteLLM routes based on model name prefixes (e.g., anthropic/claude-sonnet-4-6, bedrock/anthropic.claude-3-sonnet, vertex_ai/gemini-2.0-flash). A small _to_litellm_model() helper maps the repo's existing model names (deepseek-*, grok-*) to their LiteLLM prefix format so current configs keep working. Any of LiteLLM's 100+ supported providers can be used by passing the model name in LiteLLM format directly.

Env var compatibility

LiteLLM reads the standard env vars automatically:

Provider Env var (same as before)
OpenAI OPENAI_API_KEY
DeepSeek DEEPSEEK_API_KEY
Anthropic ANTHROPIC_API_KEY
xAI / Grok XAI_API_KEY

For backward compatibility, if CLAUDE_API_KEY is set but ANTHROPIC_API_KEY is not, the module bridges them automatically.

Adding a new provider

Just add the model name in LiteLLM format to the MODELS list:

MODELS = [..., "vertex_ai/gemini-2.0-flash", "bedrock/anthropic.claude-3-sonnet"]

No new functions, no new SDK dependencies, no dispatcher changes.

Tested

$ python3 -c "
import litellm
response = litellm.completion(
    model='claude-sonnet-4-6',
    messages=[{'role': 'user', 'content': 'Say hello in exactly 5 words.'}],
    temperature=0.0, drop_params=True,
)
print(response.choices[0].message.content)
print(f'Model: {response.model}')
"
Hello there, how are you?
Model: claude-sonnet-4-6

Module import chain verified:

$ python3 -c "
from Experiments.multi_model_ipo.prompt_orchestration.prompt_models import (
    prompt_model, prompt_deep_research, prompt_daily_report, prompt_starting_report
)
print('All functions imported successfully')
"
All functions imported successfully

Swap four separate OpenAI/Anthropic/DeepSeek/Grok functions and
three identical if/elif dispatcher chains for a single
litellm.completion() call with automatic provider routing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant