chat

package
v1.7.2-0...-ebb5c08 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: GPL-3.0 Imports: 28 Imported by: 0

README

在QQ群与用户闲聊。你将收到不同的用户发送的一至多条消息。 你需要逐个扫描消息,综合用户们发送的所有信息给出一个完整回复。

  1. >>开头的是特别@你的消息,否则这部分为空;
  2. 【发送者用户名】;
  3. 消息内容。

你的输出是不带任何格式和换行的消息内容,纯文本。

Documentation

Overview

Package chat 提供聊天记录管理和 AI 模型交互功能

Index

Constants

View Source
const (
	BitmapRate = 0x0000ff
	BitmapTemp = 0x00ff00
	BitmapNagt = 0x010000
	BitmapNrec = 0x020000
	BitmapNrat = 0x040000
)

Bitmap constants for storage

Variables

View Source
var (
	// AtPrefix @用户时给 LLM 的前缀提示, 需要和提示词一致
	AtPrefix = ">>"
	// NameL 包裹用户名的左括号, 需要和提示词一致
	NameL = "【"
	// NameR 包裹用户名的右括号, 需要和提示词一致
	NameR = "】"
)
View Source
var AgentChar []byte

AgentChar 将 char.yaml 内容嵌入为默认 agent 性格

View Source
var IsAgentCharReady = false

IsAgentCharReady then logev works

View Source
var SystemPrompt string

SystemPrompt 将 README.md 内容嵌入为默认系统提示词

Functions

func AddChatReply

func AddChatReply(grp int64, txt string)

AddChatReply 将 AI 回复追加到指定群组的聊天记录

func AgentOf

func AgentOf(id int64, service string) *goba.Agent

AgentOf id is self_id

func CallAgent

func CallAgent(ag *goba.Agent, issudo bool, iter int, api deepinfra.API, p model.Protocol, grp int64, role goba.PermRole) []zero.APIRequest

CallAgent and check group API permission

func EnsureConfig

func EnsureConfig(ctx *zero.Ctx) bool

EnsureConfig ensures the configuration is loaded and valid

func GetChatContext

func GetChatContext(p model.Protocol, grp int64, sysp string, isusersys bool) deepinfra.Model

GetChatContext 根据聊天记录构造可执行的 deepinfra 模型请求

func NewExtraSetBool

func NewExtraSetBool[T ~bool](ptr *T) func(ctx *zero.Ctx)

NewExtraSetBool creates a handler to set a boolean-based extra config value

func NewExtraSetFloat32

func NewExtraSetFloat32(ptr *float32) func(ctx *zero.Ctx)

NewExtraSetFloat32 creates a handler to set a float32 extra config value

func NewExtraSetModelType

func NewExtraSetModelType(ptr *ModelType) func(ctx *zero.Ctx)

NewExtraSetModelType creates a handler to set a ModelType extra config value

func NewExtraSetStr

func NewExtraSetStr[T ~string](ptr *T) func(ctx *zero.Ctx)

NewExtraSetStr creates a handler to set a string-based extra config value

func NewExtraSetUint

func NewExtraSetUint(ptr *uint) func(ctx *zero.Ctx)

NewExtraSetUint creates a handler to set a uint extra config value

func ResetAgents

func ResetAgents()

ResetAgents reset all agent log

func ResetChat

func ResetChat()

ResetChat 清空全局聊天记录,重新开始

func ResetChatIn

func ResetChatIn(grps ...int64)

ResetChatIn 清空 grps 的聊天记录,重新开始

func Sanitize

func Sanitize(msg string) string

Sanitize 清洗 AI 返回文本: 1. 去掉换行后内容 2. 去掉发言前缀(如【name】或[name]) 3. 去掉重复 10 次以上的子串 4. 去除首尾空白

Types

type AgentConfig

type AgentConfig struct {
	ModelName      string
	ImageModelName string
	AgentModelName string
	Type           ModelType
	ImageType      ModelType
	AgentType      ModelType
	MaxN           uint
	TopP           float32
	SystemP        string
	AgentChar      string
	API            string
	ImageAPI       string
	AgentAPI       string
	Key            ModelKey
	ImageKey       ModelKey
	AgentKey       ModelKey
	Separator      string
	NoSystemP      ModelBool
}

AgentConfig holds the configuration for the chat agent

var AC AgentConfig

AC is the global agent configuration

func (*AgentConfig) MParams

func (c *AgentConfig) MParams() (topp float32, maxn uint)

MParams returns the global model parameters: TopP and MaxN

func (*AgentConfig) String

func (c *AgentConfig) String() string

type ModelBool

type ModelBool bool

ModelBool 支持打印成 "是/否"

func (ModelBool) String

func (mb ModelBool) String() string

type ModelKey

type ModelKey string

ModelKey 支持隐藏密钥

func (ModelKey) String

func (mk ModelKey) String() string

type ModelType

type ModelType int

ModelType 支持打印 string 并生产 protocal

func (ModelType) Protocol

func (mt ModelType) Protocol(modn string, temp float32, topp float32, maxn uint) (mod model.Protocol, err error)

Protocol creates a protocol instance based on the model type

func (ModelType) String

func (mt ModelType) String() string

type Storage

type Storage ctxext.Storage

Storage wraps ctxext.Storage for chat-specific storage operations

func NewStorage

func NewStorage(ctx *zero.Ctx, gid int64) (Storage, error)

NewStorage creates a new Storage instance

func (Storage) NoAgent

func (s Storage) NoAgent() bool

NoAgent returns whether the agent is disabled

func (Storage) NoRecord

func (s Storage) NoRecord() bool

NoRecord returns whether recording is disabled

func (Storage) NoReplyAt

func (s Storage) NoReplyAt() bool

NoReplyAt returns whether replying with @ is disabled

func (Storage) Rate

func (s Storage) Rate() uint8

Rate returns the rate value from storage

func (Storage) Temp

func (s Storage) Temp() float32

Temp returns the temperature value from storage

Jump to

Keyboard shortcuts

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