Files
ai_academy/internal/handler/initialization_extract_relations_test.go
T
runny 7ec21f35b0 chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
2026-11-16 18:12:23 +08:00

41 lines
1.3 KiB
Go

package handler
import (
"context"
"errors"
"testing"
"academy/internal/config"
"academy/internal/models/chat"
"academy/internal/types"
)
type proseReplyChat struct{}
func (proseReplyChat) Chat(context.Context, []chat.Message, *chat.ChatOptions) (*types.ChatResponse, error) {
return &types.ChatResponse{Content: "抱歉,这段文本没有可抽取的实体和关系。", FinishReason: "stop"}, nil
}
func (proseReplyChat) ChatStream(
context.Context, []chat.Message, *chat.ChatOptions,
) (<-chan types.StreamResponse, error) {
return nil, errors.New("not implemented")
}
func (proseReplyChat) GetModelName() string { return "prose" }
func (proseReplyChat) GetModelID() string { return "prose" }
// The graph-settings "try extract" button must report a prose refusal as a
// failure. Returning an empty graph would make the UI clear the user's
// few-shot nodes/relations and show "success" (#3606 review).
func TestExtractRelationsFromTextReportsModelRefusal(t *testing.T) {
h := &InitializationHandler{config: &config.Config{
ExtractManager: &config.ExtractManagerConfig{
ExtractGraph: &types.PromptTemplateStructured{Description: "extract"},
},
}}
res, err := h.extractRelationsFromText(context.Background(), "目录", nil, proseReplyChat{})
if err == nil {
t.Fatalf("expected an error for a prose refusal, got %+v", res)
}
}