pkg

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GPT_KEY = "GPT_KEY" // 以环境变量来存放gpt的key

	GPT_URL        = "https://api.openai.com/v1/chat/completions"   // POST&GET:和gpt进行聊天
	MODEL_URL      = "https://api.openai.com/v1/models"             // GET:请求模型列表
	IMG_CREATE_URL = "https://api.openai.com/v1/images/generations" // POST:图片生成

	AUDIO_TRANSLATION_URL   = "https://api.openai.com/v1/audio/transcriptions" // POST:音频asr
	AUDIO_TRANSCRIPTION_URL = "https://api.openai.com/v1/audio/transcriptions" // POST:音频转录
)

Variables

View Source
var (
	ErrWithEmptyContent = errors.New("聊天内容为空")
)

Functions

This section is empty.

Types

type AudioTranslationRequest added in v0.3.0

type AudioTranslationRequest struct {
	File     string `json:"file"`
	Model    string `json:"model"`
	Prompt   string `json:"prompt"`
	Language string `json:"language" description:"The language of the input audio"`
}

type AudioTranslationResponse added in v0.3.0

type AudioTranslationResponse struct {
	Text string `json:"text"`
}

type Chat

type Chat struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
}

type ChatClient

type ChatClient struct {
	context.Context
	*Client

	Messages []string
}

func NewChatClient

func NewChatClient(ctx context.Context) (*ChatClient, error)

func (*ChatClient) Send

func (c *ChatClient) Send(src interface{}) (err error)

func (*ChatClient) WithPrompt

func (c *ChatClient) WithPrompt(messages []string) *ChatClient

type ChatResponse

type ChatResponse struct {
	Choices []Choice `json:"choices"`
	Created int      `json:"created"`
	ID      string   `json:"id"`
	Object  string   `json:"object"`
	Usage   Usage    `json:"usage"`
}

type Choice

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

type Client

type Client struct {
	*req.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...Option) (client *Client, err error)

func (*Client) PostClient added in v0.3.0

func (c *Client) PostClient()

PostClient 后置处理参数

func (*Client) PreNewClient

func (c *Client) PreNewClient()

PreNewClient 预检参数

func (*Client) Send

func (c *Client) Send(src interface{}) (err error)

type GptClient

type GptClient interface {
	Send(interface{}) error
}

type ImageCreateRequest added in v0.2.0

type ImageCreateRequest struct {
	Prompt string `json:"prompt"`
	Num    int    `json:"n"`
	Size   string `json:"size"`
}

图片生成

type ImageCreateResponse added in v0.2.0

type ImageCreateResponse struct {
	Created int       `json:"created"`
	Data    []UrlMeta `json:"data"`
}

图片生成

type Message

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

type ModelMeta

type ModelMeta struct {
	Created    int          `json:"created"`
	ID         string       `json:"id"`
	Object     string       `json:"object"`
	OwnedBy    string       `json:"owned_by"`
	Parent     interface{}  `json:"parent"`
	Permission []Permission `json:"permission"`
	Root       string       `json:"root"`
}

type ModelResponse

type ModelResponse struct {
	Data   []ModelMeta `json:"data"`
	Object string      `json:"object"`
}

type Option

type Option func(client *Client)

func WithBody added in v0.2.0

func WithBody(body interface{}) Option

func WithClientTimeoutSec

func WithClientTimeoutSec(timeoutSec int64) Option

func WithContentType added in v0.3.0

func WithContentType(contentType string) Option

func WithMethod

func WithMethod(method string) Option

func WithPrompt

func WithPrompt(prompt string) Option

func WithUrl

func WithUrl(url string) Option

type Permission

type Permission struct {
	AllowCreateEngine  bool        `json:"allow_create_engine"`
	AllowFineTuning    bool        `json:"allow_fine_tuning"`
	AllowLogprobs      bool        `json:"allow_logprobs"`
	AllowSampling      bool        `json:"allow_sampling"`
	AllowSearchIndices bool        `json:"allow_search_indices"`
	AllowView          bool        `json:"allow_view"`
	Created            int         `json:"created"`
	Group              interface{} `json:"group"`
	ID                 string      `json:"id"`
	IsBlocking         bool        `json:"is_blocking"`
	Object             string      `json:"object"`
	Organization       string      `json:"organization"`
}

type RespErr added in v0.3.0

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

返回错误信息

func (RespErr) Error added in v0.3.0

func (r RespErr) Error() string

type ResponseErr added in v0.3.0

type ResponseErr struct {
	Error RespErr `json:"error"`
}

返回错误信息

type Text2Cmd

type Text2Cmd struct {
	Model            string   `json:"model"`
	Prompt           string   `json:"prompt"`
	Temperature      int      `json:"temperature"`
	MaxTokens        int      `json:"max_tokens"`
	TopP             float64  `json:"top_p"`
	FrequencyPenalty float64  `json:"frequency_penalty"`
	PresencePenalty  float64  `json:"presence_penalty"`
	Stop             []string `json:"stop"`
}

type UrlMeta added in v0.2.0

type UrlMeta struct {
	URL string `json:"url"`
}

图片生成

type Usage

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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