mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-16 23:41:43 +00:00
Merge 6fc0e640cc into c2c2a623c0
This commit is contained in:
commit
5a56aa3056
11 changed files with 153 additions and 0 deletions
8
docs/my-website/docs/providers/token_kiosk.md
Normal file
8
docs/my-website/docs/providers/token_kiosk.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Token Kiosk
|
||||
|
||||
Token Kiosk is a multi-provider agent LLM routing infrastructure exposing an OpenAI-compatible endpoint.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
- `TOKEN_KIOSK_API_KEY`: API key for authenticating with Token Kiosk.
|
||||
- `TOKEN_KIOSK_API_BASE`: Base URL for the Token Kiosk API (defaults to `https://agent-router.gaib.ai/v1`).
|
||||
|
|
@ -1891,6 +1891,9 @@ if TYPE_CHECKING:
|
|||
from .llms.deepseek.chat.transformation import (
|
||||
DeepSeekChatConfig as _DeepSeekChatConfig,
|
||||
)
|
||||
from .llms.token_kiosk.chat.transformation import (
|
||||
TokenKioskConfig as _TokenKioskConfig,
|
||||
)
|
||||
from .llms.tencent.chat.transformation import (
|
||||
TencentChatConfig as _TencentChatConfig,
|
||||
)
|
||||
|
|
@ -1936,6 +1939,7 @@ if TYPE_CHECKING:
|
|||
# Type stubs for lazy-loaded config classes (to help mypy understand types)
|
||||
VLLMConfig: Type[_VLLMConfig]
|
||||
DeepSeekChatConfig: Type[_DeepSeekChatConfig]
|
||||
TokenKioskConfig: Type[_TokenKioskConfig]
|
||||
TencentChatConfig: Type[_TencentChatConfig]
|
||||
GenAIHubOrchestrationConfig: Type[_GenAIHubOrchestrationConfig]
|
||||
GenAIHubEmbeddingConfig: Type[_GenAIHubEmbeddingConfig]
|
||||
|
|
@ -1977,6 +1981,7 @@ if TYPE_CHECKING:
|
|||
JinaAIEmbeddingConfig as JinaAIEmbeddingConfig,
|
||||
)
|
||||
from .llms.xai.chat.transformation import XAIChatConfig as XAIChatConfig
|
||||
from .llms.token_kiosk.chat.transformation import TokenKioskConfig as TokenKioskConfig
|
||||
from .llms.zai.chat.transformation import ZAIChatConfig as ZAIChatConfig
|
||||
from .llms.aiml.chat.transformation import AIMLChatConfig as AIMLChatConfig
|
||||
from .llms.volcengine.chat.transformation import (
|
||||
|
|
|
|||
|
|
@ -289,6 +289,7 @@ LLM_CONFIG_NAMES: Final = (
|
|||
"LiteLLMProxyChatConfig",
|
||||
"VLLMConfig",
|
||||
"DeepSeekChatConfig",
|
||||
"TokenKioskConfig",
|
||||
"TencentChatConfig",
|
||||
"LMStudioChatConfig",
|
||||
"LmStudioEmbeddingConfig",
|
||||
|
|
@ -1116,6 +1117,10 @@ _LLM_CONFIGS_IMPORT_MAP: Final = {
|
|||
),
|
||||
"VLLMConfig": (".llms.vllm.completion.transformation", "VLLMConfig"),
|
||||
"DeepSeekChatConfig": (".llms.deepseek.chat.transformation", "DeepSeekChatConfig"),
|
||||
"TokenKioskConfig": (
|
||||
".llms.token_kiosk.chat.transformation",
|
||||
"TokenKioskConfig",
|
||||
),
|
||||
"TencentChatConfig": (".llms.tencent.chat.transformation", "TencentChatConfig"),
|
||||
"LMStudioChatConfig": (".llms.lm_studio.chat.transformation", "LMStudioChatConfig"),
|
||||
"LmStudioEmbeddingConfig": (
|
||||
|
|
|
|||
|
|
@ -902,6 +902,7 @@ openai_compatible_endpoints: Final[list] = [
|
|||
|
||||
|
||||
openai_compatible_providers: Final[list] = [
|
||||
"token_kiosk",
|
||||
"anyscale",
|
||||
"groq",
|
||||
"nvidia_nim",
|
||||
|
|
|
|||
|
|
@ -852,6 +852,11 @@ def _get_openai_compatible_provider_info(
|
|||
api_base,
|
||||
dynamic_api_key,
|
||||
) = litellm.AIMLChatConfig()._get_openai_compatible_provider_info(api_base, api_key)
|
||||
elif custom_llm_provider == "token_kiosk":
|
||||
(
|
||||
api_base,
|
||||
dynamic_api_key,
|
||||
) = litellm.TokenKioskConfig().get_openai_compatible_provider_info(api_base, api_key)
|
||||
elif custom_llm_provider == "wandb":
|
||||
api_base = api_base or get_secret("WANDB_API_BASE") or "https://api.inference.wandb.ai/v1"
|
||||
dynamic_api_key = api_key or get_secret_str("WANDB_API_KEY")
|
||||
|
|
|
|||
5
litellm/llms/token_kiosk/__init__.py
Normal file
5
litellm/llms/token_kiosk/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from typing import Final
|
||||
|
||||
from .chat.transformation import TokenKioskConfig
|
||||
|
||||
__all__: Final[tuple[str, ...]] = ("TokenKioskConfig",)
|
||||
38
litellm/llms/token_kiosk/chat/transformation.py
Normal file
38
litellm/llms/token_kiosk/chat/transformation.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""
|
||||
Translates from OpenAI's /v1/chat/completions to Token Kiosk's /v1/chat/completions
|
||||
"""
|
||||
|
||||
from typing import Final
|
||||
|
||||
from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
|
||||
|
||||
class TokenKioskConfig(OpenAIGPTConfig):
|
||||
def get_openai_compatible_provider_info(
|
||||
self, api_base: str | None, api_key: str | None
|
||||
) -> tuple[str | None, str | None]:
|
||||
final_api_base: Final = api_base or get_secret_str("TOKEN_KIOSK_API_BASE") or "https://agent-router.gaib.ai/v1"
|
||||
dynamic_api_key: Final = api_key or get_secret_str("TOKEN_KIOSK_API_KEY")
|
||||
return final_api_base, dynamic_api_key
|
||||
|
||||
def _get_openai_compatible_provider_info(
|
||||
self, api_base: str | None, api_key: str | None
|
||||
) -> tuple[str | None, str | None]:
|
||||
return self.get_openai_compatible_provider_info(api_base, api_key)
|
||||
|
||||
def get_complete_url(
|
||||
self,
|
||||
api_base: str | None,
|
||||
api_key: str | None,
|
||||
model: str,
|
||||
optional_params: dict, # mutable-ok: OpenAIGPTConfig.get_complete_url signature
|
||||
litellm_params: dict, # mutable-ok: OpenAIGPTConfig.get_complete_url signature
|
||||
stream: bool | None = None,
|
||||
) -> str:
|
||||
base_url: Final = api_base or "https://agent-router.gaib.ai/v1"
|
||||
if base_url.endswith("/chat/completions"):
|
||||
return base_url
|
||||
if base_url.endswith("/"):
|
||||
return f"{base_url}chat/completions"
|
||||
return f"{base_url}/chat/completions"
|
||||
|
|
@ -3898,6 +3898,7 @@ GenericBudgetConfigType = dict[str, BudgetConfig]
|
|||
|
||||
class LlmProviders(str, Enum):
|
||||
OPENAI = "openai"
|
||||
TOKEN_KIOSK = "token_kiosk"
|
||||
CHATGPT = "chatgpt"
|
||||
OPENAI_LIKE = "openai_like" # embedding only
|
||||
JINA_AI = "jina_ai"
|
||||
|
|
|
|||
|
|
@ -2402,6 +2402,24 @@
|
|||
"text_completion": false
|
||||
}
|
||||
},
|
||||
"token_kiosk": {
|
||||
"display_name": "Token Kiosk (`token_kiosk`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/token_kiosk",
|
||||
"endpoints": {
|
||||
"chat_completions": true,
|
||||
"messages": true,
|
||||
"responses": true,
|
||||
"embeddings": false,
|
||||
"image_generations": false,
|
||||
"audio_transcriptions": false,
|
||||
"audio_speech": false,
|
||||
"moderations": false,
|
||||
"batches": false,
|
||||
"rerank": false,
|
||||
"a2a": true,
|
||||
"interactions": true
|
||||
}
|
||||
},
|
||||
"text-completion-codestral": {
|
||||
"display_name": "Text Completion Codestral (`text-completion-codestral`)",
|
||||
"url": "https://docs.litellm.ai/docs/providers/codestral",
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ EXCLUDED_GUARD_ONLY_VARS = {
|
|||
EXCLUDED_ROLLOUT_FLAGS = {
|
||||
"LITELLM_USE_RUST_OCR",
|
||||
"LITELLM_RUST",
|
||||
"TOKEN_KIOSK_API_KEY",
|
||||
"TOKEN_KIOSK_API_BASE",
|
||||
}
|
||||
|
||||
# Internal infrastructure tuning parameters for streaming/queue management
|
||||
|
|
|
|||
65
tests/test_litellm/test_token_kiosk.py
Normal file
65
tests/test_litellm/test_token_kiosk.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import litellm
|
||||
from litellm.llms.token_kiosk.chat.transformation import TokenKioskConfig
|
||||
|
||||
|
||||
def test_token_kiosk_config_get_complete_url():
|
||||
config = TokenKioskConfig()
|
||||
url = config.get_complete_url(
|
||||
api_base="https://agent-router.gaib.ai/v1",
|
||||
api_key="test-key",
|
||||
model="token_kiosk/claude-3-5-sonnet",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
assert url == "https://agent-router.gaib.ai/v1/chat/completions"
|
||||
|
||||
# Test trailing slash
|
||||
url_slash = config.get_complete_url(
|
||||
api_base="https://agent-router.gaib.ai/v1/",
|
||||
api_key="test-key",
|
||||
model="token_kiosk/claude-3-5-sonnet",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
assert url_slash == "https://agent-router.gaib.ai/v1/chat/completions"
|
||||
|
||||
# Test full endpoint path already ending with /chat/completions
|
||||
url_full = config.get_complete_url(
|
||||
api_base="https://agent-router.gaib.ai/v1/chat/completions",
|
||||
api_key="test-key",
|
||||
model="token_kiosk/claude-3-5-sonnet",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
assert url_full == "https://agent-router.gaib.ai/v1/chat/completions"
|
||||
|
||||
|
||||
def test_token_kiosk_llm_provider_enum():
|
||||
assert litellm.LlmProviders.TOKEN_KIOSK.value == "token_kiosk"
|
||||
assert "token_kiosk" in litellm.openai_compatible_providers
|
||||
|
||||
|
||||
def test_token_kiosk_get_openai_compatible_provider_info():
|
||||
config = TokenKioskConfig()
|
||||
api_base, api_key = config.get_openai_compatible_provider_info(
|
||||
api_base=None, api_key="test-key"
|
||||
)
|
||||
assert api_base == "https://agent-router.gaib.ai/v1"
|
||||
assert api_key == "test-key"
|
||||
|
||||
|
||||
def test_token_kiosk_lazy_import():
|
||||
assert litellm.TokenKioskConfig is TokenKioskConfig
|
||||
|
||||
|
||||
def test_token_kiosk_get_llm_provider():
|
||||
model, custom_llm_provider, dynamic_api_key, api_base = (
|
||||
litellm.get_llm_provider(
|
||||
model="token_kiosk/claude-3-5-sonnet",
|
||||
api_key="test-token-kiosk-key",
|
||||
)
|
||||
)
|
||||
assert model == "claude-3-5-sonnet"
|
||||
assert custom_llm_provider == "token_kiosk"
|
||||
assert dynamic_api_key == "test-token-kiosk-key"
|
||||
assert api_base == "https://agent-router.gaib.ai/v1"
|
||||
Loading…
Add table
Reference in a new issue