refactor: 将客服后端重构为宿主可嵌入模块
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
This commit is contained in:
+14
-3
@@ -26,7 +26,7 @@ type llm struct{}
|
||||
var LLM = &llm{}
|
||||
|
||||
func (s *llm) Chat(ctx context.Context, systemPrompt string, userPrompt string) (*ChatCompletionResult, error) {
|
||||
config, err := GetEnabledAIConfig(enums.AIModelTypeLLM)
|
||||
config, err := resolveDefaultAIConfig(ctx, enums.AIModelTypeLLM)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -34,6 +34,7 @@ func (s *llm) Chat(ctx context.Context, systemPrompt string, userPrompt string)
|
||||
}
|
||||
|
||||
func (s *llm) ChatWithConfig(ctx context.Context, config models.AIConfig, systemPrompt string, userPrompt string) (*ChatCompletionResult, error) {
|
||||
ctx = ensurePlatformAIRequestScope(ctx)
|
||||
messages := make([]openai.ChatCompletionMessageParamUnion, 0, 2)
|
||||
if strs.IsNotBlank(systemPrompt) {
|
||||
messages = append(messages, openai.ChatCompletionMessageParamUnion{
|
||||
@@ -62,7 +63,7 @@ func (s *llm) ChatWithConfig(ctx context.Context, config models.AIConfig, system
|
||||
applyProviderSpecificChatParams(¶ms, config)
|
||||
|
||||
client := newOpenAIClient(config)
|
||||
chatResp, err := client.Chat.Completions.New(ctx, params)
|
||||
chatResp, err := client.Chat.Completions.New(ctx, params, platformRequestOptions(ctx, config, "chat.completion")...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to call llm api (model=%s provider=%s system_chars=%d user_chars=%d max_output_tokens=%d): %w",
|
||||
config.ModelName, config.Provider, utf8.RuneCountInString(systemPrompt), utf8.RuneCountInString(userPrompt), config.MaxOutputTokens, err)
|
||||
@@ -84,13 +85,23 @@ func applyProviderSpecificChatParams(params *openai.ChatCompletionNewParams, con
|
||||
if params == nil {
|
||||
return
|
||||
}
|
||||
if isDashScopeQwenThinkingModel(config) {
|
||||
if isDeepSeekV4Model(config) {
|
||||
params.SetExtraFields(map[string]any{
|
||||
"thinking": map[string]any{"type": "disabled"},
|
||||
})
|
||||
} else if isDashScopeQwenThinkingModel(config) {
|
||||
params.SetExtraFields(map[string]any{
|
||||
"enable_thinking": false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func isDeepSeekV4Model(config models.AIConfig) bool {
|
||||
baseURL := strings.ToLower(strings.TrimSpace(config.BaseURL))
|
||||
modelName := strings.ToLower(strings.TrimSpace(config.ModelName))
|
||||
return strings.Contains(baseURL, "api.deepseek.com") && strings.HasPrefix(modelName, "deepseek-v4-")
|
||||
}
|
||||
|
||||
func isDashScopeQwenThinkingModel(config models.AIConfig) bool {
|
||||
baseURL := strings.ToLower(strings.TrimSpace(config.BaseURL))
|
||||
modelName := strings.ToLower(strings.TrimSpace(config.ModelName))
|
||||
|
||||
Reference in New Issue
Block a user