diff --git a/config.yaml b/config.yaml index a64ada6..a2008c2 100644 --- a/config.yaml +++ b/config.yaml @@ -35,7 +35,11 @@ task: ai: # 是否启用 enable: false + # 模型,不填默认gpt-3.5-turbo-0613 + model: gpt-3.5-turbo-0613 # OpenAI Api key apiKey: sk-xxxx # 接口代理域名,不填默认ChatGPT官方地址 - baseUrl: https://sxxx \ No newline at end of file + baseUrl: https://sxxx + # 人设 + personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。 \ No newline at end of file diff --git a/config/ai.go b/config/ai.go index 5726ddd..b27e3ea 100644 --- a/config/ai.go +++ b/config/ai.go @@ -3,7 +3,9 @@ package config // ai // @description: AI配置 type ai struct { - Enable bool `json:"enable" yaml:"enable"` // 是否启用AI - ApiKey string `json:"apiKey" yaml:"apiKey"` // API Key - BaseUrl string `json:"baseUrl" yaml:"baseUrl"` // API地址 + Enable bool `json:"enable" yaml:"enable"` // 是否启用AI + Model string `json:"model" yaml:"model"` // 模型 + ApiKey string `json:"apiKey" yaml:"apiKey"` // API Key + BaseUrl string `json:"baseUrl" yaml:"baseUrl"` // API地址 + Personality string `json:"personality" yaml:"personality"` // 人设 } diff --git a/handler/at_message.go b/handler/at_message.go index 6fe9be5..a0d5662 100644 --- a/handler/at_message.go +++ b/handler/at_message.go @@ -28,6 +28,27 @@ func handleAtMessage(m entity.Message) { m.Content = strings.Replace(m.Content, matches[0], "", 1) } + // 组装消息体 + messages := make([]openai.ChatCompletionMessage, 0) + if config.Conf.Ai.Personality != "" { + // 填充人设 + messages = append(messages, openai.ChatCompletionMessage{ + Role: openai.ChatMessageRoleSystem, + Content: config.Conf.Ai.Personality, + }) + } + // 填充用户消息 + messages = append(messages, openai.ChatCompletionMessage{ + Role: openai.ChatMessageRoleUser, + Content: m.Content, + }) + + // 配置模型 + model := openai.GPT3Dot5Turbo0613 + if config.Conf.Ai.Model != "" { + model = config.Conf.Ai.Model + } + // 默认使用AI回复 conf := openai.DefaultConfig(config.Conf.Ai.ApiKey) if config.Conf.Ai.BaseUrl != "" { @@ -37,7 +58,7 @@ func handleAtMessage(m entity.Message) { resp, err := client.CreateChatCompletion( context.Background(), openai.ChatCompletionRequest{ - Model: openai.GPT3Dot5Turbo0613, + Model: model, Messages: []openai.ChatCompletionMessage{ { Role: openai.ChatMessageRoleUser,