-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsequential_chain.py
More file actions
41 lines (28 loc) · 1.06 KB
/
Copy pathsequential_chain.py
File metadata and controls
41 lines (28 loc) · 1.06 KB
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
37
38
39
40
41
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
# from langchain.chains import SimpleChain
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from dotenv import load_dotenv
load_dotenv()
# Define the prompt template
prompt1 = PromptTemplate(
input_variables=["topic"],
template="Generate a detailed report on {topic}"
)
prompt2 = PromptTemplate(
input_variables=["text"],
template="Generate a 5 points summary from the following text: {text}"
)
def init_model():
llm = HuggingFaceEndpoint(
repo_id="mistralai/Mixtral-8x22B-Instruct-v0.1",
# mistralai/Mixtral-8x22B-Instruct-v0.1
task="text-generation"
)
return ChatHuggingFace(llm=llm)
model = init_model()
parser= StrOutputParser()
chain = prompt1 | model | parser | prompt2 | model | parser
result = chain.invoke({"topic": "AI role in Education"})
print(result) # Should print the French translation of "cricket"
chain.get_graph().print_ascii()