-
Notifications
You must be signed in to change notification settings - Fork 3
/
01-4-sequentialchain.py
36 lines (27 loc) · 1.01 KB
/
01-4-sequentialchain.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.prompts import PromptTemplate
from langchain import OpenAI
from langchain.llms import Anthropic
from langchain.chains import SimpleSequentialChain, LLMChain
from dotenv import load_dotenv
load_dotenv()
prompt = PromptTemplate(
input_variables=["topic"],
template="Write me an outline on {topic}",
)
# llm = Anthropic(temperature=0.5, max_tokens_to_sample=1024)
llm = OpenAI(temperature=0.9, max_tokens=-1)
chain = LLMChain(
llm=llm,
prompt=prompt)
chain = LLMChain(llm=llm, prompt=prompt)
second_prompt = PromptTemplate(
input_variables=["outline"],
template="""Write a blog article in the format of the given outline
Outline:
{outline}""",
)
chain_two = LLMChain(llm=llm, prompt=second_prompt)
overall_chain = SimpleSequentialChain (chains = [chain, chain_two], verbose=True)
# Run the chain specifying only the input variable for the first chain.
catchphrase = overall_chain.run("Learning SQL")
print(catchphrase)