39 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
package llm_service
 | 
						||
 | 
						||
import (
 | 
						||
	"ai_scheduler/internal/data/model"
 | 
						||
	"ai_scheduler/internal/entitys"
 | 
						||
	"context"
 | 
						||
)
 | 
						||
 | 
						||
type LlmService interface {
 | 
						||
	IntentRecognize(ctx context.Context, sysInfo model.AiSy, history []model.AiChatHi, userInput string, tasks []model.AiTask) (string, error)
 | 
						||
}
 | 
						||
 | 
						||
// buildSystemPrompt 构建系统提示词
 | 
						||
func buildSystemPrompt(prompt string) string {
 | 
						||
	if len(prompt) == 0 {
 | 
						||
		prompt = "[system] 你是一个智能路由系统,核心职责是 **精准解析用户意图并路由至对应任务模块**\n[rule]\n1.返回以下格式的JSON:{ \"index\": \"工具索引index\", \"confidence\": 0.0-1.0,\"reasoning\": \"判断理由\"}\n2.严格返回字符串格式,禁用markdown格式返回\n3.只返回json字符串,不包含任何其他解释性文字\n4.当用户意图非常不清晰时使用,尝试进行追问具体希望查询内容"
 | 
						||
	}
 | 
						||
 | 
						||
	return prompt
 | 
						||
}
 | 
						||
 | 
						||
func buildAssistant(his []model.AiChatHi) (chatHis entitys.ChatHis) {
 | 
						||
	for _, item := range his {
 | 
						||
		if len(chatHis.SessionId) == 0 {
 | 
						||
			chatHis.SessionId = item.SessionID
 | 
						||
		}
 | 
						||
		chatHis.Messages = append(chatHis.Messages, entitys.HisMessage{
 | 
						||
			Role:      item.Role,
 | 
						||
			Content:   item.Content,
 | 
						||
			Timestamp: item.CreateAt.Format("2006-01-02 15:04:05"),
 | 
						||
		})
 | 
						||
	}
 | 
						||
	chatHis.Context = entitys.HisContext{
 | 
						||
		UserLanguage: "zh-CN",
 | 
						||
		SystemMode:   "technical_support",
 | 
						||
	}
 | 
						||
	return
 | 
						||
}
 |