openaiwrap

package
v0.14.0-nightly.20250326 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallWithRetry

func CallWithRetry[T any](ctx context.Context, config Config, caller OpenaiCaller[T], payload string) (T, error)

CallWithRetry handles retrying API calls with exponential backoff. This is meant to be used with openai api calls.

func ProcessRecordField

func ProcessRecordField[T any](
	ctx context.Context,
	rec opencdc.Record,
	resolver sdk.ReferenceResolver,
	processor func(ctx context.Context, input string) (T, error),
	formatter func(T) ([]byte, error),
) (opencdc.Record, error)

func TestRecords

func TestRecords() []opencdc.Record

Types

type Config

type Config struct {
	// MaxRetries is the maximum number of retries for API calls. Defaults to 3.
	MaxRetries int `json:"max_retries" default:"3"`
	// InitialBackoff is the initial backoff duration in milliseconds. Defaults to 1000ms (1s).
	InitialBackoff int `json:"initial_backoff" default:"1000"`
	// MaxBackoff is the maximum backoff duration in milliseconds. Defaults to 30000ms (30s).
	MaxBackoff int `json:"max_backoff" default:"30000"`
	// BackoffFactor is the factor by which the backoff increases. Defaults to 2.0
	BackoffFactor float64 `json:"backoff_factor" default:"2.0"`
}

Config contains common configuration options for OpenAI processors

type FlakyEmbeddingsCaller

type FlakyEmbeddingsCaller struct {
	CallCount  int
	Embeddings []float32
}

func (*FlakyEmbeddingsCaller) Call

func (f *FlakyEmbeddingsCaller) Call(ctx context.Context, input string) ([]float32, error)

type FlakyOpenAICaller

type FlakyOpenAICaller struct {
	CallCount int
}

func (*FlakyOpenAICaller) Call

func (f *FlakyOpenAICaller) Call(ctx context.Context, input string) (string, error)

type MockEmbeddingsCaller

type MockEmbeddingsCaller struct {
	Embeddings []float32
}

func (*MockEmbeddingsCaller) Call

func (m *MockEmbeddingsCaller) Call(ctx context.Context, input string) ([]float32, error)

type OpenaiCaller

type OpenaiCaller[T any] interface {
	Call(ctx context.Context, input string) (T, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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