Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 5 minutes and 26 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
总体概览该变更改进了流式响应的跟踪和验证逻辑,通过引入 变更内容
预估代码审查工作量🎯 3 (Moderate) | ⏱️ ~20 minutes 可能相关的 PR
诗歌
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/core/src/llm-core/platform/model.ts (2)
330-337: 类型签名扩展合理,需修复格式将参数类型从
AIMessageChunk扩展为AIMessage | AIMessageChunk是合理的,因为现在需要在非流式路径(第 507-509 行)中复用此方法。对tool_call_chunks的类型转换是必要的,因为只有AIMessageChunk有此属性。🛠️ 修复 Prettier 格式
private _hasToolCallChunk(message?: AIMessage | AIMessageChunk): boolean { return ( (message?.tool_calls?.length ?? 0) > 0 || - ((message as AIMessageChunk | undefined)?.tool_call_chunks?.length ?? - 0) > 0 || + ((message as AIMessageChunk | undefined)?.tool_call_chunks + ?.length ?? 0) > 0 || (message?.invalid_tool_calls?.length ?? 0) > 0 ) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/llm-core/platform/model.ts` around lines 330 - 337, The _hasToolCallChunk method signature change to accept AIMessage | AIMessageChunk is fine; fix the formatting so it meets Prettier/style rules: ensure the conditional expression is line-broken and indented cleanly, keep the explicit cast for accessing tool_call_chunks on AIMessageChunk (e.g., (message as AIMessageChunk | undefined)?.tool_call_chunks) and align the nullish coalescing checks for tool_calls, tool_call_chunks, and invalid_tool_calls so the parentheses and operators are on the correct lines to satisfy the project's formatter.
256-260: 代码逻辑正确,但有格式问题
hasResponse的追踪逻辑正确地区分了"收到数据块"和"收到有效内容"。静态分析工具指出此处有格式问题。🛠️ 修复 Prettier 格式
hasResponse = hasResponse || hasTool || - getMessageContent(chunk.message.content).trim().length > 0 + getMessageContent(chunk.message.content).trim() + .length > 0🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/llm-core/platform/model.ts` around lines 256 - 260, 代码逻辑无误但存在 Prettier 格式问题:在包含 hasResponse 更新和 yield chunk 的代码块(涉及变量 hasResponse、hasTool、getMessageContent 和 chunk)应用项目的 Prettier/格式化规则以修复换行与缩进,使表达式和 yield 语句符合统一风格(例如将条件表达式和 yield 分为单独行并确保正确空格/分号),然后保存以通过静态检查。
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/src/llm-core/platform/model.ts`:
- Around line 330-337: The _hasToolCallChunk method signature change to accept
AIMessage | AIMessageChunk is fine; fix the formatting so it meets
Prettier/style rules: ensure the conditional expression is line-broken and
indented cleanly, keep the explicit cast for accessing tool_call_chunks on
AIMessageChunk (e.g., (message as AIMessageChunk | undefined)?.tool_call_chunks)
and align the nullish coalescing checks for tool_calls, tool_call_chunks, and
invalid_tool_calls so the parentheses and operators are on the correct lines to
satisfy the project's formatter.
- Around line 256-260: 代码逻辑无误但存在 Prettier 格式问题:在包含 hasResponse 更新和 yield chunk
的代码块(涉及变量 hasResponse、hasTool、getMessageContent 和 chunk)应用项目的
Prettier/格式化规则以修复换行与缩进,使表达式和 yield 语句符合统一风格(例如将条件表达式和 yield
分为单独行并确保正确空格/分号),然后保存以通过静态检查。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fa60dab4-877f-439b-b914-d78f7e70a20d
📒 Files selected for processing (1)
packages/core/src/llm-core/platform/model.ts
There was a problem hiding this comment.
Code Review
This pull request improves response validation in ChatLunaChatModel by introducing a hasResponse flag to track whether a stream or completion contains actual content or tool calls, ensuring that empty responses are correctly identified as failures. Feedback suggests optimizing the streaming loop to avoid redundant string processing once a response is detected and notes that the final validation check is redundant for streaming paths already handled by internal assertions.
| hasResponse = | ||
| hasResponse || | ||
| hasTool || | ||
| getMessageContent(chunk.message.content).trim().length > 0 |
There was a problem hiding this comment.
在流式响应的循环中,hasResponse 的判断逻辑可以进行微调以提高效率。一旦 hasResponse 变为 true,后续的 chunk 就不再需要调用 getMessageContent 和 trim() 进行检查。考虑到流式响应可能包含大量细碎的 chunk,这种优化在处理高吞吐量响应时是有益的。
| hasResponse = | |
| hasResponse || | |
| hasTool || | |
| getMessageContent(chunk.message.content).trim().length > 0 | |
| if (!hasResponse) { | |
| hasResponse = | |
| hasTool || | |
| getMessageContent(chunk.message.content).trim().length > 0 | |
| } |
| if ( | ||
| getMessageContent(response.message.content).trim() | ||
| .length < 1 && | ||
| this._hasToolCallChunk( | ||
| response.message as AIMessage | AIMessageChunk | ||
| ) !== true | ||
| ) { | ||
| throw new ChatLunaError( | ||
| ChatLunaErrorCode.API_REQUEST_FAILED | ||
| ) | ||
| } |
变更说明
API_REQUEST_FAILED,交给模型层现有maxRetries处理。验证
yarn fast-build core