Skip to content

fix: 修复因错误合并导致的bug - #621

Merged
Samueli924 merged 1 commit into
Samueli924:mainfrom
Zropk66:main
Aug 14, 2026
Merged

fix: 修复因错误合并导致的bug#621
Samueli924 merged 1 commit into
Samueli924:mainfrom
Zropk66:main

Conversation

@Zropk66

@Zropk66 Zropk66 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved AI connection checks for more consistent success and failure detection.
    • Reduced duplicate connection attempts and standardized connection test behavior.
    • Improved handling of connection errors and incomplete responses.
  • Improvements

    • Configuration options now reliably fall back to default values when no valid values are provided.
    • Response handling remains consistent while retrying study-related requests.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request consolidates LLM connection testing into one throttled request, standardizes response validation, changes fallback expressions for three configuration values, and simplifies a tuple return statement.

Changes

Connection and Configuration Updates

Layer / File(s) Summary
LLM connection test flow
api/answer.py
AI.check_llm_connection initializes the client and proxy, applies throttling once, sends one request with max_tokens=200, and accepts either message or reasoning content.
Configuration and response-return cleanup
main.py, api/base.py
Three configuration values now use or-based defaults, and fetch_response_with_retry returns its response tuple directly.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题明确表述了这是一个修复类变更,且与本次对连接检测、重试和配置默认值的修正相符。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
api/answer.py (1)

1318-1320: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid hiding response-shape bugs as connection failures.

except Exception also catches local programming and parsing errors, logs only the error text, and makes them indistinguishable from network failures. Catch expected transport/API exceptions and use logger.exception for unexpected failures. Static analysis also reports BLE001.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/answer.py` around lines 1318 - 1320, Update the exception handling around
the connection check in the relevant method of the answer class: catch only the
expected transport/API exception types for connection failures, and log
unexpected exceptions with logger.exception before returning False. Preserve the
existing failure result while preventing local response-shape or programming
errors from being silently classified as connection failures and address the
BLE001 warning.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/answer.py`:
- Around line 1308-1313: Align check_llm_connection() with AI._query_locked() by
requiring non-empty message.content before reporting a successful provider
connection; do not treat reasoning_content alone as sufficient unless
_query_locked() is also updated to use it as the answer content.

---

Nitpick comments:
In `@api/answer.py`:
- Around line 1318-1320: Update the exception handling around the connection
check in the relevant method of the answer class: catch only the expected
transport/API exception types for connection failures, and log unexpected
exceptions with logger.exception before returning False. Preserve the existing
failure result while preventing local response-shape or programming errors from
being silently classified as connection failures and address the BLE001 warning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 92dda8ce-fdf8-4787-8369-4fb69456036c

📥 Commits

Reviewing files that changed from the base of the PR and between dee643f and 9c94561.

📒 Files selected for processing (3)
  • api/answer.py
  • api/base.py
  • main.py

Comment thread api/answer.py
Comment on lines +1308 to +1313
# 统一检查响应
if completion.choices:
msg = completion.choices[0].message
if msg.content or getattr(msg, 'reasoning_content', None):
logger.info(f'{self.name} 连接检查成功')
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Files:"
git ls-files | rg '(^|/)api/answer\.py$|(^|/)main\.py$' || true

echo
echo "api/answer.py relevant snippets:"
sed -n '1240,1290p' api/answer.py || true
sed -n '1298,1320p' api/answer.py || true

echo
echo "main.py relevant snippets:"
sed -n '200,245p' main.py || true

echo
echo "Search for _query_locked and connection check usages:"
rg -n "_query_locked|连接检查|reason" -S api/answer.py main.py || true

echo
echo "Git diff summary/name-only:"
git diff --stat || true
git diff -- api/answer.py main.py | sed -n '1,220p' || true

Repository: Samueli924/chaoxing

Length of output: 6218


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Behavioral probe for the string-validation logic: parse_answer_like logic from _query_locked
# and the connection-check condition as written, over a small sample of response variants.
python3 - <<'PY'
from pathlib import Path
import re

answer_py = Path('api/answer.py').read_text()
m = re.search(r'_query_locked\(.*?\):(?:\n\s+.*)*?(?=\n    def \w|\Z)', answer_py, re.S)
print("FOUND_QUERY_LOCKED=", m is not None)
if m:
    snippet = m.group(0)
    print(snippet)
    print("contains_reasoning_in_parse=", bool(re.search(r'reasoning_content', snippet, re.I)))
    print("contains_text_content=", bool(re.search(r'\.content\b', snippet, re.I)))
else:
    print(answer_py[1240*80:1270*80])

conn = re.search(r'if \s+completion\.choices:\s*\n((?:\s+.+\n)+)', answer_py)
if conn:
    print("FOUND_CONN_CHECK=true")
    print(conn.group(0))
PY

Repository: Samueli924/chaoxing

Length of output: 27070


🌐 Web query:

OpenAI Python ChatCompletionMessage reasoning_content attribute Content

💡 Result:

In the standard official OpenAI Python SDK, the ChatCompletionMessage object does not include a native reasoning_content attribute [1]. While some third-party model providers (such as DeepSeek or Grok) and local inference servers like vLLM include a reasoning_content field in their API responses to expose "thinking" or "reasoning" tokens, OpenAI has explicitly declined to incorporate this field as a standard part of their Python SDK's ChatCompletionMessage object [2][3][4][5]. Key technical points: 1. SDK Absence: The official openai-python library's ChatCompletionMessage class definition does not define reasoning_content [1]. Attempts to introduce this field into the official SDK via pull requests have been declined [2]. 2. Third-Party Usage: You may encounter this field when using the OpenAI Python client to communicate with third-party APIs that follow the OpenAI Chat Completions API format but extend it to include reasoning tokens [4][5]. In these scenarios, developers often access the field dynamically (e.g., via getattr or casting) because the SDK's type-hinting will not recognize it [6][4]. 3. OpenAI's Reasoning Approach: OpenAI handles reasoning models via their own specific APIs and architectural patterns (e.g., the Responses API or specific reasoning contexts) rather than by exposing raw reasoning tokens in the standard ChatCompletionMessage structure [7]. If you are working with a third-party service that returns reasoning_content, you can access it by treating the response message as a dictionary or using dynamic attribute access, but you should not expect it to be a permanent or supported feature of the official OpenAI Python SDK [6][4].

Citations:


Keep the AI provider startup check aligned with the real answer parsing.

check_llm_connection() returns success when only reasoning_content is present, because AI._query_locked() continues to parse completion.choices[0].message.content. A reasoning-only response can clear startup validation but fail as None when real questions are answered. Require usable answer content in the check, or parse reasoning_content in _query_locked() the same way.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/answer.py` around lines 1308 - 1313, Align check_llm_connection() with
AI._query_locked() by requiring non-empty message.content before reporting a
successful provider connection; do not treat reasoning_content alone as
sufficient unless _query_locked() is also updated to use it as the answer
content.

@Samueli924
Samueli924 merged commit 9699e63 into Samueli924:main Aug 14, 2026
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