chat

package
v0.0.0-...-fa0c35c Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermissionNone        = "none"
	PermissionChat        = "chat"
	PermissionChatPlus    = "chat+"
	PermissionImageSmall  = "image-small"
	PermissionImageMedium = "image-medium"
	PermissionImageLarge  = "image-large"
	PermissionImageMulti  = "image-multi"
)

Variables

View Source
var (
	SupportedGptModels = map[string]GptModel{
		"gpt-3.5-turbo":          Gpt3Dot5Turbo,
		"gpt-3.5-turbo-16k":      Gpt3Dot5Turbo16K,
		"gpt-3.5-turbo-0613":     Gpt3Dot5Turbo0613,
		"gpt-3.5-turbo-16k-0613": Gpt3Dot5Turbo16K0613,
		"gpt-4":                  Gpt4,
		"gpt-4-poe":              Gpt4Poe,
		"gpt-4-0314":             Gpt40314,
		"gpt-4-0613":             Gpt40613,
	}

	SupportedImageSizes = map[ImageSize]string{
		SizeSmall:  "256x256",
		SizeMedium: "512x512",
		SizeLarge:  "1024x1024",
	}
)
View Source
var (
	SupportedGptMessageRoles = map[string]GptMessageRole{
		"user":      RoleUser,
		"system":    RoleSystem,
		"assistant": RoleAssistant,
	}
)

Functions

func GetImageGenerationPrice

func GetImageGenerationPrice(size ImageSize) float64

func GetModelThousandTokenPrice

func GetModelThousandTokenPrice(_ GptModel) (prompt float64, answer float64)

Types

type ApiType

type ApiType string
const (
	GptApi   ApiType = "chat"
	ImageApi ApiType = "image"
	ShortUrl ApiType = "short"
)

type Client

type Client struct{}

func (Client) DrawPicture

func (c Client) DrawPicture(prompt string, size ImageSize) (u string, err error)

func (Client) ReplyConversation

func (c Client) ReplyConversation(text string, modelOpt GptModel) (reply string, footer string)

type Config

type Config struct {
	BaseUrl           string   `yaml:"base_url"`
	ApiVersion        string   `yaml:"api_version"`
	AppToken          string   `yaml:"app_token"`
	Prompt            string   `yaml:"prompt"`
	Temperature       float64  `yaml:"temperature"`
	PresencePenalty   float64  `yaml:"presence_penalty"`
	FrequencyPenalty  float64  `yaml:"frequency_penalty"`
	DefaultPermission []string `yaml:"default_permission"`
}

type DrawCommand

type DrawCommand struct {
	plugin.ImageReplyCommand
}

func (DrawCommand) Description

func (d DrawCommand) Description() string

func (DrawCommand) Example

func (d DrawCommand) Example() string

func (DrawCommand) Handle

func (d DrawCommand) Handle(payload processor.Payload) (replyMessage message.Message)

func (DrawCommand) Name

func (d DrawCommand) Name() string

func (DrawCommand) Triggered

func (d DrawCommand) Triggered(content string) (triggered bool)

type GptCommand

type GptCommand struct {
	plugin.TextReplyMessageBaseImplementation
}

func (GptCommand) Description

func (g GptCommand) Description() string

func (GptCommand) Example

func (g GptCommand) Example() string

func (GptCommand) Handle

func (g GptCommand) Handle(payload processor.Payload) (replyMessage message.Message)

func (GptCommand) Name

func (g GptCommand) Name() string

func (GptCommand) Triggered

func (g GptCommand) Triggered(content string) (triggered bool)

type GptCompletionsRequest

type GptCompletionsRequest struct {
	Model            GptModel     `json:"model"`
	Messages         []GptMessage `json:"messages"`
	Temperature      float64      `json:"temperature"`
	PresencePenalty  float64      `json:"presence_penalty"`
	FrequencyPenalty float64      `json:"frequency_penalty"`
	TopP             float64      `json:"top_p"`
	Stream           bool         `json:"stream"`
}

func NewGptCompletionsRequest

func NewGptCompletionsRequest(options GptConfigOptions, messages *GptMessageChain) GptCompletionsRequest

type GptCompletionsResponse

type GptCompletionsResponse struct {
	ID      string            `json:"id"`
	Object  string            `json:"object"`
	Created int64             `json:"created"`
	Model   string            `json:"model"`
	Choices []GptReplyChoices `json:"choices"`
	Usage   GptUsage          `json:"usage"`
}

type GptConfigOptions

type GptConfigOptions struct {
	Model            GptModel `json:"model"`
	Temperature      float64  `json:"temperature"`
	PresencePenalty  float64  `json:"presence_penalty"`
	FrequencyPenalty float64  `json:"frequency_penalty"`
}

type GptMessage

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

type GptMessageChain

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

func NewGptMessage

func NewGptMessage(message string, role GptMessageRole) *GptMessageChain

func NewGptMessageChain

func NewGptMessageChain(messages ...GptMessage) *GptMessageChain

func NewGptMessageWithPrompt

func NewGptMessageWithPrompt(prompt string, message string, role GptMessageRole) *GptMessageChain

func NewGptPrompt

func NewGptPrompt(prompt string) *GptMessageChain

func (*GptMessageChain) AddMessage

func (chain *GptMessageChain) AddMessage(message GptMessage) *GptMessageChain

func (*GptMessageChain) AddMessages

func (chain *GptMessageChain) AddMessages(messages ...GptMessage) *GptMessageChain

func (*GptMessageChain) GetMessages

func (chain *GptMessageChain) GetMessages() []GptMessage

func (*GptMessageChain) MergeChainAfter

func (chain *GptMessageChain) MergeChainAfter(another *GptMessageChain) *GptMessageChain

func (*GptMessageChain) MergeChainBefore

func (chain *GptMessageChain) MergeChainBefore(another *GptMessageChain) *GptMessageChain

type GptMessageRole

type GptMessageRole string
const (
	RoleUser      GptMessageRole = "user"
	RoleSystem    GptMessageRole = "system"
	RoleAssistant GptMessageRole = "assistant"
)

type GptModel

type GptModel string
const (
	Gpt3Dot5Turbo        GptModel = "gpt-3.5-turbo"
	Gpt3Dot5Turbo16K     GptModel = "gpt-3.5-turbo-16k"
	Gpt3Dot5Turbo0613    GptModel = "gpt-3.5-turbo-0613"
	Gpt3Dot5Turbo16K0613 GptModel = "gpt-3.5-turbo-16k-0613"
	Gpt4                 GptModel = "gpt-4"
	Gpt40314             GptModel = "gpt-4-0314"
	Gpt40613             GptModel = "gpt-4-0613"
	Gpt4Poe              GptModel = "gpt-4-poe"
)

type GptReplyChoices

type GptReplyChoices struct {
	Index        int        `json:"index"`
	Message      GptMessage `json:"message"`
	FinishReason string     `json:"finish_reason"`
}

type GptUsage

type GptUsage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type ImageGenerationRequest

type ImageGenerationRequest struct {
	Prompt string `json:"prompt"`
	Number int    `json:"n"`
	Size   string `json:"size"`
}

type ImageGenerationResponse

type ImageGenerationResponse struct {
	Created uint64                        `json:"created"`
	Data    []ImageGenerationResponseData `json:"data"`
}

type ImageGenerationResponseData

type ImageGenerationResponseData struct {
	Url        string `json:"url"`
	Base64Json any    `json:"b64_json"`
}

type ImageSize

type ImageSize string
const (
	SizeLarge  ImageSize = "large"
	SizeMedium ImageSize = "medium"
	SizeSmall  ImageSize = "small"
)

type ManagementCommand

type ManagementCommand struct {
	plugin.TextReplyMessageBaseImplementation
}

func (ManagementCommand) Description

func (m ManagementCommand) Description() string

func (ManagementCommand) Example

func (m ManagementCommand) Example() string

func (ManagementCommand) Handle

func (m ManagementCommand) Handle(payload processor.Payload) (replyMessage message.Message)

func (ManagementCommand) Name

func (m ManagementCommand) Name() string

func (ManagementCommand) Triggered

func (m ManagementCommand) Triggered(content string) (triggered bool)

type Permission

type Permission struct {
	UserID      string `gorm:"column:user_id;primaryKey;type:varchar(20)"`
	UserName    string `gorm:"column:user_name;type:varchar(255)"`
	Permissions uint64 `gorm:"column:permissions;index"`
}

func (Permission) TableName

func (p Permission) TableName() string

type PermissionData

type PermissionData uint64

func (PermissionData) AddPermission

func (p PermissionData) AddPermission(permission PermissionData) PermissionData

func (PermissionData) AllPermissions

func (p PermissionData) AllPermissions() []string

func (PermissionData) HasPermission

func (p PermissionData) HasPermission(permission PermissionData) bool

func (PermissionData) RemovePermission

func (p PermissionData) RemovePermission(permission PermissionData) PermissionData

type Plugin

type Plugin struct{}

func (Plugin) Commands

func (p Plugin) Commands() []plugin.MessageCommand

func (Plugin) TriggerKey

func (p Plugin) TriggerKey() string

Jump to

Keyboard shortcuts

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