openai

package
v2.3.7 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 21 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"`
	User             string        `json:"user,omitempty"`
	Seed             string        `json:"seed,omitempty"`
}

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"`
	Seed                 string  `mapstructure:"seed"`
	MaxTokens            int     `mapstructure:"max_tokens"`

	// number of thread messages stored which are used as a context for further requests
	HistorySize int `mapstructure:"history_size"`

	// is no other command matched, evaluate the message with openai
	UseAsFallback bool `mapstructure:"use_as_fallback"`

	// maximum update frequency of slack messages when "stream" is active
	UpdateInterval time.Duration `mapstructure:"update_interval"`

	// log all input+output text to the logger. This could include personal information, therefore disabled by default!
	LogTexts bool `mapstructure:"log_texts"`

	// Dall-E image generation
	DalleModel          string `mapstructure:"dalle_model"`
	DalleImageSize      string `mapstructure:"dalle_image_size"`
	DalleNumberOfImages int    `mapstructure:"dalle_number_of_images"`
}

Config configuration: API key to do API calls

func (*Config) IsEnabled

func (c *Config) IsEnabled() bool

IsEnabled checks if token is set

type DalleRequest added in v2.3.4

type DalleRequest struct {
	Model  string `json:"model"`
	Prompt string `json:"prompt"`
	N      int    `json:"n"`
	Size   string `json:"size"`
}
{
    "model": "dall-e-3",
    "prompt": "a white siamese cat",
    "n": 1,
    "size": "1024x1024"
  }

type DalleResponse added in v2.3.4

type DalleResponse struct {
	Data  []DalleResponseImage `json:"data"`
	Error struct {
		Code    string `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}
{
  "created": 1700233554,
  "data": [
    {
      "url": "https://XXXX"
    }
  ]
}

or:

{
  "error": {
    "code": "invalid_size",
    "message": "The size is not supported by this model.",
    "param": null,
    "type": "invalid_request_error"
  }
}

type DalleResponseImage added in v2.3.4

type DalleResponseImage struct {
	URL           string `json:"url"`
	RevisedPrompt string `json:"revised_prompt"`
}

Jump to

Keyboard shortcuts

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