|
1 | 1 | import argparse |
2 | 2 | import os.path |
3 | 3 | import sys |
4 | | -import openai as openai |
| 4 | +import pkg_resources |
| 5 | +import subprocess |
5 | 6 | import tiktoken |
| 7 | +import openai as openai |
6 | 8 | from config import API_KEY |
7 | 9 |
|
| 10 | +# List of required packages |
| 11 | +required_packages = [ |
| 12 | + 'openai', |
| 13 | + 'tiktoken', |
| 14 | +] |
| 15 | + |
| 16 | + |
| 17 | +# Function to check if a package is already installed |
| 18 | +def package_is_installed(package): |
| 19 | + return package in {pkg.key for pkg in pkg_resources.working_set} |
| 20 | + |
| 21 | + |
| 22 | +# Function to install required packages using pip |
| 23 | +def install_packages(): |
| 24 | + for package in required_packages: |
| 25 | + if not package_is_installed(package): |
| 26 | + try: |
| 27 | + subprocess.check_call([sys.executable, "-m", "pip", "install", package]) |
| 28 | + except subprocess.CalledProcessError: |
| 29 | + return False |
| 30 | + return True |
| 31 | + |
| 32 | + |
| 33 | +# Install required packages |
| 34 | +if not install_packages(): |
| 35 | + print("Failed to install required packages. Please make sure you have pip installed.") |
| 36 | + sys.exit(1) |
| 37 | + |
8 | 38 | parser = argparse.ArgumentParser(description="CodeScribe - An Automate way to describe code") |
9 | 39 |
|
10 | 40 | parser.add_argument('-s', '--code_folder', type=str, help='Path to the code folder') |
@@ -69,15 +99,24 @@ def num_tokens_from_string(string: str, encoding_name: str) -> int: |
69 | 99 | token_count = num_tokens_from_string(code, "cl100k_base") |
70 | 100 | print(f"Number of token: {token_count}") |
71 | 101 |
|
72 | | -openai.api_key = API_KEY |
73 | | - |
74 | | -response = openai.Completion.create( |
75 | | - model="text-davinci-003", |
76 | | - prompt=prompt, |
77 | | - temperature=0, |
78 | | - max_tokens=2048, |
79 | | - |
80 | | -) |
81 | | - |
82 | | -print("\nGenerated comments:") |
83 | | -print(response.choices[0].text) |
| 102 | +response = "" |
| 103 | + |
| 104 | +# if token_count <= 2048: |
| 105 | +# openai.api_key = API_KEY |
| 106 | +# response = openai.Completion.create( |
| 107 | +# model="text-davinci-003", |
| 108 | +# prompt=prompt, |
| 109 | +# temperature=0, |
| 110 | +# max_tokens=2048, |
| 111 | +# |
| 112 | +# ) |
| 113 | +# else: |
| 114 | +# print(f"Sry text limit is 2048 at once") |
| 115 | + |
| 116 | +# print("\nGenerated comments:") |
| 117 | +# code_scribe_response = response.choices[0].text |
| 118 | +# print(code_scribe_response) |
| 119 | + |
| 120 | +# Create the "CodeScribe Files" directory |
| 121 | +output_dir = os.path.join(os.getcwd(), "CodeScribe Files") |
| 122 | +os.makedirs(output_dir, exist_ok=True) |
0 commit comments