-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbranch_runnable.py
More file actions
36 lines (28 loc) · 943 Bytes
/
Copy pathbranch_runnable.py
File metadata and controls
36 lines (28 loc) · 943 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
36
from langchain_groq import ChatGroq
from langchain.prompts import PromptTemplate
from langchain.schema.runnable import RunnableSequence , RunnableParallel , RunnablePassthrough , RunnableLambda , RunnableBranch
from langchain_core.output_parsers import StrOutputParser
from dotenv import load_dotenv
import os
load_dotenv()
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
llm = ChatGroq(
model='deepseek-r1-distill-llama-70b'
)
parser=StrOutputParser()
prompt=PromptTemplate(
template='make a details about {topic}',
input_variables=["topic"],
)
prompt1=PromptTemplate(
template='make a summary about {topic}',
input_variables=["topic"],
)
chain1=RunnableSequence(prompt, llm, parser)
chain2=RunnableBranch(
(lambda x: len(x.split())>10,RunnableSequence(prompt1, llm, parser)),
RunnablePassthrough()
)
chain3=RunnableSequence(chain1, chain2)
output=chain3.invoke({"topic": "terror attack"})
print(output)