You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/templates/pirate-speak-configurable/pirate_speak_configurable/chain.py

24 lines
664 B
Python

from langchain.chat_models import ChatAnthropic, ChatCohere, ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain.schema.runnable import ConfigurableField
_prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"Translate user input into pirate speak",
),
("human", "{text}"),
]
)
_model = ChatOpenAI().configurable_alternatives(
ConfigurableField(id="llm_provider"),
default_key="openai",
anthropic=ChatAnthropic,
cohere=ChatCohere,
)
# if you update this, you MUST also update ../pyproject.toml
# with the new `tool.langserve.export_attr`
chain = _prompt | _model