test: Phase 6 全功能测试 — 19个测试全部通过 + 开发路线文档
- host: 沙箱执行/命令拦截/超时/文件读写/系统信息/路径验证 (6 tests) - rag: 文本分块/余弦相似度/关键词匹配/文档索引+搜索 (4 tests) - tools: host_exec/host_file/host_system/knowledge_search/knowledge_ingest (5 tests) - vision: 图片编码/错误处理/定义验证/执行流程 (4 tests) - Embedder 重构为接口,支持 API 和 Simple 两种实现 - 添加 ROADMAP.md 未来开发路线 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -10,8 +10,15 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Embedder creates text embeddings using an LLM API.
|
||||
type Embedder struct {
|
||||
// Embedder is the interface for text embedding.
|
||||
type Embedder interface {
|
||||
Embed(ctx context.Context, text string) ([]float64, error)
|
||||
EmbedBatch(ctx context.Context, texts []string) ([]float64, error)
|
||||
IsAvailable() bool
|
||||
}
|
||||
|
||||
// APIEmbedder creates text embeddings using an LLM API.
|
||||
type APIEmbedder struct {
|
||||
baseURL string
|
||||
apiKey string
|
||||
model string
|
||||
@@ -19,8 +26,8 @@ type Embedder struct {
|
||||
}
|
||||
|
||||
// NewEmbedder creates a new embedding service.
|
||||
func NewEmbedder(baseURL, apiKey, model string) *Embedder {
|
||||
return &Embedder{
|
||||
func NewEmbedder(baseURL, apiKey, model string) *APIEmbedder {
|
||||
return &APIEmbedder{
|
||||
baseURL: baseURL,
|
||||
apiKey: apiKey,
|
||||
model: model,
|
||||
@@ -58,12 +65,12 @@ type embeddingError struct {
|
||||
}
|
||||
|
||||
// Embed generates an embedding vector for the given text.
|
||||
func (e *Embedder) Embed(ctx context.Context, text string) ([]float64, error) {
|
||||
func (e *APIEmbedder) Embed(ctx context.Context, text string) ([]float64, error) {
|
||||
return e.EmbedBatch(ctx, []string{text})
|
||||
}
|
||||
|
||||
// EmbedBatch generates embeddings for multiple texts.
|
||||
func (e *Embedder) EmbedBatch(ctx context.Context, texts []string) ([]float64, error) {
|
||||
func (e *APIEmbedder) EmbedBatch(ctx context.Context, texts []string) ([]float64, error) {
|
||||
if !e.IsAvailable() {
|
||||
return nil, fmt.Errorf("embedding service not available: no API key configured")
|
||||
}
|
||||
@@ -113,6 +120,6 @@ func (e *Embedder) EmbedBatch(ctx context.Context, texts []string) ([]float64, e
|
||||
}
|
||||
|
||||
// IsAvailable checks if the embedding service is configured.
|
||||
func (e *Embedder) IsAvailable() bool {
|
||||
func (e *APIEmbedder) IsAvailable() bool {
|
||||
return e.apiKey != "" && e.baseURL != ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user