-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel_chain.py
More file actions
65 lines (46 loc) · 1.99 KB
/
Copy pathparallel_chain.py
File metadata and controls
65 lines (46 loc) · 1.99 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
from langchain_core.runnables import RunnableParallel
load_dotenv()
model1 =HuggingFaceEndpoint(
repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1",
task="conversational", # ✅ not text-generation
provider="together"
)
model2 = HuggingFaceEndpoint(
repo_id="tiiuae/falcon-7b",
task="text-generation",
provider="together"
)
prompt1 = PromptTemplate(
template='Generate short and simple notes from the following text \n {text}',
input_variables=['text']
)
prompt2 = PromptTemplate(
template='Generate 5 short question answers from the following text \n {text}',
input_variables=['text']
)
prompt3 = PromptTemplate(
template='Merge the provided notes and quiz into a single document \n notes -> {notes} and quiz -> {quiz}',
input_variables=['notes', 'quiz']
)
parser = StrOutputParser()
parallel_chain = RunnableParallel({
'notes': prompt1 | model1 | parser,
'quiz': prompt2 | model2 | parser
})
merge_chain = prompt3 | model1 | parser
chain = parallel_chain | merge_chain
text = """
Streamlit is an open-source Python library for building interactive web apps using only Python. It's ideal for creating dashboards, data-driven web apps, reporting tools and interactive user interfaces without needing HTML, CSS or JavaScript.
This article introduces key Streamlit features, shows how to build a simple app and explains how to run it on a local server using minimal code.
Streamlit Installation
Make sure Python and pip are already installed on your system. To install Streamlit, run the following command in the command prompt or terminal:
pip install streamlit
"""
result = chain.invoke({'text':text})
print(result)
chain.get_graph().print_ascii()