This commit is contained in:
@@ -20,7 +20,7 @@ func TestArkGeneratorProducesValidatedContent(t *testing.T) {
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body["model"] != "doubao-test" {
|
||||
t.Fatalf("request body=%v err=%v", body, err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"choices": []any{map[string]any{"message": map[string]any{"content": `{"summary":"谈到河边小学","open_topic":"下次可以聊聊同学","story_title":"河边小学的回忆","story_content":"小时候在河边小学读书。","fact_content":"曾在河边小学读书","confidence":0.82}`}}}})
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"choices": []any{map[string]any{"message": map[string]any{"content": `{"summary":"谈到河边小学","keywords":["河边小学","童年"],"open_topic":"下次可以聊聊同学","story_title":"河边小学的回忆","story_content":"小时候在河边小学读书。","fact_content":"曾在河边小学读书","confidence":0.82}`}}}})
|
||||
}))
|
||||
defer server.Close()
|
||||
generator, err := NewArkGenerator(server.URL+"/api/v3", "test-key", "doubao-test", time.Second)
|
||||
@@ -28,7 +28,7 @@ func TestArkGeneratorProducesValidatedContent(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := generator.Generate(context.Background(), GenerationInput{Content: "小时候在河边小学读书。"})
|
||||
if err != nil || result.ModelRef != "ark:doubao-test" || result.Confidence != 0.82 || !result.AllowStory {
|
||||
if err != nil || result.ModelRef != "ark:doubao-test" || result.Confidence != 0.82 || !result.AllowStory || len(result.Keywords) != 2 {
|
||||
t.Fatalf("result=%+v err=%v", result, err)
|
||||
}
|
||||
}
|
||||
@@ -47,3 +47,26 @@ func TestArkGeneratorRetriesTemporaryFailure(t *testing.T) {
|
||||
t.Fatalf("429 should be retryable: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeterministicGeneratorIncludesKeywords(t *testing.T) {
|
||||
result, err := (DeterministicGenerator{}).Generate(context.Background(), GenerationInput{Content: "小时候在河边小学读书,最喜欢和同学一起踢球。"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(result.Keywords) < 1 || len(result.Keywords) > 8 {
|
||||
t.Fatalf("keywords=%v", result.Keywords)
|
||||
}
|
||||
formatted := summaryWithKeywords(result.Summary, result.Keywords)
|
||||
if formatted == result.Summary {
|
||||
t.Fatalf("summary did not include keywords: %q", formatted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestedGenerationVersion(t *testing.T) {
|
||||
if got := requestedGenerationVersion(json.RawMessage(`{"generation_version":7}`)); got != 7 {
|
||||
t.Fatalf("generation version=%d", got)
|
||||
}
|
||||
if got := requestedGenerationVersion(json.RawMessage(`{}`)); got != 1 {
|
||||
t.Fatalf("default generation version=%d", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user