openai

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package openai provides a client wrapper for the OpenAI API that complies with the ai.Provider interface.

Index

Constants

View Source
const DefaultModel = "gpt-4o"

DefaultModel is the default model to use when making requests to the OpenAI API.

View Source
const ErrInvalidRequest xerrors.Error = "invalid request: must provide either an image or text"

ErrInvalidRequest is returned when the request provided to the OpenAI API is missing both an image and text.

Variables

This section is empty.

Functions

func NewRequest

func NewRequest(req *ai.Request) openai.ChatCompletionRequest

NewTextRequest creates a chat completion request with streaming support for the OpenAI API given the provided ai.Request object.

func NewRequestWithImage

func NewRequestWithImage(req *ai.Request) openai.ChatCompletionRequest

NewRequestWithImage creates a chat completion request with streaming support for the OpenAI API given the provided ai.Request object. The req.Content field should be a base64-encoded image.

Types

type Client

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

Client represents an OpenAI API client that complies with the ai.Provider interface.

func NewClient

func NewClient(key string) *Client

NewClient returns a new Client instance with the given API key.

func (*Client) Do

func (c *Client) Do(ctx *cli.Context, request *ai.Request) error

Do performs a single API request to the OpenAI API, returning a response for the provided Request and writing said response to ctx.App.Writer as a stream of strings.

func (*Client) Name

func (*Client) Name() string

Name returns the name of the provider.

Jump to

Keyboard shortcuts

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