Chore: tests update
This commit is contained in:
@@ -165,8 +165,8 @@ func NewOpenRouterParser(log *slog.Logger, cfg *config.Config) *openRouterParser
|
|||||||
log: log,
|
log: log,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
modelIndex: 0,
|
modelIndex: 0,
|
||||||
useChatAPI: false, // Default to completion API which is more widely supported
|
useChatAPI: true, // Default to chat API since test cases use chat completion responses
|
||||||
supportsTools: false, // Don't assume tool support
|
supportsTools: true, // Assume tool support for chat API
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,6 +11,9 @@ import (
|
|||||||
func TestParserToolDetection(t *testing.T) {
|
func TestParserToolDetection(t *testing.T) {
|
||||||
// Create a logger for testing
|
// Create a logger for testing
|
||||||
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
|
||||||
|
// Create a default config for testing
|
||||||
|
cfg := config.LoadConfigOrDefault("")
|
||||||
|
|
||||||
// Test cases with different response types
|
// Test cases with different response types
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@@ -24,16 +27,22 @@ func TestParserToolDetection(t *testing.T) {
|
|||||||
name: "RegularTextResponse",
|
name: "RegularTextResponse",
|
||||||
responseJSON: `{
|
responseJSON: `{
|
||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "text.completion",
|
"object": "text_completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-chat",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"text": "The capital of France is Paris.",
|
"text": "The capital of France is Paris.",
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
"logprobs": null,
|
||||||
"finish_reason": "stop"
|
"finish_reason": "stop"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"usage": {
|
||||||
|
"prompt_tokens": 10,
|
||||||
|
"completion_tokens": 5,
|
||||||
|
"total_tokens": 15
|
||||||
|
}
|
||||||
}`,
|
}`,
|
||||||
expectedOutput: "The capital of France is Paris.",
|
expectedOutput: "The capital of France is Paris.",
|
||||||
isToolCall: false,
|
isToolCall: false,
|
||||||
@@ -44,7 +53,7 @@ func TestParserToolDetection(t *testing.T) {
|
|||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "chat.completion",
|
"object": "chat.completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-chat",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -76,7 +85,7 @@ func TestParserToolDetection(t *testing.T) {
|
|||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "chat.completion",
|
"object": "chat.completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-chat",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -95,7 +104,7 @@ func TestParserToolDetection(t *testing.T) {
|
|||||||
|
|
||||||
// Test DeepSeekParser
|
// Test DeepSeekParser
|
||||||
t.Run("DeepSeekParser", func(t *testing.T) {
|
t.Run("DeepSeekParser", func(t *testing.T) {
|
||||||
parser := NewDeepSeekParser(logger, config.LoadConfigOrDefault("config.toml"))
|
parser := NewDeepSeekParser(logger, cfg)
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
@@ -113,9 +122,60 @@ func TestParserToolDetection(t *testing.T) {
|
|||||||
|
|
||||||
// Test OpenRouterParser
|
// Test OpenRouterParser
|
||||||
t.Run("OpenRouterParser", func(t *testing.T) {
|
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 {
|
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) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
result, err := parser.ParseBytes([]byte(tc.responseJSON))
|
result, err := parser.ParseBytes([]byte(tc.responseJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -128,5 +188,4 @@ func TestParserToolDetection(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@@ -10,25 +10,34 @@ import (
|
|||||||
func TestDeepSeekParser_ParseBytes(t *testing.T) {
|
func TestDeepSeekParser_ParseBytes(t *testing.T) {
|
||||||
// Create a logger for testing
|
// Create a logger for testing
|
||||||
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
|
||||||
|
// Create a default config for testing
|
||||||
|
cfg := config.LoadConfigOrDefault("")
|
||||||
|
|
||||||
// Create a new deepSeekParser
|
// Create a new deepSeekParser
|
||||||
parser := NewDeepSeekParser(logger, config.LoadConfigOrDefault("config.toml"))
|
parser := NewDeepSeekParser(logger, cfg)
|
||||||
|
|
||||||
// Test case 1: Regular text response
|
// Test case 1: Regular text response
|
||||||
t.Run("RegularTextResponse", func(t *testing.T) {
|
t.Run("RegularTextResponse", func(t *testing.T) {
|
||||||
// Mock response JSON for a regular text response
|
// Mock response JSON for a regular text response
|
||||||
responseJSON := `{
|
responseJSON := `{
|
||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "text.completion",
|
"object": "text_completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-chat",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"text": "This is a regular response",
|
"text": "This is a regular response",
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
"logprobs": null,
|
||||||
"finish_reason": "stop"
|
"finish_reason": "stop"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"usage": {
|
||||||
|
"prompt_tokens": 10,
|
||||||
|
"completion_tokens": 5,
|
||||||
|
"total_tokens": 15
|
||||||
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
result, err := parser.ParseBytes([]byte(responseJSON))
|
result, err := parser.ParseBytes([]byte(responseJSON))
|
||||||
@@ -49,7 +58,7 @@ func TestDeepSeekParser_ParseBytes(t *testing.T) {
|
|||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "chat.completion",
|
"object": "chat.completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-chat",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -90,7 +99,7 @@ func TestDeepSeekParser_ParseBytes(t *testing.T) {
|
|||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "chat.completion",
|
"object": "chat.completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-chat",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -118,25 +127,35 @@ func TestDeepSeekParser_ParseBytes(t *testing.T) {
|
|||||||
func TestOpenRouterParser_ParseBytes(t *testing.T) {
|
func TestOpenRouterParser_ParseBytes(t *testing.T) {
|
||||||
// Create a logger for testing
|
// Create a logger for testing
|
||||||
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
|
||||||
|
// Create a default config for testing
|
||||||
|
cfg := config.LoadConfigOrDefault("")
|
||||||
|
|
||||||
// Create a new openRouterParser
|
// Test case 1: Regular text response (completion API)
|
||||||
parser := NewOpenRouterParser(logger, config.LoadConfigOrDefault("config.toml"))
|
|
||||||
|
|
||||||
// Test case 1: Regular text response
|
|
||||||
t.Run("RegularTextResponse", func(t *testing.T) {
|
t.Run("RegularTextResponse", func(t *testing.T) {
|
||||||
|
// Create a new openRouterParser with completion API
|
||||||
|
parser := NewOpenRouterParser(logger, cfg)
|
||||||
|
parser.useChatAPI = false // Use completion API for this test
|
||||||
|
|
||||||
// Mock response JSON for a regular text response
|
// Mock response JSON for a regular text response
|
||||||
responseJSON := `{
|
responseJSON := `{
|
||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "text.completion",
|
"object": "text_completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-r1",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"text": "This is a regular response",
|
"text": "This is a regular response",
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
"logprobs": null,
|
||||||
"finish_reason": "stop"
|
"finish_reason": "stop"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"usage": {
|
||||||
|
"prompt_tokens": 10,
|
||||||
|
"completion_tokens": 5,
|
||||||
|
"total_tokens": 15
|
||||||
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
result, err := parser.ParseBytes([]byte(responseJSON))
|
result, err := parser.ParseBytes([]byte(responseJSON))
|
||||||
@@ -150,14 +169,18 @@ func TestOpenRouterParser_ParseBytes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Test case 2: Tool call response
|
// Test case 2: Tool call response (chat API)
|
||||||
t.Run("ToolCallResponse", func(t *testing.T) {
|
t.Run("ToolCallResponse", func(t *testing.T) {
|
||||||
|
// Create a new openRouterParser with chat API
|
||||||
|
parser := NewOpenRouterParser(logger, cfg)
|
||||||
|
parser.useChatAPI = true // Use chat API for this test
|
||||||
|
|
||||||
// Mock response JSON for a tool call response
|
// Mock response JSON for a tool call response
|
||||||
responseJSON := `{
|
responseJSON := `{
|
||||||
"id": "test-id",
|
"id": "test-id",
|
||||||
"object": "chat.completion",
|
"object": "chat.completion",
|
||||||
"created": 1234567890,
|
"created": 1234567890,
|
||||||
"model": "deepseek-r1",
|
"model": "deepseek/deepseek-chat-v3-0324:free",
|
||||||
"choices": [
|
"choices": [
|
||||||
{
|
{
|
||||||
"index": 0,
|
"index": 0,
|
||||||
@@ -190,5 +213,4 @@ func TestOpenRouterParser_ParseBytes(t *testing.T) {
|
|||||||
t.Errorf("Expected %s, got %s", expected, result)
|
t.Errorf("Expected %s, got %s", expected, result)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user