fix:完善了代码格式
Some checks failed
Python application test / build (pull_request) Failing after 28s
Some checks failed
Python application test / build (pull_request) Failing after 28s
将一部分函数移至utils内
This commit is contained in:
@@ -2,31 +2,9 @@ import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from utils import *
|
||||
import openai
|
||||
|
||||
#utils
|
||||
def read_file_content(file_path: str) -> str:
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
return file.read()
|
||||
except FileNotFoundError:
|
||||
print("Error: File not found.")
|
||||
sys.exit(1)
|
||||
except IOError:
|
||||
print("Error: Could not read file.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def remove_comments(code: str, extension: str) -> str:
|
||||
if extension == ".py":
|
||||
return code.split("#")[0].strip()
|
||||
elif extension in {".js", ".cpp"}:
|
||||
code = re.sub(r"//.*", "", code)
|
||||
code = re.sub(r"/\*.*?\*/", "", code, flags=re.DOTALL)
|
||||
return code.strip()
|
||||
return code.strip()
|
||||
|
||||
|
||||
def detect_gpt(filename: str):
|
||||
client = openai.OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
||||
|
||||
Reference in New Issue
Block a user