-
Notifications
You must be signed in to change notification settings - Fork 0
/
support_ai_langchain.py
36 lines (23 loc) · 1.03 KB
/
support_ai_langchain.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
29
30
31
32
33
34
35
36
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
import os
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_community.document_loaders import TextLoader
from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores import FAISS
from langchain.text_splitter import RecursiveCharacterTextSplitter
load_dotenv()
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.1)
prompt = ChatPromptTemplate.from_messages([
("system", "You are an AI customer support agent. Answer the questions with the most accurate information. If you don't know the answer, say 'I don't know'."),
("human", "{input}")
])
chain = prompt | llm | StrOutputParser()
loader = TextLoader('./data/support_tickets_3.txt')
data = loader.load()
embeddings = OpenAIEmbeddings()
text_splitter = RecursiveCharacterTextSplitter()
documents = text_splitter.split_documents(data)
vectorstore = FAISS.from_documents(documents, embeddings)
print(documents)