Skip to content

Commit

Permalink
Merge pull request #125 from devchat-ai/handle_llm_error
Browse files Browse the repository at this point in the history
Handle llm error
  • Loading branch information
kagami-l authored Jun 18, 2024
2 parents 060900a + 780fe10 commit bf6e266
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/chatmark/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ def __init__(

def _handle_block_flag(self, text: str):
"""convert \\ to \\, and ` to \\`"""
return text.replace("\\", "\\\\").replace("`", "\\`")
return text.replace("```", "\\`\\`\\`") if text else text

def _remove_block_flag(self, text: str):
"""convert \\ to \\, and \\` to `"""
return text.replace("\\`", "`").replace("\\\\", "\\")
return text.replace("\\`\\`\\`", "```") if text else text

@property
def new_text(self) -> Optional[str]:
Expand Down
2 changes: 2 additions & 0 deletions merico/comments/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def main():
code_text = selected_text.get("text", "")

response = add_comments(selected_text=code_text, file_path=file_path)
if not response:
sys.exit(1)
new_code = extract_markdown_block(response)

if not new_code:
Expand Down
2 changes: 2 additions & 0 deletions merico/commit/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ def main():
if branch_name:
user_input += "\ncurrent repo branch name is:" + branch_name
commit_message = generate_commit_message_base_diff(user_input, diff)
if not commit_message:
sys.exit(1)

# TODO
# remove Closes #IssueNumber in commit message
Expand Down
2 changes: 2 additions & 0 deletions merico/docstring/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ def main():
response = add_docstring(
selected_text=selected_text.get("text", ""), file_path=selected_text.get("abspath", "")
)
if not response:
sys.exit(1)

# Get indent level
indent = get_indent_level(selected_text.get("text", ""))
Expand Down
4 changes: 2 additions & 2 deletions merico/explain/explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def explain(selected_text, visible_text):


def main():
explain(selected_text=get_selected_code(), visible_text=get_visible_code())
sys.exit(0)
result = explain(selected_text=get_selected_code(), visible_text=get_visible_code())
sys.exit(0 if result else 1)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions merico/fix/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def main():

# rewrite
response = fix_bugs(selected_text=selected_text, visible_text=visible_text)
if not response:
sys.exit(1)

# apply new code to editor
new_code = extract_markdown_block(response)
Expand Down
2 changes: 2 additions & 0 deletions merico/refactor/names/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def main():

# rewrite
response = reanme_variable(selected_text=selected_code, file_path=selected_file)
if not response:
sys.exit(1)

# apply new code to editor
new_code = extract_markdown_block(response)
Expand Down
2 changes: 2 additions & 0 deletions merico/refactor/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def main():

# rewrite
response = ai_rewrite(question=question, selected_text=selected_text)
if not response:
sys.exit(1)

# apply new code to editor
new_code = extract_markdown_block(response)
Expand Down
2 changes: 2 additions & 0 deletions merico/unit_tests/propose_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def propose_test(
)
or {}
)
if not json_res:
raise ValueError("No valid json response")

else:
# Use the openai api parameters
Expand Down
4 changes: 3 additions & 1 deletion merico/unit_tests/write_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ def write_and_print_tests(

if USE_USER_MODEL:
# Use the wrapped api
_ = chat_completion_stream_out(
response = chat_completion_stream_out(
messages=[{"role": "user", "content": user_msg}],
llm_config={"model": MODEL, "temperature": 0.1},
)
if not response.get("content", None):
raise response["error"]

else:
# Use the openai api parameters
Expand Down

0 comments on commit bf6e266

Please sign in to comment.