跳到主要内容
本笔记本介绍了如何开始使用 JinaChat 聊天模型。
from langchain_community.chat_models import JinaChat
from langchain.messages import HumanMessage, SystemMessage
from langchain_core.prompts.chat import (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
    SystemMessagePromptTemplate,
)
chat = JinaChat(temperature=0)
messages = [
    SystemMessage(
        content="You are a helpful assistant that translates English to French."
    ),
    HumanMessage(
        content="Translate this sentence from English to French. I love programming."
    ),
]
chat(messages)
AIMessage(content="J'aime programmer.", additional_kwargs={}, example=False)
您可以通过使用 MessagePromptTemplate 来利用模板。您可以从一个或多个 MessagePromptTemplate 构建一个 ChatPromptTemplate。您可以使用 ChatPromptTemplateformat_prompt——这会返回一个 PromptValue,您可以将其转换为字符串或 Message 对象,具体取决于您是想将格式化值用作 llm 还是聊天模型的输入。 为方便起见,模板上公开了一个 from_template 方法。如果您使用此模板,它将如下所示:
template = (
    "You are a helpful assistant that translates {input_language} to {output_language}."
)
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
human_template = "{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
chat_prompt = ChatPromptTemplate.from_messages(
    [system_message_prompt, human_message_prompt]
)

# get a chat completion from the formatted messages
chat(
    chat_prompt.format_prompt(
        input_language="English", output_language="French", text="I love programming."
    ).to_messages()
)
AIMessage(content="J'aime programmer.", additional_kwargs={}, example=False)

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.