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

Add LiteLLM - support for Vertex AI, Gemini, Anthropic, Bedrock (100+LLMs) #552

Open
wants to merge 2 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
10 changes: 5 additions & 5 deletions lumigator/python/mzai/backend/backend/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from backend.db import session_manager
from backend.repositories.datasets import DatasetRepository
from backend.repositories.jobs import JobRepository, JobResultRepository
from backend.services.completions import MistralCompletionService, OpenAICompletionService
from backend.services.completions import LiteLLMCompletionService, MistralCompletionService
from backend.services.datasets import DatasetService
from backend.services.jobs import JobService
from backend.settings import settings
Expand Down Expand Up @@ -68,10 +68,10 @@ def get_mistral_completion_service() -> MistralCompletionService:
]


def get_openai_completion_service() -> OpenAICompletionService:
return OpenAICompletionService()
def get_openai_completion_service() -> LiteLLMCompletionService:
return LiteLLMCompletionService()


OpenAICompletionServiceDep = Annotated[
OpenAICompletionService, Depends(get_mistral_completion_service)
LiteLLMCompletionServiceDep = Annotated[
LiteLLMCompletionService, Depends(get_mistral_completion_service)
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import APIRouter
from lumigator_schemas.completions import CompletionRequest

from backend.api.deps import MistralCompletionServiceDep, OpenAICompletionServiceDep
from backend.api.deps import LiteLLMCompletionServiceDep, MistralCompletionServiceDep

router = APIRouter()

Expand All @@ -20,5 +20,5 @@ def get_mistral_completion(request: CompletionRequest, service: MistralCompletio


@router.post(f"/{VENDOR_OPENAI}")
def get_openai_completion(request: CompletionRequest, service: OpenAICompletionServiceDep):
def get_openai_completion(request: CompletionRequest, service: LiteLLMCompletionServiceDep):
return service.get_completions_response(request)
11 changes: 5 additions & 6 deletions lumigator/python/mzai/backend/backend/services/completions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from abc import ABC, abstractmethod

import litellm
import mistralai.client
from lumigator_schemas.completions import CompletionRequest, CompletionResponse
from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage
from openai import OpenAI

from backend.settings import settings

Expand Down Expand Up @@ -44,21 +44,20 @@ def get_completions_response(self, request: CompletionRequest) -> CompletionResp
return CompletionResponse(text=response)


class OpenAICompletionService(CompletionService):
class LiteLLMCompletionService(CompletionService):
def __init__(self):
self.client = OpenAI(api_key=settings.OAI_API_KEY)
self.model = "gpt-4o-mini"
self.max_tokens = 256
self.temperature = 1
self.top_p = 1

def get_models(self) -> mistralai.client.ModelList:
response = self.client.list_models()
def get_models(self) -> list[str]:
response = litellm.models_by_provider.get("openai")

return response

def get_completions_response(self, request: CompletionRequest) -> CompletionResponse:
response = self.client.chat.completions.create(
response = litellm.completion(
model=self.model,
messages=[
{"role": "system", "content": self.prompt},
Expand Down
Loading