core

package
v0.0.0-...-9afd7d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const TimeFormat = "2006-01-02 15:04:05"

Variables

View Source
var ChatGPTCommand = &cobra.Command{
	Use:   "start",
	Short: "启动chatgpt",
	Long:  fmt.Sprintf(""),
	Run:   processMessage,
}
View Source
var Logger *zap.Logger

Functions

func InitLogger

func InitLogger(logLevel, logFile string)

InitLogger 初始化日志

func PrintlnQrcodeUrl

func PrintlnQrcodeUrl(uuid string)

func TimeEncoder

func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

TimeEncoder 序列化时间

Types

type ChatCompletionMessage

type ChatCompletionMessage struct {
	openai.ChatCompletionMessage
	Timestamp uint64
}

func (*ChatCompletionMessage) FillTimestamp

func (c *ChatCompletionMessage) FillTimestamp()

FillTimestamp 填充时间戳

func (*ChatCompletionMessage) IsExpired

func (i *ChatCompletionMessage) IsExpired() bool

IsExpired 判断消息是否过期

type ChatCompletionMessages

type ChatCompletionMessages []*ChatCompletionMessage

func (*ChatCompletionMessages) GetValidChatCompletionMessages

func (c *ChatCompletionMessages) GetValidChatCompletionMessages() []openai.ChatCompletionMessage

GetValidChatCompletionMessages 获取有效时间范围内的聊天消息

func (*ChatCompletionMessages) GetValidMessages

func (c *ChatCompletionMessages) GetValidMessages() ChatCompletionMessages

GetValidMessages 获取有效时间范围内的聊天消息

func (*ChatCompletionMessages) RemoveSecondItem

func (c *ChatCompletionMessages) RemoveSecondItem()

type ChatContext

type ChatContext struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ChatContext) AppendMessage

func (u *ChatContext) AppendMessage(key string, value *ChatCompletionMessage)

AppendMessage 追加消息

func (*ChatContext) Clear

func (u *ChatContext) Clear(key string)

Clear 清除消息

func (*ChatContext) ClearAll

func (u *ChatContext) ClearAll()

ClearAll 清除所有消息

func (*ChatContext) GetMessages

func (u *ChatContext) GetMessages(senderName string) []openai.ChatCompletionMessage

GetMessages 获取消息

func (*ChatContext) GetString

func (u *ChatContext) GetString(key string) string

func (*ChatContext) GetTimestampMessages

func (u *ChatContext) GetTimestampMessages(senderName string) ChatCompletionMessages

GetTimestampMessages 获取消息

func (*ChatContext) SetDefaultMessage

func (u *ChatContext) SetDefaultMessage(key string)

SetDefaultMessage 设置默认消息

type ChatGptConf

type ChatGptConf struct {
	Token                 string   `json:"token"`
	GroupChatPrefix       []string `json:"group_chat_prefix"`
	GroupNameWhiteList    []string `json:"group_name_white_list"`
	ConversationMaxTokens int      `json:"conversation_max_tokens"`
	CharacterDesc         string   `json:"character_desc"`
	ConversationTimeout   int      `json:"conversation_timeout"`
	// contains filtered or unexported fields
}

func (*ChatGptConf) AddGroupNameWhiteList

func (i *ChatGptConf) AddGroupNameWhiteList(name string)

AddGroupNameWhiteList 添加群聊白名单

func (*ChatGptConf) GetDefaultPrompt

func (i *ChatGptConf) GetDefaultPrompt() openai.ChatCompletionMessage

GetDefaultPrompt 获取默认的提示

func (*ChatGptConf) MatchGroupChatMentionPrefix

func (i *ChatGptConf) MatchGroupChatMentionPrefix(context string) bool

MatchGroupChatMentionPrefix 判断是否是群聊@机器人的消息

func (*ChatGptConf) MatchGroupName

func (i *ChatGptConf) MatchGroupName(groupName string) bool

MatchGroupName 判断是否群聊名称是否符合

func (*ChatGptConf) RemoveGroupNameWhiteList

func (i *ChatGptConf) RemoveGroupNameWhiteList(name string)

RemoveGroupNameWhiteList 移除群聊白名单

func (*ChatGptConf) SetDefaultPrompt

func (i *ChatGptConf) SetDefaultPrompt(value string)

SetDefaultPrompt 设置默认提示

type ConfHelper

type ConfHelper struct {
	// contains filtered or unexported fields
}

func NewConfHelper

func NewConfHelper(file string) *ConfHelper

func NewTestConfHelper

func NewTestConfHelper() *ConfHelper

func (*ConfHelper) ConversationMaxTokens

func (i *ConfHelper) ConversationMaxTokens() int

ConversationMaxTokens 获取对话最大长度

func (*ConfHelper) ConversationTimeout

func (i *ConfHelper) ConversationTimeout() int

ConversationTimeout 获取对话超时时间

func (*ConfHelper) GetConf

func (i *ConfHelper) GetConf() *ChatGptConf

func (*ConfHelper) LoadJsonConf

func (i *ConfHelper) LoadJsonConf() (conf *ChatGptConf, err error)

LoadJsonConf 从文件中加载配置

func (*ConfHelper) MatchGroupFilter

func (i *ConfHelper) MatchGroupFilter(msg *openwechat.Message) (bool, string, error)

func (*ConfHelper) SaveJsonConf

func (i *ConfHelper) SaveJsonConf(conf *ChatGptConf) error

SaveJsonConf 保存配置到文件

type MessageHandler

type MessageHandler struct {
	// contains filtered or unexported fields
}

func (MessageHandler) GetSenderName

func (h MessageHandler) GetSenderName(msg *openwechat.Message) string

GetSenderName 获取发送者名称

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL