Skip to content

修复使用openai类型接口,第一次调用失败的bug#310

Open
askyLYZ wants to merge 3 commits intoclaude-code-best:mainfrom
askyLYZ:main
Open

修复使用openai类型接口,第一次调用失败的bug#310
askyLYZ wants to merge 3 commits intoclaude-code-best:mainfrom
askyLYZ:main

Conversation

@askyLYZ
Copy link
Copy Markdown

@askyLYZ askyLYZ commented Apr 20, 2026

20260420152601312 配置openai 兼容的api接口,因为加载问题,第一次运行恒定报错。尤其在通过-p等全自动化的方式调用的时候影响极大

Summary by CodeRabbit

  • Refactor

    • Improved OpenAI client initialization to be asynchronous for more reliable/performant request handling.
  • Bug Fixes

    • Assistant responses now always provide an empty string instead of null for empty content, preventing unexpected null content in outputs.

askyLYZ added 2 commits April 20, 2026 15:24
更新openai接口类型的动态调用
修复openai类型接口第一次调用失败的bug
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4052b7aa-bfb7-4a00-9d17-b83550d9f258

📥 Commits

Reviewing files that changed from the base of the PR and between 9dd521a and d3ac5fe.

📒 Files selected for processing (1)
  • packages/@ant/model-provider/src/shared/openaiConvertMessages.ts

📝 Walkthrough

Walkthrough

Converted OpenAI client initialization to async with dynamic import; callers now await the client. Minor message shape change: assistant content uses empty string instead of null. Caching semantics remain unchanged.

Changes

Cohort / File(s) Summary
OpenAI Client Factory
src/services/api/openai/client.ts
Made getOpenAIClient asynchronous (returns Promise<OpenAI>). Replaced static OpenAI import with await import('openai') and switched to a type-only import. Removed an unused isEnvTruthy import. Preserved existing caching behavior.
OpenAI Query Function
src/services/api/openai/index.ts
Updated queryModelOpenAI to await getOpenAIClient(...) so client acquisition occurs asynchronously before making requests.
Message Conversion
packages/@ant/model-provider/src/shared/openaiConvertMessages.ts
Changed assistant message content when no text parts exist from null to an empty string (""), ensuring content is always a string.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hop from sync to async, light and spry,
Dynamic imports under a bright sky,
Empty strings where silence used to be,
Caches safe, the client wakes with glee,
A little rabbit cheers, "Now run, run free!"

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title in Chinese describes fixing a bug where OpenAI-compatible API calls fail on first invocation, which directly aligns with the changes: making getOpenAIClient async to ensure proper initialization before use.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/services/api/openai/client.ts`:
- Line 1: The import statement for the OpenAI type is missing a closing quote
which breaks TypeScript parsing; fix the unterminated string in the import for
"openai" (the line importing type OpenAI) by adding the missing closing quote
(and optional semicolon) so the statement becomes a valid import, then rerun bun
run typecheck to ensure no errors remain.
🪄 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

Run ID: 14cc8887-23a0-49b5-b122-48e7c01514f5

📥 Commits

Reviewing files that changed from the base of the PR and between e4ce08f and 9dd521a.

📒 Files selected for processing (2)
  • src/services/api/openai/client.ts
  • src/services/api/openai/index.ts

@@ -1,6 +1,5 @@
import OpenAI from 'openai'
import type OpenAI from 'openai
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Check if the file exists and read the first few lines
if [ -f "src/services/api/openai/client.ts" ]; then
  echo "=== File exists, reading first 30 lines ===" 
  head -n 30 "src/services/api/openai/client.ts"
else
  echo "File not found at src/services/api/openai/client.ts"
  # Let's search for it
  echo "=== Searching for client.ts in openai directories ==="
  fd "client\.ts" | grep -i openai
fi

Repository: claude-code-best/claude-code

Length of output: 1071


Fix the unterminated openai import on line 1.

The string literal is missing a closing quote, which prevents TypeScript from parsing the file and causes bun run typecheck to fail.

🐛 Proposed fix
-import type OpenAI from 'openai
+import type OpenAI from 'openai'

Please rerun bun run typecheck after applying the fix. As per coding guidelines, "TypeScript strict mode - bun run typecheck must pass with zero errors".

📝 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
import type OpenAI from 'openai
import type OpenAI from 'openai'
🧰 Tools
🪛 Biome (2.4.11)

[error] 1-1: unterminated string literal

(parse)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/api/openai/client.ts` at line 1, The import statement for the
OpenAI type is missing a closing quote which breaks TypeScript parsing; fix the
unterminated string in the import for "openai" (the line importing type OpenAI)
by adding the missing closing quote (and optional semicolon) so the statement
becomes a valid import, then rerun bun run typecheck to ensure no errors remain.

修复openai兼容接口的GLM-5的适配bug
@claude-code-best
Copy link
Copy Markdown
Owner

@askyLYZ 请修复 CI 的类型问题

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