chat

package
v0.0.0-...-98805be Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GeminiUser = "user"
	GeminiBot  = "model"
)
View Source
const (
	QwenChatUser = "user"
	QwenChatBot  = "assistant"
)

Variables

This section is empty.

Functions

func AddTodo

func AddTodo(param, userId string) string

func ClearMsg

func ClearMsg(param string, userId string) string

func DelTodo

func DelTodo(param, userId string) string

func DoAction

func DoAction(userId, msg string) (r string, flag bool)

func GetModel

func GetModel(param string, userId string) string

func GetMsgListWithDb

func GetMsgListWithDb[T ChatMsg](botType, userId string, msg T, f func(msg T) db.Msg, f2 func(msg db.Msg) T) []T

func GetPrompt

func GetPrompt(param string, userId string) string

func GetTodoList

func GetTodoList(param string, userId string) string

func HmacWithShaTobase64

func HmacWithShaTobase64(algorithm, data, key string) string

func RmPrompt

func RmPrompt(param string, userId string) string

func SaveMsgListWithDb

func SaveMsgListWithDb[T ChatMsg](botType, userId string, msgList []T, f func(msg T) db.Msg)

func SetModel

func SetModel(param, userId string) string

func SetPrompt

func SetPrompt(param, userId string) string

func SwitchUserBot

func SwitchUserBot(userId string, botType string) string

func WithTimeChat

func WithTimeChat(userID, msg string, f func(userID, msg string) string) string

加入超时控制

Types

type BaseChat

type BaseChat interface {
	Chat(userID string, msg string) string
	HandleMediaMsg(msg *message.MixMessage) string
}

func GetChatBot

func GetChatBot(botType string) BaseChat

type ChatMsg

type ChatMsg interface {
	openai.ChatCompletionMessage | QwenMessage | SparkMessage | *genai.Content
}

type Echo

type Echo struct{}

func (*Echo) Chat

func (e *Echo) Chat(userID string, msg string) string

func (*Echo) HandleMediaMsg

func (e *Echo) HandleMediaMsg(msg *message.MixMessage) string

type ErrorChat

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

func (*ErrorChat) Chat

func (e *ErrorChat) Chat(userID string, msg string) string

func (*ErrorChat) HandleMediaMsg

func (e *ErrorChat) HandleMediaMsg(msg *message.MixMessage) string

type GeminiChat

type GeminiChat struct {
	BaseChat
	// contains filtered or unexported fields
}

func (*GeminiChat) Chat

func (g *GeminiChat) Chat(userID string, msg string) string

type Input

type Input struct {
	Messages []QwenMessage `json:"messages"`
}

type Output

type Output struct {
	Text         string `json:"text"`
	FinishReason string `json:"finish_reason"`
}

type Parameters

type Parameters struct {
	ResultFormat      string   `json:"result_format"`
	Seed              int      `json:"seed"`
	MaxTokens         int      `json:"max_tokens"`
	TopP              float64  `json:"top_p"`
	TopK              float64  `json:"top_k"`
	RepetitionPenalty float64  `json:"repetition_penalty"`
	Temperature       float64  `json:"temperature"`
	Stop              string   `json:"stop"`
	EnableSearch      bool     `json:"enable_search"`
	IncrementalOutput bool     `json:"incremental_output"`
	Tools             []string `json:"tools"`
}

type QwenChat

type QwenChat struct {
	BaseChat
	Config *config.QwenConfig
	// contains filtered or unexported fields
}

func (*QwenChat) Chat

func (chat *QwenChat) Chat(userId, message string) (res string)

type QwenMessage

type QwenMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type QwenRequest

type QwenRequest struct {
	Model      string     `json:"model"`
	Input      Input      `json:"input"`
	Parameters Parameters `json:"parameters"`
}

type QwenResponse

type QwenResponse struct {
	Output    Output `json:"output"`
	Usage     Usage  `json:"usage"`
	RequestID string `json:"request_id"`
}

type SimpleChat

type SimpleChat struct {
}

func (SimpleChat) Chat

func (s SimpleChat) Chat(userID string, msg string) string

func (SimpleChat) HandleMediaMsg

func (s SimpleChat) HandleMediaMsg(msg *message.MixMessage) string

type SimpleGptChat

type SimpleGptChat struct {
	BaseChat
	// contains filtered or unexported fields
}

func (*SimpleGptChat) Chat

func (s *SimpleGptChat) Chat(userID string, msg string) string

type SparkChat

type SparkChat struct {
	BaseChat
	Config *config.SparkConfig
	// contains filtered or unexported fields
}

func (*SparkChat) Chat

func (chat *SparkChat) Chat(userId, message string) (res string)

type SparkMessage

type SparkMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type SparkResponse

type SparkResponse struct {
	Header  *SparkResponseHeader `json:"header"`
	Payload map[string]any       `json:"payload"`
}

type SparkResponseHeader

type SparkResponseHeader struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Sid     string `json:"sid"`
	Status  int    `json:"status"`
}

func (*SparkResponseHeader) IsFailed

func (header *SparkResponseHeader) IsFailed() bool

func (*SparkResponseHeader) IsSuccess

func (header *SparkResponseHeader) IsSuccess() bool

func (*SparkResponseHeader) ToString

func (header *SparkResponseHeader) ToString() string

type Usage

type Usage struct {
	OutputTokens int `json:"output_tokens"`
	InputTokens  int `json:"input_tokens"`
}

Jump to

Keyboard shortcuts

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