openai

package
v1.36.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertParametersToSchema

func ConvertParametersToSchema(params any) (shared.FunctionParameters, error)

ConvertParametersToSchema converts parameters to OpenAI Schema format

Types

type Client

type Client struct {
	base.Config
	// contains filtered or unexported fields
}

Client represents an OpenAI client wrapper. It implements the provider.Provider interface.

func NewClient

func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, opts ...options.Opt) (*Client, error)

NewClient creates a new OpenAI client from the provided configuration

func (*Client) Close added in v1.36.0

func (c *Client) Close()

Close releases resources held by the client, including any pooled WebSocket connections. It is safe to call Close multiple times.

func (*Client) CreateBatchEmbedding

func (c *Client) CreateBatchEmbedding(ctx context.Context, texts []string) (*base.BatchEmbeddingResult, error)

CreateBatchEmbedding generates embedding vectors for multiple texts.

OpenAI supports up to 2048 inputs per request

func (*Client) CreateChatCompletionStream

func (c *Client) CreateChatCompletionStream(
	ctx context.Context,
	messages []chat.Message,
	requestTools []tools.Tool,
) (chat.MessageStream, error)

CreateChatCompletionStream creates a streaming chat completion request It returns a stream that can be iterated over to get completion chunks

func (*Client) CreateEmbedding

func (c *Client) CreateEmbedding(ctx context.Context, text string) (*base.EmbeddingResult, error)

CreateEmbedding generates an embedding vector for the given text

func (*Client) CreateResponseStream

func (c *Client) CreateResponseStream(
	ctx context.Context,
	messages []chat.Message,
	requestTools []tools.Tool,
) (chat.MessageStream, error)

func (*Client) Rerank

func (c *Client) Rerank(ctx context.Context, query string, documents []types.Document, criteria string) ([]float64, error)

Rerank scores documents by relevance to the query using an OpenAI chat model. It returns relevance scores in the same order as input documents.

type ResponseStreamAdapter

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

ResponseStreamAdapter adapts the OpenAI responses stream to our interface. It works with any responseEventStream implementation (SSE or WebSocket).

func (*ResponseStreamAdapter) Close

func (a *ResponseStreamAdapter) Close()

Close closes the stream

func (*ResponseStreamAdapter) Recv

Recv gets the next completion chunk

Jump to

Keyboard shortcuts

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