-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
28 lines (21 loc) · 841 Bytes
/
main.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
26
27
28
import os
from dotenv import load_dotenv
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
load_dotenv(dotenv_path=".env.dev")
model = ChatOpenAI(api_key=os.getenv("OPENAI_API_KEY"))
system_template = "You are a helpful assistant that can translate between Vietnamese and English."
human_template = "{text}"
prompt_template = ChatPromptTemplate.from_messages(
[("system", system_template), ("user", human_template)]
)
parser = StrOutputParser()
chain = prompt_template | model | parser
while True:
user_input = input("Human: ")
if user_input.lower() == "exit":
break
output = chain.invoke({"text": user_input})
print(f"Assistant: {output}")