Skip to main content
이 노트북은 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을 사용하여 템플릿을 활용할 수 있습니다. 하나 이상의 MessagePromptTemplates에서 ChatPromptTemplate을 빌드할 수 있습니다. ChatPromptTemplateformat_prompt를 사용할 수 있습니다 — 이것은 PromptValue를 반환하며, 형식화된 값을 llm 또는 채팅 모델에 입력으로 사용하려는지 여부에 따라 문자열 또는 Message 객체로 변환할 수 있습니다. 편의를 위해 템플릿에 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)

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I