openai

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallChatGPT

func CallChatGPT(cfg Config, inputMessages []ChatMessage, stream bool) (<-chan string, error)

func GetCommands

func GetCommands(base bot.BaseCommand, config *config.Config) bot.Commands

GetCommands if enable, register the openai commands

Types

type ChatChoice

type ChatChoice struct {
	Index        int         `json:"index"`
	Message      ChatMessage `json:"message"`
	FinishReason string      `json:"finish_reason"`
	Delta        ChatMessage `json:"delta"`
}

type ChatMessage

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

type ChatRequest

type ChatRequest struct {
	Model            string         `json:"model"`
	Messages         []ChatMessage  `json:"messages"`
	Temperature      float32        `json:"temperature,omitempty"`
	TopP             float32        `json:"top_p,omitempty"`
	N                int            `json:"n,omitempty"`
	Stop             []string       `json:"stop,omitempty"`
	Stream           bool           `json:"stream,omitempty"`
	MaxTokens        int            `json:"max_tokens,omitempty"`
	PresencePenalty  float32        `json:"presence_penalty,omitempty"`
	FrequencyPenalty float32        `json:"frequency_penalty,omitempty"`
	LogitBias        map[string]int `json:"logit_bias,omitempty"`
	User             string         `json:"user,omitempty"`
}

https://platform.openai.com/docs/guides/chat/chat-completions-beta https://platform.openai.com/docs/api-reference/chat

type ChatResponse

type ChatResponse struct {
	ID      string       `json:"id"`
	Object  string       `json:"object"`
	Created int64        `json:"created"`
	Choices []ChatChoice `json:"choices"`
	Error   struct {
		Message string `json:"message"`
		Type    string `json:"type"`
	} `json:"error"`
	Usage struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
}

func (ChatResponse) GetDelta

func (r ChatResponse) GetDelta() ChatMessage

func (ChatResponse) GetError

func (r ChatResponse) GetError() error

func (ChatResponse) GetMessage

func (r ChatResponse) GetMessage() ChatMessage

type Config

type Config struct {
	APIKey               string        `mapstructure:"api_key"`
	APIHost              string        `mapstructure:"api_host"`
	InitialSystemMessage string        `mapstructure:"initial_system_message"`
	Model                string        `mapstructure:"model"`
	Temperature          float32       `mapstructure:"temperature"`
	UpdateInterval       time.Duration `mapstructure:"update_interval"`
}

Config configuration: API key to do API calls

func (*Config) IsEnabled

func (c *Config) IsEnabled() bool

IsEnabled checks if token is set

Jump to

Keyboard shortcuts

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