-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.py
More file actions
35 lines (22 loc) · 659 Bytes
/
Copy pathloader.py
File metadata and controls
35 lines (22 loc) · 659 Bytes
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
#Text loader
from langchain_community.document_loaders import TextLoader
from langchain.chat_models import init_chat_model
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate
from dotenv import load_dotenv
load_dotenv()
model = init_chat_model(
model="gpt-4o-mini"
)
loader = TextLoader("text.txt",encoding="utf-8")
quiz = PromptTemplate(
template="write the summmary for the following {poem}",
input_variables=["poem"]
)
parser = StrOutputParser(
)
docs = loader.load()
print(docs[0])
chain = quiz|model|parser
result = chain.invoke({"poem":docs[0].page_content})
print(result)