openai

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OPENAI = "openai"
	AZURE  = "azure"
)

Variables

View Source
var DefaultModel = openai.GPT3Dot5Turbo

DefaultModel is the default OpenAI model to use if one is not provided.

View Source
var SummaryPrefixFunc = openai.FunctionDefinition{
	Name: "get_summary_prefix",
	Parameters: jsonschema.Definition{
		Type: jsonschema.Object,
		Properties: map[string]jsonschema.Definition{
			"prefix": {
				Type: jsonschema.String,
				Enum: []string{
					"build", "chore", "ci",
					"docs", "feat", "fix",
					"perf", "refactor", "style",
					"test",
				},
			},
		},
		Required: []string{"prefix"},
	},
}

SummaryPrefixFunc is a openai function definition.

Functions

func GetModel

func GetModel(model string) string

GetModel returns the model ID corresponding to the given model name. If the model name is not recognized, it returns the default model ID.

func NewHeaders

func NewHeaders(headers []string) http.Header

NewHeaders creates a new http.Header from the given slice of headers.

Types

type Client

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

Client is a struct that represents an OpenAI client.

func New

func New(opts ...Option) (*Client, error)

New creates a new OpenAI API client with the given options.

func (*Client) AllowFuncCall

func (c *Client) AllowFuncCall() bool

AllowFuncCall returns true if the model supports function calls. In an API call, you can describe functions to gpt-3.5-turbo-0613 and gpt-4-0613 https://platform.openai.com/docs/guides/gpt/chat-completions-api

func (*Client) Completion

func (c *Client) Completion(
	ctx context.Context,
	content string,
) (*Response, error)

Completion is a method on the Client struct that takes a context.Context and a string argument and returns a string and an error.

func (*Client) CreateChatCompletion

func (c *Client) CreateChatCompletion(
	ctx context.Context,
	content string,
) (resp openai.ChatCompletionResponse, err error)

CreateChatCompletion is an API call to create a completion for a chat message.

func (*Client) CreateCompletion

func (c *Client) CreateCompletion(
	ctx context.Context,
	content string,
) (resp openai.CompletionResponse, err error)

CreateCompletion is an API call to create a completion. This is the main endpoint of the API. It returns new text, as well as, if requested, the probabilities over each alternative token at each position.

If using a fine-tuned model, simply provide the model's ID in the CompletionRequest object, and the server will use the model's parameters to generate the completion.

func (*Client) CreateFunctionCall

func (c *Client) CreateFunctionCall(
	ctx context.Context,
	content string,
	funcs ...openai.FunctionDefinition,
) (resp openai.ChatCompletionResponse, err error)

CreateChatCompletion is an API call to create a function call for a chat message.

type DefaultHeaderTransport

type DefaultHeaderTransport struct {
	Origin http.RoundTripper
	Header http.Header
}

DefaultHeaderTransport is an http.RoundTripper that adds the given headers to

func (*DefaultHeaderTransport) RoundTrip

func (t *DefaultHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is an interface that specifies instrumentation configuration options.

func WithApiVersion

func WithApiVersion(apiVersion string) Option

WithApiVersion returns a new Option that sets the apiVersion for OpenAI Model.

func WithBaseURL

func WithBaseURL(val string) Option

WithBaseURL returns a new Option that sets the base URL for the client configuration. It takes a string value representing the base URL to use for requests. It returns an optionFunc that sets the baseURL field of the configuration to the provided

func WithFrequencyPenalty

func WithFrequencyPenalty(val float32) Option

WithFrequencyPenalty returns a new Option that sets the frequencyPenalty for the client configuration.

func WithHeaders

func WithHeaders(headers []string) Option

WithHeaders returns a new Option that sets the headers for the http client configuration.

func WithMaxTokens

func WithMaxTokens(val int) Option

WithMaxTokens returns a new Option that sets the max tokens for the client configuration. The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length.

func WithModel

func WithModel(val string) Option

WithModel is a function that returns an Option, which sets the model field of the config struct.

func WithModelName

func WithModelName(val string) Option

WithModelName sets the `modelName` variable to the provided `val` parameter. This function returns an `Option` object.

func WithOrgID

func WithOrgID(val string) Option

WithOrgID is a function that returns an Option, which sets the orgID field of the config struct.

func WithPresencePenalty

func WithPresencePenalty(val float32) Option

WithPresencePenalty returns a new Option that sets the presencePenalty for the client configuration.

func WithProvider

func WithProvider(val string) Option

WithProvider sets the `provider` variable based on the value of the `val` parameter. If `val` is not set to `OPENAI` or `AZURE`, it will be set to the default value `defaultProvider`. This function returns an `Option` object.

func WithProxyURL

func WithProxyURL(val string) Option

WithProxyURL is a function that returns an Option, which sets the proxyURL field of the config struct.

func WithSkipVerify

func WithSkipVerify(val bool) Option

WithSkipVerify returns a new Option that sets the skipVerify for the client configuration.

func WithSocksURL

func WithSocksURL(val string) Option

WithSocksURL is a function that returns an Option, which sets the socksURL field of the config struct.

func WithTemperature

func WithTemperature(val float32) Option

WithTemperature returns a new Option that sets the temperature for the client configuration. What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

func WithTimeout

func WithTimeout(val time.Duration) Option

WithTimeout returns a new Option that sets the timeout for the client configuration. It takes a time.Duration value representing the timeout duration. It returns an optionFunc that sets the timeout field of the configuration to the provided value.

func WithToken

func WithToken(val string) Option

WithToken is a function that returns an Option, which sets the token field of the config struct.

func WithTopP

func WithTopP(val float32) Option

WithTopP returns a new Option that sets the topP for the client configuration.

type Response

type Response struct {
	Content string
	Usage   openai.Usage
}

type SummaryPrefixParams

type SummaryPrefixParams struct {
	Prefix string `json:"prefix"`
}

SummaryPrefixParams is a struct that stores configuration options for the get_summary_prefix function.

func GetSummaryPrefixArgs

func GetSummaryPrefixArgs(data string) SummaryPrefixParams

GetSummaryPrefixArgs returns the SummaryPrefixParams struct corresponding to the given JSON data.

Jump to

Keyboard shortcuts

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