api

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	URL          = "https://api.openai.com"
	ContentType  = "application/json"
	Timeout      = 10 * time.Minute
	MaxIdleConns = 100

	Bearer        = "Bearer "
	Authorization = "Authorization"
)

Functions

func Client

func Client() *http.Client

Types

type ChatCompletionsMessage

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

type ChatCompletionsUsage

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

type Config

type Config struct {
	ApiKey string `json:"apiKey"`
}

type ImagesGenerationsReq added in v0.2.0

type ImagesGenerationsReq struct {
	Prompt         string `json:"prompt"`
	N              int    `json:"n"`
	Size           string `json:"size"`
	ResponseFormat string `json:"response_format"`
	User           string `json:"user"`
}

type ImagesGenerationsRes added in v0.2.0

type ImagesGenerationsRes struct {
	Created int64                      `json:"created"`
	Data    []ImagesGenerationsResData `json:"data"`
}

type ImagesGenerationsResData added in v0.2.0

type ImagesGenerationsResData struct {
	Url string `json:"url"`
}

type ReqChatCompletions

type ReqChatCompletions struct {
	Model    string                   `json:"model"`
	Messages []ChatCompletionsMessage `json:"messages"`
	Stream   bool                     `json:"stream"`
}

type Request

type Request[RequestBody any, ResponseResult any] struct {
	Url          string
	Method       string
	Headers      map[string]string
	Body         *RequestBody
	Response     *ResponseResult
	StatusCode   int
	HttpResponse *http.Response
	ApiKey       string
}

func ChatCompletions

func ChatCompletions(apiKey string, reqChatCompletions *ReqChatCompletions) (*Request[ReqChatCompletions, ResChatCompletions], error)

func ImagesEdit added in v0.2.1

func ImagesEdit(apiKey string, reqChatCompletions *ImagesGenerationsReq) (*Request[ImagesGenerationsReq, ImagesGenerationsRes], error)

func ImagesGenerations added in v0.2.0

func ImagesGenerations(apiKey string, reqChatCompletions *ImagesGenerationsReq) (*Request[ImagesGenerationsReq, ImagesGenerationsRes], error)

func (*Request[RequestBody, ResponseResult]) Do

func (r *Request[RequestBody, ResponseResult]) Do() error

type ResChatCompletions

type ResChatCompletions struct {
	Id      string                     `json:"id"`
	Object  string                     `json:"object"`
	Created int64                      `json:"created"`
	Model   string                     `json:"model"`
	Usage   ChatCompletionsUsage       `json:"usage"`
	Choices []ResChatCompletionsChoice `json:"choices"`
}

type ResChatCompletionsChoice

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

Jump to

Keyboard shortcuts

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