Chore: tests update
This commit is contained in:
@@ -11,6 +11,9 @@ import (
|
||||
func TestParserToolDetection(t *testing.T) {
|
||||
// Create a logger for testing
|
||||
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||
|
||||
// Create a default config for testing
|
||||
cfg := config.LoadConfigOrDefault("")
|
||||
|
||||
// Test cases with different response types
|
||||
testCases := []struct {
|
||||
@@ -24,16 +27,22 @@ func TestParserToolDetection(t *testing.T) {
|
||||
name: "RegularTextResponse",
|
||||
responseJSON: `{
|
||||
"id": "test-id",
|
||||
"object": "text.completion",
|
||||
"object": "text_completion",
|
||||
"created": 1234567890,
|
||||
"model": "deepseek-chat",
|
||||
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||
"choices": [
|
||||
{
|
||||
"text": "The capital of France is Paris.",
|
||||
"index": 0,
|
||||
"logprobs": null,
|
||||
"finish_reason": "stop"
|
||||
}
|
||||
]
|
||||
],
|
||||
"usage": {
|
||||
"prompt_tokens": 10,
|
||||
"completion_tokens": 5,
|
||||
"total_tokens": 15
|
||||
}
|
||||
}`,
|
||||
expectedOutput: "The capital of France is Paris.",
|
||||
isToolCall: false,
|
||||
@@ -44,7 +53,7 @@ func TestParserToolDetection(t *testing.T) {
|
||||
"id": "test-id",
|
||||
"object": "chat.completion",
|
||||
"created": 1234567890,
|
||||
"model": "deepseek-chat",
|
||||
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||
"choices": [
|
||||
{
|
||||
"index": 0,
|
||||
@@ -76,7 +85,7 @@ func TestParserToolDetection(t *testing.T) {
|
||||
"id": "test-id",
|
||||
"object": "chat.completion",
|
||||
"created": 1234567890,
|
||||
"model": "deepseek-chat",
|
||||
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||
"choices": [
|
||||
{
|
||||
"index": 0,
|
||||
@@ -95,7 +104,7 @@ func TestParserToolDetection(t *testing.T) {
|
||||
|
||||
// Test DeepSeekParser
|
||||
t.Run("DeepSeekParser", func(t *testing.T) {
|
||||
parser := NewDeepSeekParser(logger, config.LoadConfigOrDefault("config.toml"))
|
||||
parser := NewDeepSeekParser(logger, cfg)
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -113,9 +122,60 @@ func TestParserToolDetection(t *testing.T) {
|
||||
|
||||
// Test OpenRouterParser
|
||||
t.Run("OpenRouterParser", func(t *testing.T) {
|
||||
parser := NewOpenRouterParser(logger, config.LoadConfigOrDefault("config.toml"))
|
||||
// Test RegularTextResponse with completion API
|
||||
t.Run("RegularTextResponse", func(t *testing.T) {
|
||||
parser := NewOpenRouterParser(logger, cfg)
|
||||
parser.useChatAPI = false // Use completion API for this test
|
||||
|
||||
tc := struct {
|
||||
name string
|
||||
responseJSON string
|
||||
expectedOutput string
|
||||
isToolCall bool
|
||||
expectedTool string
|
||||
}{
|
||||
name: "RegularTextResponse",
|
||||
responseJSON: `{
|
||||
"id": "test-id",
|
||||
"object": "text_completion",
|
||||
"created": 1234567890,
|
||||
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||
"choices": [
|
||||
{
|
||||
"text": "The capital of France is Paris.",
|
||||
"index": 0,
|
||||
"logprobs": null,
|
||||
"finish_reason": "stop"
|
||||
}
|
||||
],
|
||||
"usage": {
|
||||
"prompt_tokens": 10,
|
||||
"completion_tokens": 5,
|
||||
"total_tokens": 15
|
||||
}
|
||||
}`,
|
||||
expectedOutput: "The capital of France is Paris.",
|
||||
isToolCall: false,
|
||||
}
|
||||
|
||||
result, err := parser.ParseBytes([]byte(tc.responseJSON))
|
||||
if err != nil {
|
||||
t.Errorf("ParseBytes returned an error: %v", err)
|
||||
}
|
||||
|
||||
if result != tc.expectedOutput {
|
||||
t.Errorf("Expected %s, got %s", tc.expectedOutput, result)
|
||||
}
|
||||
})
|
||||
|
||||
// Test ToolCallResponse and RegularMessageResponse with chat API
|
||||
parser := NewOpenRouterParser(logger, cfg)
|
||||
parser.useChatAPI = true // Use chat API for these tests
|
||||
|
||||
for _, tc := range testCases {
|
||||
if tc.name == "RegularTextResponse" {
|
||||
continue // Skip this one as we tested it above
|
||||
}
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result, err := parser.ParseBytes([]byte(tc.responseJSON))
|
||||
if err != nil {
|
||||
@@ -128,5 +188,4 @@ func TestParserToolDetection(t *testing.T) {
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user