openai

package
v0.0.0-...-48dc23e Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStrArrayUnsupportedType = errors.New("unsupported type, must be string or []string")

Functions

This section is empty.

Types

type CompletionFunction

type CompletionFunction struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Parameters  []byte `json:"parameters,omitempty"`
}

type CreateChatCompletionsChoice

type CreateChatCompletionsChoice struct {
	Index        int      `json:"index,omitempty"`
	Message      *Message `json:"message,omitempty"`
	Delta        *Message `json:"delta,omitempty"`
	FinishReason string   `json:"finish_reason,omitempty"`
}

type CreateChatCompletionsRequest

type CreateChatCompletionsRequest struct {
	Model            string               `json:"model,omitempty"`
	Messages         []Message            `json:"messages,omitempty"`
	Functions        []CompletionFunction `json:"functions,omitempty"`
	FunctionCall     *string              `json:"function_call,omitempty"`
	Temperature      float64              `json:"temperature,omitempty"`
	TopP             float64              `json:"top_p,omitempty"`
	N                int                  `json:"n,omitempty"`
	Stream           bool                 `json:"stream,omitempty"`
	Stop             StrArray             `json:"stop,omitempty"`
	MaxTokens        int                  `json:"max_tokens,omitempty"`
	PresencePenalty  float64              `json:"presence_penalty,omitempty"`
	FrequencyPenalty float64              `json:"frequency_penalty,omitempty"`
	LogitBias        map[string]string    `json:"logit_bias,omitempty"`
	User             string               `json:"user,omitempty"`
	ResponseFormat   ResponseFormat       `json:"response_format,omitempty"`
	Seed             int                  `json:"seed,omitempty"`
}

type CreateChatCompletionsResponse

type CreateChatCompletionsResponse struct {
	ID                string                        `json:"id,omitempty"`
	Object            string                        `json:"object,omitempty"`
	Created           int                           `json:"created,omitempty"`
	Model             string                        `json:"model,omitempty"`
	Choices           []CreateChatCompletionsChoice `json:"choices,omitempty"`
	Usage             CreateChatCompletionsUsage    `json:"usage,omitempty"`
	SystemFingerprint string                        `json:"system_fingerprint,omitempty"`
}

type CreateChatCompletionsUsage

type CreateChatCompletionsUsage struct {
	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens,omitempty"`
}

type Error

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

Error is the error standard response from the API

func (*Error) Error

func (e *Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Error *Error `json:"error,omitempty"`
}

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Message

type Message struct {
	Role         string        `json:"role,omitempty"`
	Content      string        `json:"content,omitempty"`
	FunctionCall *FunctionCall `json:"function_call,omitempty"`
}

type OpenAiClient

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

func NewOpenAiClient

func NewOpenAiClient(apiKey, organization, model string) *OpenAiClient

NewOpenAiClient creates a new client

func (*OpenAiClient) Call

func (c *OpenAiClient) Call(ctx context.Context, method string, url string, body io.Reader) (response *http.Response, err error)

Call makes a request

func (*OpenAiClient) CreateChatCompletions

func (c *OpenAiClient) CreateChatCompletions(ctx context.Context, r *CreateChatCompletionsRequest) (response *CreateChatCompletionsResponse, err error)

func (*OpenAiClient) CreateChatCompletionsRaw

func (c *OpenAiClient) CreateChatCompletionsRaw(ctx context.Context, r *CreateChatCompletionsRequest) ([]byte, error)

func (*OpenAiClient) Get

func (c *OpenAiClient) Get(ctx context.Context, url string, input any) (response []byte, err error)

Get makes a get request

func (*OpenAiClient) Post

func (c *OpenAiClient) Post(ctx context.Context, url string, input any) (response []byte, err error)

Post makes a post request

type OpenAiModel

type OpenAiModel struct {
	Client *OpenAiClient
}

func NewModel

func NewModel(apiKey, organization, model string) *OpenAiModel

func (*OpenAiModel) Inference

func (m *OpenAiModel) Inference(ctx context.Context, input string) (string, error)

type ResponseFormat

type ResponseFormat struct {
	Type string `json:"type"`
}

type StrArray

type StrArray []string

func (*StrArray) UnmarshalJSON

func (sa *StrArray) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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