Skip to main content

JinaChat

本笔记本介绍了如何开始使用JinaChat聊天模型。

from langchain.chat_models import JinaChat
from langchain.prompts.chat import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
AIMessagePromptTemplate,
HumanMessagePromptTemplate,
)
from langchain.schema import AIMessage, HumanMessage, SystemMessage
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进行模板化。您可以从一个或多个MessagePromptTemplates构建一个ChatPromptTemplate。您可以使用ChatPromptTemplateformat_prompt方法,它返回一个PromptValue,您可以将其转换为字符串或消息对象,具体取决于您是否希望将格式化的值用作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]
)

# 从格式化的消息中获取聊天完成
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)