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: list out embedding models for Google AI provider #1839

Merged
merged 3 commits into from
Oct 8, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
COMPOSIO_API_KEY: ${{ secrets.COMPOSIO_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}

on:
push:
Expand Down
31 changes: 27 additions & 4 deletions letta/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,23 @@ def get_model_context_window_size(self, model_name: str):
class GoogleAIProvider(Provider):
# gemini
api_key: str = Field(..., description="API key for the Google AI API.")
service_endpoint: str = "generativelanguage"
service_endpoint: str = "generativelanguage" # TODO: remove once old functions are refactored to just use base_url
base_url: str = "https://generativelanguage.googleapis.com"

def list_llm_models(self):
from letta.llm_api.google_ai import google_ai_get_model_list

# TODO: use base_url instead
model_options = google_ai_get_model_list(service_endpoint=self.service_endpoint, api_key=self.api_key)
# filter by 'generateContent' models
model_options = [mo for mo in model_options if "generateContent" in mo["supportedGenerationMethods"]]
model_options = [str(m["name"]) for m in model_options]

# filter by model names
model_options = [mo[len("models/") :] if mo.startswith("models/") else mo for mo in model_options]

# TODO remove manual filtering for gemini-pro
model_options = [mo for mo in model_options if str(mo).startswith("gemini") and "-pro" in str(mo)]
# TODO: add context windows
# model_options = ["gemini-pro"]

configs = []
for model in model_options:
Expand All @@ -210,7 +213,27 @@ def list_llm_models(self):
return configs

def list_embedding_models(self):
return []
from letta.llm_api.google_ai import google_ai_get_model_list

# TODO: use base_url instead
model_options = google_ai_get_model_list(service_endpoint=self.service_endpoint, api_key=self.api_key)
# filter by 'generateContent' models
model_options = [mo for mo in model_options if "embedContent" in mo["supportedGenerationMethods"]]
model_options = [str(m["name"]) for m in model_options]
model_options = [mo[len("models/") :] if mo.startswith("models/") else mo for mo in model_options]

configs = []
for model in model_options:
configs.append(
EmbeddingConfig(
embedding_model=model,
embedding_endpoint_type="google_ai",
embedding_endpoint=self.base_url,
embedding_dim=768,
embedding_chunk_size=300, # NOTE: max is 2048
)
)
return configs

def get_model_context_window(self, model_name: str):
from letta.llm_api.google_ai import google_ai_get_model_context_window
Expand Down
16 changes: 10 additions & 6 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from letta.providers import AnthropicProvider, OpenAIProvider
from letta.providers import AnthropicProvider, GoogleAIProvider, OpenAIProvider


def test_openai():
Expand Down Expand Up @@ -30,13 +30,17 @@ def test_anthropic():
# print(models)
#
#
# def test_googleai():
# provider = GoogleAIProvider(api_key=os.getenv("GEMINI_API_KEY"))
# models = provider.list_llm_models()
# print(models)
def test_googleai():
provider = GoogleAIProvider(api_key=os.getenv("GEMINI_API_KEY"))
models = provider.list_llm_models()
print(models)

provider.list_embedding_models()


#
#
# test_googleai()
test_googleai()
# test_ollama()
# test_groq()
# test_openai()
Expand Down
Loading