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

Adding Litellm client and some models/providers. #563

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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ when you first time run Devika, it will create a `config.toml` file for you in t
- `CLAUDE`: Your Anthropic API key for accessing Claude models.
- `MISTRAL`: Your Mistral API key for accessing Mistral models.
- `GROQ`: Your Groq API key for accessing Groq models.
- `OPENROUTER`: Your OpenRouter API key for accessing OpenRouter models.
- `DEEPINFRA`: Your DeepInfra API key for accessing DeepInfra models.
- `NETLIFY`: Your Netlify API key for deploying and managing web projects.

- API_ENDPOINTS
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ duckduckgo-search
orjson
gevent
gevent-websocket
litellm

2 changes: 2 additions & 0 deletions sample.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ OPENAI = "<YOUR_OPENAI_API_KEY>"
GEMINI = "<YOUR_GEMINI_API_KEY>"
MISTRAL = "<YOUR_MISTRAL_API_KEY>"
GROQ = "<YOUR_GROQ_API_KEY>"
OPENROUTER = "<YOUR_OPENROUTER_API_KEY>"
DEEPINFRA = "<YOUR_DEEPINFRA_API_KEY>"
NETLIFY = "<YOUR_NETLIFY_API_KEY>"

[API_ENDPOINTS]
Expand Down
28 changes: 28 additions & 0 deletions src/llm/litellm_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
from litellm import completion
from src.config import Config

class LiteLLM:
def __init__(self):
self.config = Config()

def set_api_key(self, model_id: str):
if "openrouter" in model_id:
os.environ["OPENROUTER_API_KEY"] = self.config.get_openrouter_api_key()
elif "deepinfra" in model_id:
os.environ["DEEPINFRA_API_KEY"] = self.config.get_deepinfra_api_key()
elif "openai" in model_id:
os.environ["OPENAI_API_KEY"] = self.config.get_openai_api_key()
elif "anthropic" in model_id:
os.environ["ANTHROPIC_API_KEY"] = self.config.get_anthropic_api_key()
elif "mistral" in model_id:
os.environ["MISTRAL_API_KEY"] = self.config.get_mistral_api_key()
elif "cohere" in model_id:
os.environ["COHERE_API_KEY"] = self.config.get_cohere_api_key()


def inference(self, model_id: str, prompt: str) -> str:
self.set_api_key(model_id)
messages = [{"role": "user", "content": prompt.strip()}]
response = completion(model=model_id, messages=messages)
return response['choices'][0]['message']['content']
20 changes: 19 additions & 1 deletion src/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .gemini_client import Gemini
from .mistral_client import MistralAi
from .groq_client import Groq
from .litellm_client import LiteLLM

from src.state import AgentState

Expand Down Expand Up @@ -42,6 +43,8 @@ def __init__(self, model_id: str = None):
],
"GOOGLE": [
("Gemini 1.0 Pro", "gemini-pro"),
("Gemini 1.5 Flash", "gemini-1.5-flash"),
("Gemini 1.5 Pro", "gemini-1.5-pro-latest"),
],
"MISTRAL": [
("Mistral 7b", "open-mistral-7b"),
Expand All @@ -57,6 +60,20 @@ def __init__(self, model_id: str = None):
("Mixtral", "mixtral-8x7b-32768"),
("GEMMA 7B", "gemma-7b-it"),
],
"LITELLM": [
("OpenRouter: Llama 3 8B Instruct", "openrouter/meta-llama/llama-3-8b-instruct:extended"),
("OpenRouter: Claude 3 Haiku", "openrouter/anthropic/claude-3-haiku"),
("OpenRouter: Claude 3 Sonnet", "openrouter/anthropic/claude-3-sonnet"),
("OpenRouter: Claude 3 Sonnet 20240229", "openrouter/anthropic/claude-3-sonnet-20240229"),
("DeepInfra: Mixtral 8x7B Instruct", "deepinfra/mistralai/Mixtral-8x7B-Instruct-v0.1"),
("DeepInfra: Dolphin 2.6 Mixtral", "deepinfra/cognitivecomputations/dolphin-2.6-mixtral-8x7b"),
("OpenRouter: Gemini Pro 1.5", "openrouter/google/gemini-pro-1.5"),
("OpenRouter: Gemini Flash 1.5", "openrouter/google/gemini-flash-1.5"),
("OpenRouter: Gemma 7B", "openrouter/google/gemma-7b-it"),
("OpenRouter: DeepSeek Coder", "openrouter/deepseek/deepseek-coder"),
("OpenRouter: Palm 2 CodeChat Bison 32k", "openrouter/google/palm-2-codechat-bison-32k"),
("OpenRouter: CodeLLama 34B Instruct", "openrouter/meta-llama/codellama-34b-instruct"),
],
"OLLAMA": []
}
if ollama.client:
Expand Down Expand Up @@ -96,7 +113,8 @@ def inference(self, prompt: str, project_name: str) -> str:
"OPENAI": OpenAi(),
"GOOGLE": Gemini(),
"MISTRAL": MistralAi(),
"GROQ": Groq()
"GROQ": Groq(),
"LITELLM": LiteLLM(),
}

try:
Expand Down