Fix formatting in ask-code.py and commit.py

This commit is contained in:
bobo.yang 2023-12-27 15:42:51 +08:00
parent d67c3d26a1
commit 14dc3b2b52
2 changed files with 14 additions and 7 deletions

View File

@ -48,7 +48,7 @@ def query(question, lsp_brige_port):
spent_money += (price[0] * token_usage.prompt_tokens) / 1000 + (
price[1] * token_usage.completion_tokens
) / 1000
spent_money = spent_money/0.7
spent_money = spent_money / 0.7
print(f"***/ask-code has costed approximately ${spent_money:.4f} USD for this question.***")

View File

@ -47,16 +47,18 @@ def assert_value(value, message):
print(message, file=sys.stderr, flush=True)
sys.exit(-1)
def decode_path(encoded_path):
octal_pattern = re.compile(r'\\[0-7]{3}')
octal_pattern = re.compile(r"\\[0-7]{3}")
if octal_pattern.search(encoded_path):
bytes_path = encoded_path.encode('utf-8').decode('unicode_escape').encode('latin1')
decoded_path = bytes_path.decode('utf-8')
bytes_path = encoded_path.encode("utf-8").decode("unicode_escape").encode("latin1")
decoded_path = bytes_path.decode("utf-8")
return decoded_path
else:
return encoded_path
def get_modified_files():
"""
获取当前修改文件列表以及已经staged的文件列表
@ -68,7 +70,7 @@ def get_modified_files():
tuple: 包含两个list的元组第一个list包含当前修改过的文件第二个list包含已经staged的文件
"""
""" 获取当前修改文件列表以及已经staged的文件列表"""
output = subprocess.check_output(["git", "status", "-s", "-u"], text=True, encoding="utf-8")
output = subprocess.check_output(["git", "status", "-s", "-u"], text=True, encoding="utf-8")
lines = output.split("\n")
modified_files = []
staged_files = []
@ -355,8 +357,13 @@ def generate_commit_message_base_diff(user_input, diff):
"{__USER_INPUT__}", f"{user_input + language_prompt}"
)
if len(str(prompt)) > 10000:
print("Due to the large size of the diff data, generating a commit message through AI would be very costly, therefore, it is not recommended to use AI for generating the description. Please manually edit the commit message before submitting.")
return {"content":""}
print(
"Due to the large size of the diff data, "
"generating a commit message through AI would be very costly, therefore, "
"it is not recommended to use AI for generating the description. "
"Please manually edit the commit message before submitting."
)
return {"content": ""}
messages = [{"role": "user", "content": prompt}]
response = chat_completion_no_stream(