-
Notifications
You must be signed in to change notification settings - Fork 0
/
7_chat_prompts.py
25 lines (20 loc) · 988 Bytes
/
7_chat_prompts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import load_keys
from langchain.chat_models import ChatOpenAI
from langchain import LLMChain
from langchain.prompts.chat import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
)
chat = ChatOpenAI(temperature=0)
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
#x = chat_prompt.format_prompt(input_language="English", output_language="Spanish", text="I love programming.")
#result = chat(x.to_messages())
chain = LLMChain(llm=chat, prompt=chat_prompt)
result = chain.run(input_language="English", output_language="Spanish", text="I love programming.")
print(result)