Skip to content

fix: 有关Like知识库的相关问题#579

Merged
Samueli924 merged 1 commit intoSamueli924:mainfrom
Guang233:main
Dec 25, 2025
Merged

fix: 有关Like知识库的相关问题#579
Samueli924 merged 1 commit intoSamueli924:mainfrom
Guang233:main

Conversation

@Guang233
Copy link
Copy Markdown
Contributor

@Guang233 Guang233 commented Dec 25, 2025

修复了Like知识库的以下问题:

  • token检查失败:请求方式由POST改为GET
  • 删除无用或错误代码:如返回体中code的判断(返回体中没有该字段)
  • 修改处理多选题答案逻辑:避免出现所有多选题的答案选项都是AAAABBBBCCCCDDDD

Summary by CodeRabbit

  • Bug Fixes
    • Improved API communication reliability and response handling for better accuracy
    • Enhanced balance retrieval functionality with optimized HTTP method
    • Fixed configuration parsing to ensure retry settings are properly interpreted as integers
    • Corrected answer processing logic for multiple-choice and completion question formats
    • Resolved duplicate option additions that could occur during response handling

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 25, 2025

📝 Walkthrough

Walkthrough

These changes modify API response handling and text processing logic. Specifically, they remove conditional code validation, switch to GET for balance retrieval, add type casting for configuration values, adjust text cleaning logic, and refactor answer assembly in response parsing.

Changes

Cohort / File(s) Summary
API Response Handling
api/answer.py
Removed code-field validation in _parse_response, changed get_api_balance from POST to GET with direct status-based return, and added int type casting for "likeapi_retry_times" config value in load_config.
Response Processing Logic
api/base.py
Modified clean_res to only strip leading lettered numbering when string length > 1; added break statement in fetch_response after appending matched options for multiple-choice questions; refactored answer assembly in completion handling to join response list directly instead of accumulated answer.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop, skip, and GET request away,
Validations removed, we simplify today,
Strip only the worthy, break duplicate lines,
Join fresh responses—the logic realigns!
Whiskers twitch with satisfaction,
Another fine PR in action!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is in Chinese and relates to fixes for 'Like knowledge base' issues, which aligns with the PR objectives describing fixes for token verification, code field removal, and multiple-choice answer handling.
✨ Finishing touches
  • 📝 Docstrings were successfully generated.
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cb4523 and a37c04b.

📒 Files selected for processing (2)
  • api/answer.py
  • api/base.py
🧰 Additional context used
🪛 Ruff (0.14.10)
api/answer.py

607-607: Probable use of requests call with verify=False disabling SSL certificate checks

(S501)

api/base.py

685-685: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)


686-686: String contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH EXCLAMATION MARK). Did you mean ! (EXCLAMATION MARK)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH QUESTION MARK). Did you mean ? (QUESTION MARK)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH SEMICOLON). Did you mean ; (SEMICOLON)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH COLON). Did you mean : (COLON)?

(RUF001)


792-792: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (5)
api/base.py (2)

792-792: Good fix for preventing duplicate option additions.

The break statement correctly prevents duplicate option letters from being added when an answer matches multiple options in the list. This directly addresses the issue mentioned in the PR description where multiple-choice answers were incorrectly becoming "AAAABBBBCCCCDDDD".


808-809: LGTM: Cleaner completion answer handling.

The change to directly join the list response into the final answer is correct and cleaner than the previous approach. This ensures completion-type questions properly handle list responses.

api/answer.py (3)

514-514: Correct removal of invalid field check.

Removing the check for the non-existent code field in the API response aligns with the PR objective. The response body doesn't contain this field, so the validation was causing incorrect behavior.


658-658: LGTM: Proper type casting for configuration value.

The int() cast is necessary because configparser returns string values. Without this cast, _retry_times would be a string, which could cause type comparison issues in the retry logic (line 402: try_times < self._retry_times).


604-612: Confirm HTTP method aligns with PR intent to fix token check failures.

The change to GET for the balance endpoint (line 604) matches the PR objective and includes proper Bearer token authorization. The error handling for timeouts, connection failures, and JSON parsing errors is comprehensive.

The verify=False on line 607 disables SSL certificate validation—this matches the pattern used elsewhere in the codebase and may be necessary for the Like knowledge base API, but should remain documented if intentional.

Comment on lines +685 to 687
# 仅在字符串长度大于1时才尝试去除开头的字母编号,防止误删单个字母答案
cleaned = re.sub(r'^[A-Za-z]|[.,!?;:,。!?;:]', '', c) if len(c) > 1 else c
cleaned_res.append(cleaned.strip())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical regex logic error: punctuation will be stripped from anywhere in the string.

The regex pattern r'^[A-Za-z]|[.,!?;:,。!?;:]' has an unintended behavior. The | (OR) operator means:

  • Match a letter at the start of the string, OR
  • Match punctuation anywhere in the string

This will incorrectly remove punctuation from the middle of answer text, not just from the beginning/end as intended.

🔎 Proposed fix
-                # 仅在字符串长度大于1时才尝试去除开头的字母编号,防止误删单个字母答案
-                cleaned = re.sub(r'^[A-Za-z]|[.,!?;:,。!?;:]', '', c) if len(c) > 1 else c
+                # 仅在字符串长度大于1时才尝试去除开头的字母编号和首尾标点,防止误删单个字母答案
+                cleaned = re.sub(r'^[A-Za-z][\s.]?|[.,!?;:,。!?;:]+$', '', c) if len(c) > 1 else c

This revised pattern:

  • ^[A-Za-z][\s.]? - removes a leading letter optionally followed by space or dot
  • [.,!?;:,。!?;:]+$ - removes trailing punctuation only
  • Prevents removal of punctuation from the middle of text
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# 仅在字符串长度大于1时才尝试去除开头的字母编号,防止误删单个字母答案
cleaned = re.sub(r'^[A-Za-z]|[.,!?;:,。!?;:]', '', c) if len(c) > 1 else c
cleaned_res.append(cleaned.strip())
# 仅在字符串长度大于1时才尝试去除开头的字母编号和首尾标点,防止误删单个字母答案
cleaned = re.sub(r'^[A-Za-z][\s.]?|[.,!?;:,。!?;:]+$', '', c) if len(c) > 1 else c
cleaned_res.append(cleaned.strip())
🧰 Tools
🪛 Ruff (0.14.10)

685-685: Comment contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF003)


686-686: String contains ambiguous (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH EXCLAMATION MARK). Did you mean ! (EXCLAMATION MARK)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH QUESTION MARK). Did you mean ? (QUESTION MARK)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH SEMICOLON). Did you mean ; (SEMICOLON)?

(RUF001)


686-686: String contains ambiguous (FULLWIDTH COLON). Did you mean : (COLON)?

(RUF001)

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 25, 2025

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #580

coderabbitai bot added a commit that referenced this pull request Dec 25, 2025
Docstrings generation was requested by @Samueli924.

* #579 (comment)

The following files were modified:

* `api/answer.py`
* `api/base.py`
@Samueli924 Samueli924 merged commit 0aeb778 into Samueli924:main Dec 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants