openai

package
v0.0.0-...-0ee1bbb Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModelGPT35Turbo    = "gpt-3.5-turbo"
	ModelGPT35Turbo16K = "gpt-3.5-turbo-16k"
	ModelGPT4          = "gpt-4"
	ModelGPT432K       = "gpt-4-32k"
)
View Source
const ApiUrl = "https://api.openai.com/v1/chat/completions"

Variables

This section is empty.

Functions

func ChatCompletion

func ChatCompletion(params *ChatCompletionParams, callback CreateChatCompletionCallbackFunc) (err error)

Types

type ChatCompletionParams

type ChatCompletionParams struct {
	Model    string
	Messages RequestChatParamsMessages
}

type CreateChatCompletionCallbackFunc

type CreateChatCompletionCallbackFunc func(originContent string, contentObj *ResponseChat) error

type OpenaiClient

type OpenaiClient struct {
}

OpenaiClient openai推送

func Instance

func Instance() *OpenaiClient

Instance 单例

func (*OpenaiClient) GetConfig

func (c *OpenaiClient) GetConfig() (configData *entity.ConfigOpenai, err error)

GetConfig 获取配置

type RequestChatParams

type RequestChatParams struct {
	Model     string                    `json:"model"`
	Messages  RequestChatParamsMessages `json:"messages"`
	MaxTokens int                       `json:"max_tokens"`
	Stream    bool                      `json:"stream"`
}

type RequestChatParamsMessageItem

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

type RequestChatParamsMessages

type RequestChatParamsMessages []*RequestChatParamsMessageItem

type ResponseChat

type ResponseChat struct {
	Id      string              `json:"id"`
	Object  string              `json:"object"`
	Created int                 `json:"created"`
	Choices ResponseChatChoices `json:"choices"`
	Usage   *ResponseChatUsage  `json:"usage"`
}

type ResponseChatChoices

type ResponseChatChoices []*ResponseChatChoicesItem

type ResponseChatChoicesItem

type ResponseChatChoicesItem struct {
	Index        int                             `json:"index"`
	Message      *ResponseChatChoicesItemMessage `json:"message"`
	Delta        *ResponseChatChoicesItemMessage `json:"delta"`
	FinishReason string                          `json:"finish_reason"`
}

type ResponseChatChoicesItemMessage

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

type ResponseChatError

type ResponseChatError struct {
	Error *ResponseChatErrorData `json:"error"`
}

type ResponseChatErrorData

type ResponseChatErrorData struct {
	Message string      `json:"message"`
	Type    string      `json:"type"`
	Param   interface{} `json:"param"`
	Code    string      `json:"code"`
}

type ResponseChatUsage

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

Jump to

Keyboard shortcuts

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