ChatLiteLLMRouter
LiteLLM is a library that simplifies calling Anthropic, Azure, Huggingface, Replicate, etc.
This notebook covers how to get started with using Langchain + the LiteLLM Router I/O library.
from langchain_community.chat_models import ChatLiteLLMRouter
from langchain_core.messages import HumanMessage
from litellm import Router
API Reference:ChatLiteLLMRouter | HumanMessage
model_list = [
{
"model_name": "gpt-4",
"litellm_params": {
"model": "azure/gpt-4-1106-preview",
"api_key": "<your-api-key>",
"api_version": "2023-05-15",
"api_base": "https://<your-endpoint>.openai.azure.com/",
},
},
{
"model_name": "gpt-35-turbo",
"litellm_params": {
"model": "azure/gpt-35-turbo",
"api_key": "<your-api-key>",
"api_version": "2023-05-15",
"api_base": "https://<your-endpoint>.openai.azure.com/",
},
},
]
litellm_router = Router(model_list=model_list)
chat = ChatLiteLLMRouter(router=litellm_router, model_name="gpt-35-turbo")
messages = [
HumanMessage(
content="Translate this sentence from English to French. I love programming."
)
]
chat(messages)
AIMessage(content="J'aime programmer.")