Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

The model was receiving the raw /think … command text as context, causing it to interpret the command instead of the user’s question.

  • Input handling
    • Centralized input extraction in extractInputFromMessage, removing the command prefix (e.g., /think) before passing text to the model context.
  • Tests
    • Added focused tests ensuring command text is stripped when a trigger command is present, including bot-mention forms (/think@bot) and plain messages without a command prefix.

Example:

trigger := &config.ChatTrigger{Command: "think"}
msg := &tb.Message{Text: "/think hello world"}

extractInputFromMessage(msg, trigger) // "hello world"
Original prompt

This section details on the original issue you should resolve

<issue_title>给大模型的上下文里面把命令部分去掉</issue_title>
<issue_description>> /think 是否任意实数都能使用对n求和 x^n, n为任意整数包括负数 的形式表示

如上,调用大模型的时候 /think 命令会代入上下文,导致大模型理解错误,返回下面这种内容:

我目前没有执行指令的权限,也无法处理 /think 这类命令。如果你有任何数学问题、需要解释或推导,请直接告诉我,我会尽力为你解答!</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove command part from context for large model Strip chat command prefixes from model input context Jan 14, 2026
Copilot AI requested a review from hugefiver January 14, 2026 04:09
@icceey
Copy link
Contributor

icceey commented Jan 14, 2026

@copilot 单元测试不够全面,至少还应该包含两种情况:

  • 指向型命令/think@bot
  • 纯消息没有命令前缀

@icceey
Copy link
Contributor

icceey commented Jan 14, 2026

@copilot 重试

@hugefiver
Copy link
Collaborator

@copilot 重试

@hugefiver hugefiver changed the base branch from master to dev January 14, 2026 04:35
@icceey
Copy link
Contributor

icceey commented Jan 14, 2026

@copilot 再重试

Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 14, 2026

@copilot 重试

Added coverage for both cases and confirmed the command body is preserved when no prefix exists. Commit 3fe0139.

@hugefiver hugefiver marked this pull request as ready for review January 14, 2026 04:52
Copilot AI review requested due to automatic review settings January 14, 2026 04:52
@hugefiver
Copy link
Collaborator

@copilot 单元测试不够全面,至少还应该包含两种情况:

  • 指向型命令/think@bot
  • 纯消息没有命令前缀

@copilot

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug where chat command prefixes (like /think) were incorrectly included in the AI model's input context, causing the model to misinterpret commands instead of processing the actual user question.

Changes:

  • Fixed inverted error handling logic in command prefix stripping (changed if err != nil to if err == nil)
  • Refactored input extraction into a dedicated extractInputFromMessage function for better testability
  • Added comprehensive unit tests covering command stripping scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
chat/chat.go Fixed bug in command prefix stripping logic and extracted input handling into testable function
chat/chat_input_test.go Added unit tests verifying command prefixes are correctly stripped from model input

Comment on lines +12 to +42
func TestExtractInputFromMessage_RemovesCommandPrefix(t *testing.T) {
trigger := &config.ChatTrigger{Command: "think"}
tests := []struct {
name string
msg *tb.Message
want string
}{
{
name: "plain command prefix stripped",
msg: &tb.Message{Text: "/think hello world"},
want: "hello world",
},
{
name: "command with bot mention stripped",
msg: &tb.Message{Text: "/think@bot hello world"},
want: "hello world",
},
{
name: "no command prefix kept",
msg: &tb.Message{Text: "hello world"},
want: "hello world",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := extractInputFromMessage(tt.msg, trigger)
assert.Equal(t, tt.want, got)
})
}
}
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The test coverage could be more comprehensive. Consider adding test cases for:

  1. Messages with Caption instead of Text (e.g., photo captions)
  2. Empty trigger command (trigger.Command == "")
  3. Command with no arguments (e.g., just "/think" without any text after)
  4. Empty message text and caption

These edge cases would ensure the function handles all scenarios robustly.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Copilot AI commented Jan 14, 2026

@copilot 单元测试不够全面,至少还应该包含两种情况:

  • 指向型命令/think@bot
    ...

Covered both bot-mention and no-prefix inputs in tests; see commit 3fe0139.

@hugefiver hugefiver merged commit 1f98bde into dev Jan 14, 2026
16 of 17 checks passed
@hugefiver hugefiver deleted the copilot/remove-context-command-part branch January 14, 2026 05:04
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