openai

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

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

OpenAIBackend is the default URI endpoint for the OpenAI API.

Variables

View Source
var (
	// ModelGPT35Turbo represents the gpt-3.5-turbo model used by ChatGPT
	ModelGPT35Turbo = types.Model{"gpt-3.5-turbo", 4096, types.ModelTypeChat}

	// ModelGPT35Turbo represents the gpt-3.5-turbo-0301 model, a March 1st 2023
	// snapshot of gpt-3.5-turbo
	ModelGPT35Turbo0301 = types.Model{"gpt-3.5-turbo-0301", 4096, types.ModelTypeChat}

	// ModelGPT4 represents the gpt-4 model
	ModelGPT4 = types.Model{"gpt-4", 8192, types.ModelTypeChat}

	// ModelGPT40314 represents the gpt-4-0314 model, a March 14th 2023 snapshot
	// of the gpt-4 model.
	ModelGPT40314 = types.Model{"gpt-4-0314", 8192, types.ModelTypeChat}

	// ModelGPT432K represents the gpt-4-32k model, which is the same as gpt-4,
	// but with 4x the context length.
	ModelGPT432K = types.Model{"gpt-4-32k", 32768, types.ModelTypeChat}

	// ModelGPT432K0314 represents the gpt-4-32k-0314 model, a March 14th 2023
	// snapshot of the gpt-4-32k model
	ModelGPT432K0314 = types.Model{"gpt-4-32k-0314", 32768, types.ModelTypeChat}

	// SupportedModels is a list of all language models supported by this
	// backend implementation.
	SupportedModels = []types.Model{
		ModelGPT35Turbo,
		ModelGPT35Turbo0301,
		ModelGPT4,
		ModelGPT40314,
		ModelGPT432K,
		ModelGPT432K0314,
	}
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*requests.HTTPClient
	// contains filtered or unexported fields
}

Client is a structure used to continuously generate IaC code via OpenAPI

func NewClient

func NewClient(opts *NewClientOptions) *Client

NewClient creates a new instance of the Client struct, with the provided input options. The OpenAI API backend is not yet contacted at this point.

func (*Client) Chat

func (client *Client) Chat(model types.Model) types.Conversation

Chat initiates a conversation with an OpenAI chat model. A conversation maintains context, allowing to send further instructions to modify the output from previous requests, just like using the ChatGPT website.

func (*Client) Complete

func (client *Client) Complete(
	ctx context.Context,
	model types.Model,
	prompt string,
) (res types.Response, err error)

Complete sends a request to OpenAI's Completions API using the provided model and prompt, and returns the response

func (*Client) DefaultModel

func (client *Client) DefaultModel() types.Model

DefaultModel returns the default model used by this backend.

func (*Client) ListModels

func (client *Client) ListModels() []types.Model

ListModels returns a list of all the models supported by this backend implementation.

type Conversation

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

Conversation is a struct used to converse with an OpenAI chat model. It maintains all messages sent/received in order to maintain context just like using ChatGPT.

func (*Conversation) Send

func (conv *Conversation) Send(ctx context.Context, prompt string, msgs ...types.Message) (
	res types.Response,
	err error,
)

Send sends the provided message to the API and returns a Response object. To maintain context, all previous messages (whether from you to the API or vice-versa) are sent as well, allowing you to ask the API to modify the code it already generated.

type NewClientOptions

type NewClientOptions struct {
	// APIKey is the OpenAI API key to use for requests. This is required.
	ApiKey string

	// URL is the OpenAI API URL to userequests. Optional, defaults to OpenAIBackend.
	URL string

	// APIVersion is the version of the OpenAI API to use. Optional.
	APIVersion string
}

NewClientOptions is a struct containing all the parameters accepted by the NewClient constructor.

Jump to

Keyboard shortcuts

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