mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-09-03 07:25:50 +08:00
test(cast): add new test for dropping multiple nil function call tool calls
- Introduced a new test case to verify that multiple nil FunctionCall tool calls are correctly removed from the message content, ensuring only relevant text parts are retained. - Removed the previous test file `newbodypair_reg_test.go` as its functionality is now covered in the updated test suite.
This commit is contained in:
@@ -3213,3 +3213,23 @@ func TestSanitizeToolCallArguments(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBodyPair_DropsMultipleNilFunctionCallToolCalls(t *testing.T) {
|
||||
aiMsg := &llms.MessageContent{
|
||||
Role: llms.ChatMessageTypeAI,
|
||||
Parts: []llms.ContentPart{
|
||||
llms.ToolCall{ID: "a", Type: "function", FunctionCall: nil},
|
||||
llms.ToolCall{ID: "b", Type: "function", FunctionCall: nil},
|
||||
llms.TextContent{Text: "keep me"},
|
||||
},
|
||||
}
|
||||
|
||||
NewBodyPair(aiMsg, nil)
|
||||
|
||||
assert.Len(t, aiMsg.Parts, 1, "both nil-FunctionCall tool calls should be removed, text kept")
|
||||
if assert.Len(t, aiMsg.Parts, 1) {
|
||||
txt, ok := aiMsg.Parts[0].(llms.TextContent)
|
||||
assert.True(t, ok, "surviving part should be the TextContent, got %T", aiMsg.Parts[0])
|
||||
assert.Equal(t, "keep me", txt.Text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/vxcontrol/langchaingo/llms"
|
||||
)
|
||||
|
||||
func TestNewBodyPair_DropsMultipleNilFunctionCallToolCalls(t *testing.T) {
|
||||
aiMsg := &llms.MessageContent{
|
||||
Role: llms.ChatMessageTypeAI,
|
||||
Parts: []llms.ContentPart{
|
||||
llms.ToolCall{ID: "a", Type: "function", FunctionCall: nil},
|
||||
llms.ToolCall{ID: "b", Type: "function", FunctionCall: nil},
|
||||
llms.TextContent{Text: "keep me"},
|
||||
},
|
||||
}
|
||||
|
||||
NewBodyPair(aiMsg, nil)
|
||||
|
||||
assert.Len(t, aiMsg.Parts, 1, "both nil-FunctionCall tool calls should be removed, text kept")
|
||||
if assert.Len(t, aiMsg.Parts, 1) {
|
||||
txt, ok := aiMsg.Parts[0].(llms.TextContent)
|
||||
assert.True(t, ok, "surviving part should be the TextContent, got %T", aiMsg.Parts[0])
|
||||
assert.Equal(t, "keep me", txt.Text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user