-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (47 loc) · 1.17 KB
/
main.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain, SequentialChain
from dotenv import load_dotenv
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--task", help="Task to be performed", type=str, default="add numbers 0 to 10")
parser.add_argument("--language", help="Language to be used", type=str, default="python")
args = parser.parse_args()
load_dotenv()
# API key is stored in .env file
llm= OpenAI()
code_prompt = PromptTemplate(
template="Write a very short {language} function that will {task}.",
input_variables=[
"language", "task"
]
)
test_prompt = PromptTemplate(
input_variables=[
"language", "code"
],
template="Write a unit test for the following {language} code:\n{code}"
)
code_chain = LLMChain(
llm=llm,
prompt=code_prompt,
output_key="code"
)
test_chain = LLMChain(
llm=llm,
prompt=test_prompt,
output_key="test"
)
chain = SequentialChain(
chains=[
code_chain,
test_chain
],
input_variables=["language", "task"],
output_variables=["code", "test"]
)
result = chain({
"language": args.language,
"task": args.task
})
print(result)