|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
import os
|
|
|
|
|
import ast
|
|
|
|
|
import tiktoken
|
|
|
|
|
import os
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import tiktoken
|
|
|
|
|
from langchain.llms import OpenAI
|
|
|
|
|
from langchain.prompts import PromptTemplate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_files(directory):
|
|
|
|
|
files_list = []
|
|
|
|
|
for root, dirs, files in os.walk(directory):
|
|
|
|
@ -13,6 +15,7 @@ def find_files(directory):
|
|
|
|
|
files_list.append(os.path.join(root, file))
|
|
|
|
|
return files_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_functions(file_path):
|
|
|
|
|
with open(file_path, 'r') as file:
|
|
|
|
|
source_code = file.read()
|
|
|
|
@ -25,6 +28,7 @@ def extract_functions(file_path):
|
|
|
|
|
functions[func_name] = func_def
|
|
|
|
|
return functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_classes(file_path):
|
|
|
|
|
with open(file_path, 'r') as file:
|
|
|
|
|
source_code = file.read()
|
|
|
|
@ -40,6 +44,7 @@ def extract_classes(file_path):
|
|
|
|
|
classes[class_name] = ", ".join(function_names)
|
|
|
|
|
return classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_functions_and_classes(directory):
|
|
|
|
|
files = find_files(directory)
|
|
|
|
|
functions_dict = {}
|
|
|
|
@ -53,6 +58,7 @@ def extract_functions_and_classes(directory):
|
|
|
|
|
classes_dict[file] = classes
|
|
|
|
|
return functions_dict, classes_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_functions(functions_dict, formats, dir):
|
|
|
|
|
c1 = len(functions_dict)
|
|
|
|
|
for i, (source, functions) in enumerate(functions_dict.items(), start=1):
|
|
|
|
@ -70,7 +76,8 @@ def parse_functions(functions_dict, formats, dir):
|
|
|
|
|
response = llm(prompt.format(code=function))
|
|
|
|
|
mode = "a" if Path(f"outputs/{source_w}").exists() else "w"
|
|
|
|
|
with open(f"outputs/{source_w}", mode) as f:
|
|
|
|
|
f.write(f"\n\n# Function name: {name} \n\nFunction: \n```\n{function}\n```, \nDocumentation: \n{response}")
|
|
|
|
|
f.write(
|
|
|
|
|
f"\n\n# Function name: {name} \n\nFunction: \n```\n{function}\n```, \nDocumentation: \n{response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_classes(classes_dict, formats, dir):
|
|
|
|
@ -92,6 +99,7 @@ def parse_classes(classes_dict, formats, dir):
|
|
|
|
|
with open(f"outputs/{source_w}", "a" if Path(f"outputs/{source_w}").exists() else "w") as f:
|
|
|
|
|
f.write(f"\n\n# Class name: {name} \n\nFunctions: \n{function_names}, \nDocumentation: \n{response}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def transform_to_docs(functions_dict, classes_dict, formats, dir):
|
|
|
|
|
docs_content = ''.join([str(key) + str(value) for key, value in functions_dict.items()])
|
|
|
|
|
docs_content += ''.join([str(key) + str(value) for key, value in classes_dict.items()])
|
|
|
|
|