mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
On xAI upstreams a custom_tool_call whose call_id starts with xs_ or as_ is an xAI server-side search call, as the xAI tool usage docs define the prefixes. The Messages and Chat Completions stream converters and the buffered accumulator no longer return such items as tool_use or tool calls, and stop_reason and finish_reason follow the remaining content. Grok SearchCount counts each such item once; client custom tools and non-xAI upstreams are unchanged.
31 lines
930 B
Go
31 lines
930 B
Go
package apicompat
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestIsServerSideSearchCall(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
itemType string
|
|
callID string
|
|
want bool
|
|
}{
|
|
{"x search", "custom_tool_call", "xs_123", true},
|
|
{"attachment search", "custom_tool_call", "as_456", true},
|
|
{"padded call id is not a prefix match", "custom_tool_call", " xs_123", false},
|
|
{"client custom tool", "custom_tool_call", "call_9", false},
|
|
{"prefix is not a substring", "custom_tool_call", "call_xs_9", false},
|
|
{"no call id", "custom_tool_call", "", false},
|
|
{"function call keeps its client meaning", "function_call", "xs_123", false},
|
|
{"other server-side item types are separate items", "x_search_call", "xs_123", false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
require.Equal(t, tt.want, IsServerSideSearchCall(tt.itemType, tt.callID))
|
|
})
|
|
}
|
|
}
|