-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_chain.py
More file actions
31 lines (26 loc) · 914 Bytes
/
example_chain.py
File metadata and controls
31 lines (26 loc) · 914 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
from hyperchain.prompt_templates import StringTemplate
from hyperchain.chain import LLMChain
from hyperchain.llm_runners import OpenAIRunner
template_prepare = StringTemplate(
"Answer the following question:\n{question}\n\nShort answer is:\n"
)
template_guess = StringTemplate(
"Guess what question this was an answer to:\n{answer}\n\nGuessed question:\n"
)
llm_chain_prepare = LLMChain(
template=template_prepare,
llm_runner=OpenAIRunner(
api_key="ENTER API KEY HERE OR IN ENV VARIABLE",
model_params={"max_tokens": 600},
),
output_name="answer",
)
llm_chain_guess = LLMChain(
template=template_guess,
llm_runner=OpenAIRunner(
api_key="ENTER API KEY HERE OR IN ENV VARIABLE",
model_params={"max_tokens": 50},
),
)
llm_chain = llm_chain_prepare + llm_chain_guess
print(llm_chain.run(question="What is APR?").result) # Run chain of querries