feat(tests): add unit tests for Langfuse wrapper functions
- Introduced a new test file for the Langfuse wrapper, implementing tests for the `buildLangfuseGenerationOutput` and `buildLangfuseMessages` functions. - Validated the output structure for various scenarios, ensuring correct handling of content, tool calls, finish reasons, and reasoning content. - Enhanced test coverage for the Langfuse functionality, improving reliability and maintainability of the codebase.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func TestBuildLangfuseGenerationOutput(t *testing.T) {
|
||||
toolCalls := []types.LLMToolCall{{ID: "call_1", Type: "function"}}
|
||||
|
||||
got := buildLangfuseGenerationOutput("", "", "tool_calls", toolCalls)
|
||||
want := map[string]interface{}{
|
||||
"content": "",
|
||||
"tool_calls": toolCalls,
|
||||
"finish_reason": "tool_calls",
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("output without reasoning = %#v; want %#v", got, want)
|
||||
}
|
||||
|
||||
got = buildLangfuseGenerationOutput("answer", "thinking", "stop", nil)
|
||||
want = map[string]interface{}{
|
||||
"content": "answer",
|
||||
"tool_calls": []types.LLMToolCall(nil),
|
||||
"finish_reason": "stop",
|
||||
"reasoning_content": "thinking",
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("output with reasoning = %#v; want %#v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildLangfuseMessagesReasoningContent(t *testing.T) {
|
||||
msgs := buildLangfuseMessages([]Message{
|
||||
{Role: "assistant", ReasoningContent: "chain of thought", ToolCalls: []ToolCall{{ID: "tc1"}}},
|
||||
})
|
||||
if len(msgs) != 1 {
|
||||
t.Fatalf("len(messages) = %d; want 1", len(msgs))
|
||||
}
|
||||
if msgs[0]["reasoning_content"] != "chain of thought" {
|
||||
t.Fatalf("reasoning_content = %v; want chain of thought", msgs[0]["reasoning_content"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user