Skip to content

Commit

Permalink
script v0 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarsh2001 committed Nov 4, 2023
1 parent a7465c9 commit 259bec7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions claude/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@


def generate_docstring(file_str, fn_name, key):
with open(file_str, 'r') as f:
content = f.read()
anthropic = Anthropic(
api_key=key,
)

prompt_file = open("resources/prompt.txt", "r")
prompt = prompt_file.read()
prompt = prompt.replace("[fn_name]", fn_name)
prompt = prompt.replace("[file]", file_str)
prompt = prompt.replace("[file]", content)

# TODO: replace this default docstring template with one generated by Claude?
# (so it can support any language, not just Python)
Expand All @@ -25,7 +27,7 @@ def generate_docstring(file_str, fn_name, key):
max_tokens_to_sample=300,
prompt=prompt,
)
print(completion.completion)
return completion.completion

def starter_code(key):
# diff text file all strings, parse the file to only fetch statements with additions
Expand All @@ -45,15 +47,16 @@ def starter_code(key):
# regex to check if there exists a docstring
if line.replace(' ', '') == '+\n':
if in_func and not contains_docstring:
print(func_name)
# fns_without_docstring[func_name] = generate_docstring(filename, func_name, key)
fns_without_docstring[func_name] = generate_docstring(filename, func_name, key)
in_func = False
contains_docstring = False
func_name = ""
if '"""' in line:
contains_docstring = True
return fns_without_docstring

if __name__ == "__main__":
# key = sys.argv[1]
starter_code("hello world")
key = sys.argv[1]
docstring_dict = starter_code(key)
print(docstring_dict)

0 comments on commit 259bec7

Please sign in to comment.