mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
Merge 2069484643 into e9b1c11098
This commit is contained in:
commit
25818f3815
7 changed files with 53 additions and 6 deletions
|
|
@ -21,6 +21,11 @@ def get_voyage_api_key(api_key: str | None = None) -> str | None:
|
|||
)
|
||||
|
||||
|
||||
def get_voyage_api_base(api_base: str | None = None, api_key: str | None = None) -> str:
|
||||
"""Resolve the Voyage embeddings host: explicit base, ``VOYAGE_API_BASE``, then key issuer."""
|
||||
return api_base or get_secret_str("VOYAGE_API_BASE") or get_default_base_url(api_key)
|
||||
|
||||
|
||||
def get_default_base_url(api_key: str | None = None) -> str:
|
||||
"""
|
||||
Pick the host that issued the key: MongoDB-issued keys (``al-`` prefix) are only
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
|
|||
from litellm.litellm_core_utils.url_utils import ensure_api_route
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
from litellm.llms.base_llm.embedding.transformation import BaseEmbeddingConfig
|
||||
from litellm.llms.voyage.common_utils import get_default_base_url, get_voyage_api_key
|
||||
from litellm.llms.voyage.common_utils import get_voyage_api_base, get_voyage_api_key
|
||||
from litellm.types.llms.openai import AllEmbeddingInputValues, AllMessageValues
|
||||
from litellm.types.utils import EmbeddingResponse, Usage
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ class VoyageEmbeddingConfig(BaseEmbeddingConfig):
|
|||
litellm_params: dict,
|
||||
stream: bool | None = None,
|
||||
) -> str:
|
||||
return ensure_api_route(api_base or get_default_base_url(api_key), "embeddings")
|
||||
return ensure_api_route(get_voyage_api_base(api_base, api_key), "embeddings")
|
||||
|
||||
def get_supported_openai_params(self, model: str) -> list:
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
|
|||
from litellm.litellm_core_utils.url_utils import ensure_api_route
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
from litellm.llms.base_llm.embedding.transformation import BaseEmbeddingConfig
|
||||
from litellm.llms.voyage.common_utils import get_default_base_url, get_voyage_api_key
|
||||
from litellm.llms.voyage.common_utils import get_voyage_api_base, get_voyage_api_key
|
||||
from litellm.types.llms.openai import AllEmbeddingInputValues, AllMessageValues
|
||||
from litellm.types.utils import EmbeddingResponse, Usage
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ class VoyageContextualEmbeddingConfig(BaseEmbeddingConfig):
|
|||
litellm_params: dict,
|
||||
stream: bool | None = None,
|
||||
) -> str:
|
||||
return ensure_api_route(api_base or get_default_base_url(api_key), "contextualizedembeddings")
|
||||
return ensure_api_route(get_voyage_api_base(api_base, api_key), "contextualizedembeddings")
|
||||
|
||||
def get_supported_openai_params(self, model: str) -> list: # mutable-ok: base class signature
|
||||
return ["encoding_format", "dimensions"]
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
|
|||
from litellm.litellm_core_utils.url_utils import ensure_api_route
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
from litellm.llms.base_llm.embedding.transformation import BaseEmbeddingConfig
|
||||
from litellm.llms.voyage.common_utils import get_default_base_url, get_voyage_api_key
|
||||
from litellm.llms.voyage.common_utils import get_voyage_api_base, get_voyage_api_key
|
||||
from litellm.types.llms.openai import AllEmbeddingInputValues, AllMessageValues
|
||||
from litellm.types.utils import EmbeddingResponse, Usage
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ class VoyageMultimodalEmbeddingConfig(BaseEmbeddingConfig):
|
|||
litellm_params: dict,
|
||||
stream: bool | None = None,
|
||||
) -> str:
|
||||
return ensure_api_route(api_base or get_default_base_url(api_key), "multimodalembeddings")
|
||||
return ensure_api_route(get_voyage_api_base(api_base, api_key), "multimodalembeddings")
|
||||
|
||||
def get_supported_openai_params(self, model: str) -> list:
|
||||
return ["dimensions"]
|
||||
|
|
|
|||
|
|
@ -579,3 +579,17 @@ def test_get_complete_url_ignores_a_trailing_slash_on_api_base(api_base: str):
|
|||
)
|
||||
== "https://gateway.example.com/voyage/v1/contextualizedembeddings"
|
||||
)
|
||||
|
||||
|
||||
def test_get_complete_url_honors_voyage_api_base(monkeypatch):
|
||||
monkeypatch.setenv("VOYAGE_API_BASE", "https://gateway.example.com/v1/")
|
||||
config = VoyageContextualEmbeddingConfig()
|
||||
|
||||
assert (
|
||||
config.get_complete_url(None, "vk-test", "voyage-3.5", {}, {})
|
||||
== "https://gateway.example.com/v1/contextualizedembeddings"
|
||||
)
|
||||
assert (
|
||||
config.get_complete_url("https://explicit.example.com/v1", "vk-test", "voyage-3.5", {}, {})
|
||||
== "https://explicit.example.com/v1/contextualizedembeddings"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -106,3 +106,17 @@ def test_get_complete_url_ignores_a_trailing_slash_on_api_base(api_base: str):
|
|||
)
|
||||
== "https://gateway.example.com/voyage/v1/multimodalembeddings"
|
||||
)
|
||||
|
||||
|
||||
def test_get_complete_url_honors_voyage_api_base(monkeypatch):
|
||||
monkeypatch.setenv("VOYAGE_API_BASE", "https://gateway.example.com/v1/")
|
||||
config = VoyageMultimodalEmbeddingConfig()
|
||||
|
||||
assert (
|
||||
config.get_complete_url(None, "vk-test", "voyage-3.5", {}, {})
|
||||
== "https://gateway.example.com/v1/multimodalembeddings"
|
||||
)
|
||||
assert (
|
||||
config.get_complete_url("https://explicit.example.com/v1", "vk-test", "voyage-3.5", {}, {})
|
||||
== "https://explicit.example.com/v1/multimodalembeddings"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -106,3 +106,17 @@ def test_get_complete_url_ignores_a_trailing_slash_on_api_base(api_base: str):
|
|||
)
|
||||
== "https://gateway.example.com/voyage/v1/embeddings"
|
||||
)
|
||||
|
||||
|
||||
def test_get_complete_url_honors_voyage_api_base(monkeypatch):
|
||||
monkeypatch.setenv("VOYAGE_API_BASE", "https://gateway.example.com/v1/")
|
||||
config = VoyageEmbeddingConfig()
|
||||
|
||||
assert (
|
||||
config.get_complete_url(None, "vk-test", "voyage-3.5", {}, {})
|
||||
== "https://gateway.example.com/v1/embeddings"
|
||||
)
|
||||
assert (
|
||||
config.get_complete_url("https://explicit.example.com/v1", "vk-test", "voyage-3.5", {}, {})
|
||||
== "https://explicit.example.com/v1/embeddings"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue