callEmbeddingAPI 调用embedding API (兼容旧接口)
(content string, channel *model.Channel, config *ChunkConfig, ctx *EmbeddingContext)
| 274 | |
| 275 | // callEmbeddingAPI 调用embedding API (兼容旧接口) |
| 276 | func (s *EmbeddingService) callEmbeddingAPI(content string, channel *model.Channel, config *ChunkConfig, ctx *EmbeddingContext) ([]float64, error) { |
| 277 | // 验证输入 |
| 278 | if channel == nil { |
| 279 | return nil, fmt.Errorf("渠道配置不能为空") |
| 280 | } |
| 281 | |
| 282 | if config == nil { |
| 283 | return nil, fmt.Errorf("配置不能为空") |
| 284 | } |
| 285 | |
| 286 | // 使用默认模型 |
| 287 | var modelName string |
| 288 | if config.EmbeddingModelName != nil && *config.EmbeddingModelName != "" { |
| 289 | modelName = *config.EmbeddingModelName |
| 290 | } else { |
| 291 | // 如果没有配置模型名称,使用默认模型(按渠道常量判断) |
| 292 | switch channel.Type { |
| 293 | case channeltype.OpenAI: |
| 294 | modelName = "text-embedding-3-small" |
| 295 | case channeltype.Azure: |
| 296 | modelName = "text-embedding-3-small" |
| 297 | case channeltype.Ali: // Qwen (百炼 compatible-mode) |
| 298 | modelName = "text-embedding-v4" |
| 299 | default: |
| 300 | modelName = "text-embedding-3-small" |
| 301 | } |
| 302 | } |
| 303 | return s.CallEmbeddingAPIWithModel(content, channel, modelName, ctx) |
| 304 | } |
| 305 | |
| 306 | // CallEmbeddingAPIWithModelWithStop 调用embedding API (指定模型) - 支持停止信号检查 |
| 307 | func (s *EmbeddingService) CallEmbeddingAPIWithModelWithStop(content string, channel *model.Channel, modelName string, libraryID, fileID int64) ([]float64, error) { |
no test coverage detected