generic

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 10 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{}

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

func (*Adapter) Complete

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

func (*Adapter) CompleteStream

func (a *Adapter) CompleteStream(
	ctx context.Context,
	cred *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) 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.

Jump to

Keyboard shortcuts

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