Documentation
¶
Overview ¶
Package openai implements a generic OpenAI-compatible provider for any /v1/chat/completions endpoint.
Index ¶
- type Client
- func (c *Client) Chat(ctx context.Context, req request.Request, streamFunc stream.Func) (message.Message, usage.Usage, error)
- func (c *Client) Embed(ctx context.Context, req embedding.Request) (embedding.Response, usage.Usage, error)
- func (c *Client) Estimate(ctx context.Context, req request.Request, content string) (int, error)
- func (c *Client) List(ctx context.Context) (model.Models, error)
- func (c *Client) Model(ctx context.Context, name string) (model.Model, error)
- func (c *Client) Models(ctx context.Context) (model.Models, error)
- func (c *Client) Synthesize(ctx context.Context, req synthesize.Request) (synthesize.Response, error)
- func (c *Client) Transcribe(ctx context.Context, req transcribe.Request) (transcribe.Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client wraps the OpenAI SDK client with Fantasy for chat.
func New ¶
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 ¶
func (c *Client) Embed(ctx context.Context, req embedding.Request) (embedding.Response, usage.Usage, error)
Embed generates embeddings for the given input texts.
func (*Client) Estimate ¶
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) 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.