provider_params
langroid/language_models/provider_params.py
Provider-specific parameter configurations for various LLM providers.
LangDBParams
¶
Bases: BaseSettings
Parameters specific to LangDB integration.
PortkeyParams
¶
Bases: BaseSettings
Parameters specific to Portkey integration.
Portkey is an AI gateway that provides a unified API for multiple LLM providers, with features like automatic retries, fallbacks, load balancing, and observability.
Example usage
Use Portkey with Anthropic¶
config = OpenAIGPTConfig( chat_model="portkey/anthropic/claude-3-sonnet-20240229", portkey_params=PortkeyParams( api_key="your-portkey-api-key", provider="anthropic" ) )
get_headers()
¶
Generate Portkey-specific headers from parameters.
Source code in langroid/language_models/provider_params.py
parse_model_string(model_string)
¶
Parse a model string like "portkey/anthropic/claude-3-sonnet" and extract provider and model name.
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple[str, str]
|
(provider, model_name) |
Source code in langroid/language_models/provider_params.py
get_provider_api_key(provider, default_key=DUMMY_API_KEY)
¶
Get the API key for the provider from environment variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider
|
str
|
The provider name (e.g., "anthropic", "openai") |
required |
default_key
|
str
|
Default key to return if not found |
DUMMY_API_KEY
|
Returns:
Type | Description |
---|---|
str
|
The API key for the provider |