generic

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package generic provides a generic OpenAI-compatible backend for custom providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter implements the generic OpenAI-compatible backend for "custom" providers.

func (*Adapter) Complete

func (a *Adapter) Complete(
	ctx context.Context,
	creds []*models.Credential,
	req *models.ChatCompletionRequest,
	providerConfig map[string]any,
) (*models.ChatCompletionResponse, error)

func (*Adapter) CompleteStream

func (a *Adapter) CompleteStream(
	ctx context.Context,
	creds []*models.Credential,
	req *models.ChatCompletionRequest,
	w io.Writer,
	providerConfig map[string]any,
) error

func (*Adapter) GetModelInfos

func (a *Adapter) GetModelInfos(
	ctx context.Context,
	cred *models.Credential,
	providerConfig map[string]any,
) ([]models.ModelInfo, error)

func (*Adapter) NeedsRefresh

func (a *Adapter) NeedsRefresh(cred *models.Credential) bool

func (*Adapter) RefreshCredential

func (a *Adapter) RefreshCredential(ctx context.Context, cred *models.Credential) (map[string]any, error)

func (*Adapter) SetLogger added in v0.1.2

func (a *Adapter) SetLogger(l *slog.Logger)

SetLogger wires the logger for pool failover lines. Unset falls back to slog.Default inside the pool.

func (*Adapter) SetUsageTracker added in v0.0.6

func (a *Adapter) SetUsageTracker(t UsageTracker)

SetUsageTracker wires per-credential usage accounting for pool calls. Unset (nil) disables accounting; attempts still run.

func (*Adapter) TypeKey

func (a *Adapter) TypeKey() string

func (*Adapter) ValidateCredentials

func (a *Adapter) ValidateCredentials(data map[string]any) error

type Client

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

Client wraps HTTP requests to an OpenAI-compatible endpoint.

func (*Client) ChatCompletion

func (c *Client) ChatCompletion(
	ctx context.Context,
	apiKey string,
	modelName string,
	req *models.ChatCompletionRequest,
) (*models.ChatCompletionResponse, error)

ChatCompletion sends a non-streaming chat completion request.

func (*Client) ChatCompletionStream

func (c *Client) ChatCompletionStream(
	ctx context.Context,
	apiKey string,
	modelName string,
	req *models.ChatCompletionRequest,
	w io.Writer,
) error

ChatCompletionStream sends a streaming chat completion request.

func (*Client) ListModels

func (c *Client) ListModels(ctx context.Context, apiKey string) ([]models.ModelInfo, error)

ListModels fetches the available models from the provider. Tolerant of compat variances: 404 is not an error (routing still works), extra fields like object/limit are ignored.

type UsageTracker added in v0.0.6

type UsageTracker = pool.UsageTracker

UsageTracker records per-credential outcomes. It is implemented by the credential pool service and injected via SetUsageTracker.

Jump to

Keyboard shortcuts

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