WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/event"
|
||||
"github.com/Tencent/WeKnora/internal/models/asr"
|
||||
"github.com/Tencent/WeKnora/internal/models/chat"
|
||||
"github.com/Tencent/WeKnora/internal/models/embedding"
|
||||
"github.com/Tencent/WeKnora/internal/models/rerank"
|
||||
"github.com/Tencent/WeKnora/internal/models/vlm"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type captureChatModel struct {
|
||||
lastMessages []chat.Message
|
||||
}
|
||||
|
||||
func (m *captureChatModel) Chat(
|
||||
context.Context,
|
||||
[]chat.Message,
|
||||
*chat.ChatOptions,
|
||||
) (*types.ChatResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *captureChatModel) ChatStream(
|
||||
_ context.Context,
|
||||
messages []chat.Message,
|
||||
_ *chat.ChatOptions,
|
||||
) (<-chan types.StreamResponse, error) {
|
||||
m.lastMessages = append([]chat.Message(nil), messages...)
|
||||
|
||||
ch := make(chan types.StreamResponse, 1)
|
||||
ch <- types.StreamResponse{
|
||||
ResponseType: types.ResponseTypeAnswer,
|
||||
Content: "ok",
|
||||
Done: true,
|
||||
}
|
||||
close(ch)
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (m *captureChatModel) GetModelName() string { return "capture" }
|
||||
func (m *captureChatModel) GetModelID() string { return "capture" }
|
||||
|
||||
type stubModelService struct {
|
||||
chatModel chat.Chat
|
||||
modelsByID map[string]*types.Model
|
||||
availableModels []*types.Model
|
||||
}
|
||||
|
||||
func TestEmitKnowledgeReferencesEventIgnoresCitationOutputSetting(t *testing.T) {
|
||||
bus := event.NewEventBus()
|
||||
var emitted []event.Event
|
||||
bus.On(event.EventAgentReferences, func(_ context.Context, evt event.Event) error {
|
||||
emitted = append(emitted, evt)
|
||||
return nil
|
||||
})
|
||||
disabled := false
|
||||
result := &types.SearchResult{ID: "chunk-1", KnowledgeTitle: "Doc"}
|
||||
cm := &types.ChatManage{
|
||||
PipelineRequest: types.PipelineRequest{CitationEnabled: &disabled},
|
||||
PipelineState: types.PipelineState{
|
||||
MergeResult: []*types.SearchResult{result},
|
||||
},
|
||||
PipelineContext: types.PipelineContext{EventBus: bus.AsEventBusInterface()},
|
||||
}
|
||||
|
||||
emitKnowledgeReferencesEvent(context.Background(), cm)
|
||||
require.Len(t, emitted, 1)
|
||||
require.Equal(t, event.EventAgentReferences, emitted[0].Type)
|
||||
require.Equal(t, []*types.SearchResult{result}, emitted[0].Data.(event.AgentReferencesData).References)
|
||||
|
||||
enabled := true
|
||||
cm.CitationEnabled = &enabled
|
||||
emitKnowledgeReferencesEvent(context.Background(), cm)
|
||||
require.Len(t, emitted, 2)
|
||||
}
|
||||
|
||||
func (s *stubModelService) CreateModel(context.Context, *types.Model) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) GetModelByID(_ context.Context, id string) (*types.Model, error) {
|
||||
return s.modelsByID[id], nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) ListModels(context.Context) ([]*types.Model, error) {
|
||||
return s.availableModels, nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) UpdateModel(context.Context, *types.Model) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) DeleteModel(context.Context, string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) UpdateModelCredentials(
|
||||
context.Context, string, *string, *string,
|
||||
) (*types.Model, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) ClearModelCredential(context.Context, string, string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) GetEmbeddingModel(context.Context, string) (embedding.Embedder, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) GetEmbeddingModelForTenant(context.Context, string, uint64) (embedding.Embedder, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) GetRerankModel(context.Context, string) (rerank.Reranker, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) GetChatModel(context.Context, string) (chat.Chat, error) {
|
||||
return s.chatModel, nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) GetVLMModel(context.Context, string) (vlm.VLM, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *stubModelService) GetASRModel(context.Context, string) (asr.ASR, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func TestHandleModelFallback_IncludesHistoryMessages(t *testing.T) {
|
||||
chatModel := &captureChatModel{}
|
||||
svc := &sessionService{
|
||||
modelService: &stubModelService{chatModel: chatModel},
|
||||
}
|
||||
|
||||
bus := event.NewEventBus()
|
||||
cm := &types.ChatManage{
|
||||
PipelineRequest: types.PipelineRequest{
|
||||
SessionID: "session-1",
|
||||
Query: "现在还能继续讲吗?",
|
||||
ChatModelID: "chat-model",
|
||||
FallbackPrompt: "Answer the latest user question: {{query}}",
|
||||
SummaryConfig: types.SummaryConfig{
|
||||
Temperature: 0.2,
|
||||
},
|
||||
Language: "zh-CN",
|
||||
},
|
||||
PipelineState: types.PipelineState{
|
||||
History: []*types.History{
|
||||
{
|
||||
Query: "先介绍一下 WeKnora",
|
||||
Answer: "WeKnora 是一个知识库问答系统。",
|
||||
},
|
||||
},
|
||||
},
|
||||
PipelineContext: types.PipelineContext{
|
||||
EventBus: bus.AsEventBusInterface(),
|
||||
},
|
||||
}
|
||||
|
||||
svc.handleModelFallback(context.Background(), cm)
|
||||
|
||||
// Corrected fallback shape: a system message carries the fallback
|
||||
// instruction, history is replayed in the middle, and the turn ends on the
|
||||
// user's question. Previously the system message was dropped entirely.
|
||||
require.Len(t, chatModel.lastMessages, 4)
|
||||
assert.Equal(t, "system", chatModel.lastMessages[0].Role)
|
||||
assert.Contains(t, chatModel.lastMessages[0].Content, "Answer the latest user question")
|
||||
assert.Equal(t, "user", chatModel.lastMessages[1].Role)
|
||||
assert.Equal(t, "先介绍一下 WeKnora", chatModel.lastMessages[1].Content)
|
||||
assert.Equal(t, "assistant", chatModel.lastMessages[2].Role)
|
||||
assert.Equal(t, "WeKnora 是一个知识库问答系统。", chatModel.lastMessages[2].Content)
|
||||
assert.Equal(t, "user", chatModel.lastMessages[3].Role)
|
||||
assert.Contains(t, chatModel.lastMessages[3].Content, "现在还能继续讲吗?")
|
||||
}
|
||||
Reference in New Issue
Block a user