446f865cdf
- Implemented KnowledgeHandler for managing knowledge groups and items, including listing, creating, updating, and deleting operations. - Added database migration scripts to create necessary tables for knowledge management, including knowledge_groups, knowledge_items, knowledge_parse_tasks, and knowledge_chunks_meta. - Introduced prompt_rule_knowledge_groups table to associate prompt rules with knowledge groups.
103 lines
2.5 KiB
Go
103 lines
2.5 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadPrefersEnvLLMAPIKey(t *testing.T) {
|
|
t.Setenv("LLM_API_KEY", "env-priority-key")
|
|
|
|
configPath := writeTestConfig(t, `
|
|
llm:
|
|
provider: ark
|
|
api_key: "config-file-key"
|
|
`)
|
|
|
|
cfg, err := Load(configPath)
|
|
if err != nil {
|
|
t.Fatalf("Load() error = %v", err)
|
|
}
|
|
|
|
if cfg.LLM.APIKey != "env-priority-key" {
|
|
t.Fatalf("expected env api key, got %q", cfg.LLM.APIKey)
|
|
}
|
|
}
|
|
|
|
func TestLoadFallsBackToConfigLLMAPIKey(t *testing.T) {
|
|
t.Setenv("LLM_API_KEY", "")
|
|
|
|
configPath := writeTestConfig(t, `
|
|
llm:
|
|
provider: ark
|
|
api_key: "config-file-key"
|
|
`)
|
|
|
|
cfg, err := Load(configPath)
|
|
if err != nil {
|
|
t.Fatalf("Load() error = %v", err)
|
|
}
|
|
|
|
if cfg.LLM.APIKey != "config-file-key" {
|
|
t.Fatalf("expected config api key, got %q", cfg.LLM.APIKey)
|
|
}
|
|
}
|
|
|
|
func TestLoadPrefersEnvRetrievalAndQdrantSettings(t *testing.T) {
|
|
t.Setenv("SILICONFLOW_API_KEY", "siliconflow-env-key")
|
|
t.Setenv("SILICONFLOW_EMBEDDING_MODEL", "env-embedding")
|
|
t.Setenv("SILICONFLOW_RERANKER_MODEL", "env-reranker")
|
|
t.Setenv("QDRANT_API_KEY", "qdrant-env-key")
|
|
t.Setenv("QDRANT_URL", "qdrant-env:6334")
|
|
t.Setenv("QDRANT_COLLECTION", "env_collection")
|
|
|
|
configPath := writeTestConfig(t, `
|
|
qdrant:
|
|
url: qdrant-config:6334
|
|
api_key: "qdrant-config-key"
|
|
collection: "config_collection"
|
|
retrieval:
|
|
provider: siliconflow
|
|
api_key: "retrieval-config-key"
|
|
embedding_model: "config-embedding"
|
|
reranker_model: "config-reranker"
|
|
`)
|
|
|
|
cfg, err := Load(configPath)
|
|
if err != nil {
|
|
t.Fatalf("Load() error = %v", err)
|
|
}
|
|
|
|
if cfg.Retrieval.APIKey != "siliconflow-env-key" {
|
|
t.Fatalf("expected env retrieval api key, got %q", cfg.Retrieval.APIKey)
|
|
}
|
|
if cfg.Retrieval.EmbeddingModel != "env-embedding" {
|
|
t.Fatalf("expected env embedding model, got %q", cfg.Retrieval.EmbeddingModel)
|
|
}
|
|
if cfg.Retrieval.RerankerModel != "env-reranker" {
|
|
t.Fatalf("expected env reranker model, got %q", cfg.Retrieval.RerankerModel)
|
|
}
|
|
if cfg.Qdrant.APIKey != "qdrant-env-key" {
|
|
t.Fatalf("expected env qdrant api key, got %q", cfg.Qdrant.APIKey)
|
|
}
|
|
if cfg.Qdrant.URL != "qdrant-env:6334" {
|
|
t.Fatalf("expected env qdrant url, got %q", cfg.Qdrant.URL)
|
|
}
|
|
if cfg.Qdrant.Collection != "env_collection" {
|
|
t.Fatalf("expected env qdrant collection, got %q", cfg.Qdrant.Collection)
|
|
}
|
|
}
|
|
|
|
func writeTestConfig(t *testing.T, body string) string {
|
|
t.Helper()
|
|
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "config.yaml")
|
|
if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
|
|
t.Fatalf("write config: %v", err)
|
|
}
|
|
|
|
return path
|
|
}
|