-
Notifications
You must be signed in to change notification settings - Fork 3
Strip chat command prefixes from model input context #704
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
Conversation
Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
|
@copilot 单元测试不够全面,至少还应该包含两种情况:
|
|
@copilot 重试 |
|
@copilot 重试 |
|
@copilot 再重试 |
Co-authored-by: hugefiver <18693500+hugefiver@users.noreply.github.com>
There was a problem hiding this 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 != niltoif err == nil) - Refactored input extraction into a dedicated
extractInputFromMessagefunction 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 |
| 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) | ||
| }) | ||
| } | ||
| } |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
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:
- Messages with Caption instead of Text (e.g., photo captions)
- Empty trigger command (trigger.Command == "")
- Command with no arguments (e.g., just "/think" without any text after)
- Empty message text and caption
These edge cases would ensure the function handles all scenarios robustly.
The model was receiving the raw
/think …command text as context, causing it to interpret the command instead of the user’s question.extractInputFromMessage, removing the command prefix (e.g.,/think) before passing text to the model context./think@bot) and plain messages without a command prefix.Example:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.