1
0
Fork 0

AI新增模型和人设配置

This commit is contained in:
李寻欢 2023-11-17 09:57:35 +08:00
parent 91d2fc50e2
commit 6c2bf3fc9c
3 changed files with 32 additions and 5 deletions

View File

@ -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
baseUrl: https://sxxx
# 人设
personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。

View File

@ -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"` // 人设
}

View File

@ -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,