openai

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenAIBaseURL = "https://api.openai.com/v1"

	RoleDeveloper = "developer"
	RoleSystem    = "system"
	RoleUser      = "user"
	RoleAssistant = "assistant"
	RoleTool      = "tool"
)

Variables

This section is empty.

Functions

func AzureOpenAIAuthenticate added in v1.1.8

func AzureOpenAIAuthenticate(req *http.Request, apikey string)

func AzureOpenAIBaseURL added in v1.1.8

func AzureOpenAIBaseURL(domain, deployment string) string

func AzureOpenAIServicePath added in v1.1.8

func AzureOpenAIServicePath(apiver string) func(string, ...any) string

func IsResultError added in v1.1.2

func IsResultError(err error) bool

func NewRetryer added in v1.1.8

func NewRetryer(retryAfter time.Duration, maxRetries int, logger log.Logger) *ret.Retryer

default retry on not canceled error or (status = 429 || (status >= 500 && status <= 599))

Types

type BodyMarshaler added in v1.1.8

type BodyMarshaler interface {
	MarshalBody() (io.Reader, string, error)
}

BodyMarshaler is the interface implemented by types that can marshal themselves for http request.

type Client added in v1.1.4

type Client struct {
	BaseURL string
	APIKey  string

	Transport http.RoundTripper
	Timeout   time.Duration
	Retryer   *ret.Retryer

	Authenticate func(req *http.Request, apikey string)  // custom authenticate function
	ServicePath  func(format string, args ...any) string // custom service path function
}

func NewAzureClient added in v1.1.8

func NewAzureClient(domain, deployment, apiver string) *Client

func (*Client) DoPost added in v1.1.4

func (c *Client) DoPost(ctx context.Context, url string, source, result any) error

type DetailError

type DetailError struct {
	Type    string `json:"type,omitempty"`
	Code    any    `json:"code,omitempty"`
	Param   any    `json:"param,omitempty"`
	Message string `json:"message,omitempty"`
}

func (*DetailError) Error

func (de *DetailError) Error() string

type ResultError

type ResultError struct {
	Method     string       `json:"-"` // http request method
	URL        *url.URL     `json:"-"` // http request URL
	StatusCode int          `json:"-"` // http status code
	Status     string       `json:"-"` // http status
	Detail     *DetailError `json:"error,omitempty"`
}

func AsResultError added in v1.1.2

func AsResultError(err error) (re *ResultError, ok bool)

func (*ResultError) Error

func (re *ResultError) Error() string

Directories

Path Synopsis
chat

Jump to

Keyboard shortcuts

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