Skip to content

Commit 95950ba

Browse files
committed
Added install_required_packages
1 parent 52d44e5 commit 95950ba

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed

main.py

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
import argparse
22
import os.path
33
import sys
4-
import openai as openai
4+
import pkg_resources
5+
import subprocess
56
import tiktoken
7+
import openai as openai
68
from config import API_KEY
79

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+
838
parser = argparse.ArgumentParser(description="CodeScribe - An Automate way to describe code")
939

1040
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:
6999
token_count = num_tokens_from_string(code, "cl100k_base")
70100
print(f"Number of token: {token_count}")
71101

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

Comments
 (0)