Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
39 lines
1.7 KiB
Go
39 lines
1.7 KiB
Go
package openai
|
|
|
|
import (
|
|
"testing"
|
|
|
|
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestObserveStreamChoicesDedupesFunctionCallNames(t *testing.T) {
|
|
info := &relaycommon.RelayInfo{StreamStatus: relaycommon.NewStreamStatus()}
|
|
seen := make(map[string]struct{})
|
|
var names []string
|
|
|
|
chunks := []string{
|
|
`{"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"c1","type":"function","function":{"name":"get_weather","arguments":""}}]}}]}`,
|
|
`{"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\"q\":"}}]}}]}`,
|
|
`{"choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"\"x\"}"}}]}}]}`,
|
|
`{"choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"id":"c2","type":"function","function":{"name":"get_time","arguments":""}}]}}]}`,
|
|
`{"choices":[{"index":0,"delta":{"tool_calls":[{"index":1,"function":{"arguments":"{}"}}]}}]}`,
|
|
}
|
|
for _, chunk := range chunks {
|
|
observeStreamChoices(info, chunk, seen, &names)
|
|
}
|
|
|
|
require.Len(t, names, 2)
|
|
assert.Equal(t, []string{"get_weather", "get_time"}, names)
|
|
assert.Empty(t, info.StreamStatus.ResponseOutcome(), "tool call deltas carry no finish reason")
|
|
|
|
observeStreamChoices(info, `{"choices":[{"index":0,"delta":{},"finish_reason":"tool_calls"}]}`, seen, &names)
|
|
assert.Equal(t, "completed", info.StreamStatus.ResponseOutcome())
|
|
assert.False(t, info.PerformanceBusinessRejection)
|
|
|
|
filtered := &relaycommon.RelayInfo{StreamStatus: relaycommon.NewStreamStatus()}
|
|
observeStreamChoices(filtered, `{"choices":[{"index":0,"delta":{},"finish_reason":"content_filter"}]}`, map[string]struct{}{}, &names)
|
|
assert.True(t, filtered.PerformanceBusinessRejection)
|
|
}
|