Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: baidu error_code 336006 #5194

Merged
merged 5 commits into from
Aug 6, 2024
Merged

fix: baidu error_code 336006 #5194

merged 5 commits into from
Aug 6, 2024

Conversation

HyiKi
Copy link
Contributor

@HyiKi HyiKi commented Aug 5, 2024

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

fix baidu error code 336006 the role of message with odd index in the messages must be assistant, change the summary role from system to assistant

修复百度错误代码 336006 “the role of message with odd index in the messages must be assistant”,将摘要角色从 system 更改为 assistant

📝 补充信息 | Additional Information

the role of summary is system, it leads to Baidu error code 336006 the role of message with odd index in the messages must be assistant

摘要的角色是 system,这会导致百度错误代码 336006:消息中奇数索引的消息的角色必须是 assistant

Summary by CodeRabbit

  • New Features
    • Enhanced the chat functionality with refined role assignment for messages, improving conversation flow accuracy.
  • Bug Fixes
    • Addressed an issue with message role assignment for even-length message lists, ensuring more reliable chat interactions.
    • Improved message role handling to ensure the "system" role is always the first message in the list.

Copy link

vercel bot commented Aug 5, 2024

@HyiKi is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Walkthrough

The recent changes enhance the chat methods in both the ErnieApi and HunyuanApi classes by refining how message roles are assigned based on their positions. The updates introduce conditional checks that adjust "system" roles as needed and improve message handling for even-length lists. These adjustments aim to resolve issues related to message role interpretation, ensuring a smoother conversation flow and compliance with new handling rules.

Changes

File Change Summary
app/client/platforms/baidu.ts Modified chat method in ErnieApi to change "system" roles to "user" and refined message handling for even-length lists.
app/client/platforms/tencent.ts Updated chat method in HunyuanApi to enforce that "system" roles must be the first message and adjusted role assignment accordingly.

Poem

🐰 In the meadow, changes bloom,
Roles now shift, dispelling gloom.
"System" to "user," a clever turn,
Guiding chats, helping us learn.
With each hop and joyful cheer,
Our conversations thrive, sincere! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aa40015 and d0e296a.

Files selected for processing (1)
  • app/client/platforms/baidu.ts (1 hunks)
Additional comments not posted (1)
app/client/platforms/baidu.ts (1)

80-81: Ensure message roles adhere to Baidu's requirements.

The conditional check that changes the role from "system" to "assistant" ensures compliance with Baidu's error code 336006. This change is crucial for preventing errors related to message roles with odd indices.

Copy link
Contributor

github-actions bot commented Aug 5, 2024

Your build has completed!

Preview deployment

app/client/platforms/baidu.ts Outdated Show resolved Hide resolved
change the summary role from system to user
Copy link
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0e296a and 9ab45c3.

Files selected for processing (1)
  • app/client/platforms/baidu.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/platforms/baidu.ts

Copy link
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9ab45c3 and 0902efc.

Files selected for processing (1)
  • app/client/platforms/tencent.ts (1 hunks)
Additional comments not posted (1)
app/client/platforms/tencent.ts (1)

94-96: LGTM! Ensure the new role assignment logic is correct.

The code changes are approved.

However, verify that the new logic for role assignment doesn't introduce any unexpected behavior.

Verification successful

The new role assignment logic is correct and does not introduce any issues.

The logic ensures that the "system" role is always the first message in the list, and subsequent "system" roles are changed to "user". This is consistent with the intended behavior.

  • The chat method correctly assigns roles to messages based on their position in the list.
  • The logic does not introduce any unexpected behavior.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new role assignment logic in the `chat` method.

# Test: Search for the method implementation. Expect: Only the new logic for role assignment.
ast-grep --lang typescript --pattern $'class HunyuanApi {
  $$$
  async chat($_) {
    $$$
    const messages = $_.map((v, index) => ({
      role: index !== 0 && v.role === "system" ? "user" : v.role,
      content: $_ ? v.content : $_,
    }));
    $$$
  }
  $$$
}'

Length of output: 268


Script:

#!/bin/bash
# Description: Verify the new role assignment logic in the `chat` method.

# Search for the `chat` method in the `app/client/platforms/tencent.ts` file and include context lines.
rg 'async chat' -A 10 app/client/platforms/tencent.ts

Length of output: 537

@lloydzhou lloydzhou merged commit 6905421 into ChatGPTNextWeb:main Aug 6, 2024
1 of 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.

3 participants