Files
chatgpt-dingtalk/pkg/process/prompt.go
T

28 lines
748 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package process
import (
"errors"
"fmt"
"strings"
"github.com/eryajf/chatgpt-dingtalk/public"
)
// GeneratePrompt 生成当次请求的 Prompt
func GeneratePrompt(msg string) (rst string, err error) {
for _, prompt := range *public.Prompt {
if strings.HasPrefix(msg, prompt.Title) {
if strings.TrimSpace(msg) == prompt.Title {
rst = fmt.Sprintf("%s\n%s___输入内容___%s", prompt.Title, prompt.Prefix, prompt.Suffix)
err = errors.New("消息内容为空") // 当提示词之后没有文本,抛出异常,以便直接返回Prompt所代表的内容
} else {
rst = prompt.Prefix + strings.TrimSpace(strings.Replace(msg, prompt.Title, "", -1)) + prompt.Suffix
}
return
} else {
rst = msg
}
}
return
}