openai

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package openai implements a generic OpenAI-compatible provider for any /v1/chat/completions endpoint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	openai.Client

	HTTPClient *http.Client

	Fantasy fantasy.Provider
}

Client wraps the OpenAI SDK client with Fantasy for chat.

func New

func New(baseURL, token string, timeout time.Duration) *Client

New creates an OpenAI-compatible client for the given base URL, token, and response timeout. If baseURL is empty, defaults to the OpenAI API.

func (*Client) Chat

func (c *Client) Chat(
	ctx context.Context,
	req request.Request,
	streamFunc stream.Func,
) (message.Message, usage.Usage, error)

Chat sends a streaming request via Fantasy using the Responses API.

func (*Client) Embed

Embed generates embeddings for the given input texts.

func (*Client) Estimate

func (c *Client) Estimate(ctx context.Context, req request.Request, content string) (int, error)

Estimate tokenizes content using OpenAI's InputTokens.Count API. Passes the raw text string as input and returns the exact token count from the model's tokenizer. Falls back to local estimation on any error.

func (*Client) List

func (c *Client) List(ctx context.Context) (model.Models, error)

List fetches the list of available models using the OpenAI SDK.

func (*Client) Model

func (c *Client) Model(ctx context.Context, name string) (model.Model, error)

Model fetches metadata for the specified model.

func (*Client) Models

func (c *Client) Models(ctx context.Context) (model.Models, error)

Models fetches all available models from the OpenAI-compatible API.

func (*Client) Synthesize

func (c *Client) Synthesize(ctx context.Context, req synthesize.Request) (synthesize.Response, error)

Synthesize converts text to speech audio via the TTS endpoint.

func (*Client) Transcribe

func (c *Client) Transcribe(ctx context.Context, req transcribe.Request) (transcribe.Response, error)

Transcribe sends an audio file to the server for speech-to-text transcription.

Jump to

Keyboard shortcuts

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