openai

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

README

OpenAI

Release License

Install

GoVersion

go get -u github.com/starudream/openai-go

Usage

GoDoc

Ref

API

License

Apache License 2.0

Documentation

Index

Constants

View Source
const (
	DefaultBaseURL   = "https://api.openai.com/"
	DefaultVersion   = "v1/"
	DefaultUserAgent = "starudream-openai-go"
)

Variables

This section is empty.

Functions

func Debug

func Debug() bool

Types

type BaseResp added in v0.0.5

type BaseResp struct {
	Error struct {
		Message string `json:"message"`
		Type    string `json:"type"`
	} `json:"error"`
}

type ChatCompletionsChan added in v0.0.2

type ChatCompletionsChan struct {
	// contains filtered or unexported fields
}

type ChatCompletionsReq

type ChatCompletionsReq struct {
	Model            string               `json:"model"`
	Messages         []CompletionsMessage `json:"messages"`
	Temperature      float64              `json:"temperature,omitempty"`
	TopP             float64              `json:"top_p,omitempty"`
	N                int                  `json:"n,omitempty"`
	Stream           bool                 `json:"stream,omitempty"`
	MaxTokens        int                  `json:"max_tokens,omitempty"`
	PresencePenalty  float64              `json:"presence_penalty,omitempty"`
	FrequencyPenalty float64              `json:"frequency_penalty,omitempty"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(token string, options ...ClientOptionFunc) (*Client, error)

func (*Client) ChatCompletions

func (c *Client) ChatCompletions(req ChatCompletionsReq) (CompletionsResp, *http.Response, error)

func (*Client) ChatCompletionsStream added in v0.0.2

func (c *Client) ChatCompletionsStream(req ChatCompletionsReq) (*ChatCompletionsChan, *http.Response, error)

func (*Client) Completions

func (c *Client) Completions(req CompletionsReq) (CompletionsResp, *http.Response, error)

func (*Client) Exec

func (c *Client) Exec(method, path string, opt, res any) (*resty.Response, error)

func (*Client) ListModels

func (c *Client) ListModels() ([]Model, *http.Response, error)

func (*Client) Pre added in v0.0.2

func (c *Client) Pre(method, path string, opt any) (string, map[string]string, any, error)

func (*Client) RetrieveModel

func (c *Client) RetrieveModel(id string) (Model, *http.Response, error)

type ClientOptionFunc

type ClientOptionFunc func(c *Client) error

func WithBaseURL

func WithBaseURL(urlStr string) ClientOptionFunc

func WithClient added in v0.0.4

func WithClient(client *resty.Client) ClientOptionFunc

func WithUserAgent

func WithUserAgent(userAgent string) ClientOptionFunc

type CompletionsChoice

type CompletionsChoice struct {
	Text         *string             `json:"text"`
	Message      *CompletionsMessage `json:"message"`
	Delta        *CompletionsMessage `json:"delta"`
	Index        int                 `json:"index"`
	FinishReason string              `json:"finish_reason"`
}

type CompletionsMessage

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

func NewCompletionsMessage added in v0.0.2

func NewCompletionsMessage(role, content string) CompletionsMessage

type CompletionsReq

type CompletionsReq struct {
	Model            string  `json:"model"`
	Prompt           string  `json:"prompt"`
	Suffix           string  `json:"suffix,omitempty"`
	MaxTokens        int     `json:"max_tokens,omitempty"`
	Temperature      float64 `json:"temperature,omitempty"`
	TopP             float64 `json:"top_p,omitempty"`
	N                int     `json:"n,omitempty"`
	PresencePenalty  float64 `json:"presence_penalty,omitempty"`
	FrequencyPenalty float64 `json:"frequency_penalty,omitempty"`
}

type CompletionsResp

type CompletionsResp struct {
	Id      string               `json:"id"`
	Object  string               `json:"object"`
	Created int                  `json:"created"`
	Model   string               `json:"model"`
	Choices []*CompletionsChoice `json:"choices"`
	Usage   *CompletionsUsage    `json:"usage"`
}

func (*CompletionsResp) GetMessage

func (p *CompletionsResp) GetMessage() []CompletionsMessage

type CompletionsUsage

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

type ListModelResp

type ListModelResp struct {
	Object string  `json:"object"`
	Data   []Model `json:"data"`
}

type Model

type Model struct {
	Id         string            `json:"id"`
	Object     string            `json:"object"`
	Created    int               `json:"created"`
	OwnedBy    string            `json:"owned_by"`
	Permission []ModelPermission `json:"permission"`
	Root       string            `json:"root"`
}

type ModelPermission

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

type Ratelimit

type Ratelimit struct {
	LimitRequests     int
	LimitTokens       int
	RemainingRequests int
	RemainingTokens   int
	ResetRequests     time.Duration
	ResetTokens       time.Duration
}

func GetRatelimit

func GetRatelimit(resp *http.Response) *Ratelimit

Directories

Path Synopsis
internal
query
Package query implements encoding of structs into URL query parameters.
Package query implements encoding of structs into URL query parameters.
sse

Jump to

Keyboard shortcuts

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