-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (49 loc) · 1.38 KB
/
main.py
File metadata and controls
60 lines (49 loc) · 1.38 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
import getpass
import os
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain, SequentialChain
from dotenv import load_dotenv
import argparse
load_dotenv()
parser = argparse.ArgumentParser()
parser.add_argument("--task", default="return a list of numbers")
parser.add_argument("--language", default="python")
args = parser.parse_args()
if "GOOGLE_API_KEY" not in os.environ:
os.environ["GOOGLE_API_KEY"] = getpass.getpass("Provide your Google API Key")
llm = ChatGoogleGenerativeAI(
model="gemini-pro"
)
code_prompt = PromptTemplate(
template="Write a very short {language} function that will {task}",
input_variables=["language", "task"]
)
test_prompt = PromptTemplate(
template="Write a test for the following {language} code: \n{code}",
input_variables=["language", "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=["test", "code"]
)
result = chain({
"language": args.language,
"task": args.task
})
# print(result)
print("\n>>>> Generated code")
print(result['code'])
print("\n>>>> Generated test")
print(result['test'])