ChatLiteLLM
LiteLLM 是一個簡化呼叫 Anthropic、Azure、Huggingface、Replicate 等的函式庫。
本筆記本涵蓋如何開始使用 Langchain + LiteLLM I/O 函式庫。
from langchain_community.chat_models import ChatLiteLLM
from langchain_core.messages import HumanMessage
API 參考:ChatLiteLLM | HumanMessage
chat = ChatLiteLLM(model="gpt-3.5-turbo")
messages = [
HumanMessage(
content="Translate this sentence from English to French. I love programming."
)
]
chat(messages)
AIMessage(content=" J'aime la programmation.", additional_kwargs={}, example=False)
ChatLiteLLM
也支援非同步和串流功能:
from langchain_core.callbacks import CallbackManager, StreamingStdOutCallbackHandler
await chat.agenerate([messages])
LLMResult(generations=[[ChatGeneration(text=" J'aime programmer.", generation_info=None, message=AIMessage(content=" J'aime programmer.", additional_kwargs={}, example=False))]], llm_output={}, run=[RunInfo(run_id=UUID('8cc8fb68-1c35-439c-96a0-695036a93652'))])
chat = ChatLiteLLM(
streaming=True,
verbose=True,
callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]),
)
chat(messages)
J'aime la programmation.
AIMessage(content=" J'aime la programmation.", additional_kwargs={}, example=False)