gpt

package
v0.0.0-...-45605f7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package gpt contains bot command handler which sends text generated by GPT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextPromptData

type ContextPromptData struct {
	Prompter PromptUser
	// ChatTitle is a chat title where prompt was generated.
	ChatTitle string
}

ContextPromptData is a data structure passed to context prompt template.

type Handler

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

Handler implements GPT request handler.

func New

func New(api *openai.Client, db *ent.Client, tp trace.TracerProvider) *Handler

New creates new Handler.

func (*Handler) OnCommand

func (h *Handler) OnCommand(ctx context.Context, e dispatch.MessageEvent) error

OnCommand implements dispatch.MessageHandler.

func (*Handler) OnInfo

func (h *Handler) OnInfo(ctx context.Context, e dispatch.MessageEvent) error

OnInfo implements dispatch.MessageHandler.

func (*Handler) OnReply

func (h *Handler) OnReply(ctx context.Context, e dispatch.MessageEvent) (rerr error)

OnReply handles replies to gpt generated messages.

func (*Handler) WithContextPromptTemplate

func (h *Handler) WithContextPromptTemplate(t *template.Template) *Handler

WithContextPromptTemplate sets template to setup a context prompt before completion.

func (*Handler) WithLimitConfig

func (h *Handler) WithLimitConfig(cfg LimitConfig) *Handler

WithMessageLimit sets message limit in runes.

type LimitConfig

type LimitConfig struct {
	// PerUserRate sets cooldown timeout for a one user across chats.
	// If <=0, limit is disabled.
	PerUserRate time.Duration
	// PerPeerRate sets cooldown timeout for a one peer (chat/channel/user).
	// If <=0, limit is disabled.
	PerPeerRate time.Duration
	// MessageSizeLimit sets limit in runes for one message (prompt).
	// If <=0, limit is disabled.
	MessageSizeLimit int
	// DialogDepthLimit sets dialog depth limit. Counts prompt and AI answer as well.
	// If <=0, limit is disabled.
	DialogDepthLimit int
}

LimitConfig sets limits for GPT.

func (*LimitConfig) ParseEnv

func (cfg *LimitConfig) ParseEnv() error

ParseEnv parses environment.

type PromptUser

type PromptUser struct {
	Username  string
	FirstName string
}

PromptUser defines context prompt data of user asking the question.

Jump to

Keyboard shortcuts

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