batch

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package batch provides batch processing for multiple LLM requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	TenantID    string         `json:"tenant_id,omitempty"`
	Inputs      []Input        `json:"inputs"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	Concurrency int            `json:"concurrency,omitempty"` // max parallel requests
}

CreateInput defines a new batch job.

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Error describes a batch item failure.

type Executor

type Executor interface {
	Execute(ctx context.Context, req *provider.CompletionRequest) (*provider.CompletionResponse, error)
}

Executor processes individual batch requests.

type Input

type Input struct {
	CustomID string                      `json:"custom_id"`
	Request  *provider.CompletionRequest `json:"request"`
}

Input is a single item in a batch job.

type Job

type Job struct {
	ID          string         `json:"id"`
	TenantID    string         `json:"tenant_id,omitempty"`
	Status      JobStatus      `json:"status"`
	Inputs      []Input        `json:"inputs"`
	Results     []Result       `json:"results,omitempty"`
	TotalItems  int            `json:"total_items"`
	Completed   int            `json:"completed"`
	Failed      int            `json:"failed"`
	CreatedAt   time.Time      `json:"created_at"`
	StartedAt   *time.Time     `json:"started_at,omitempty"`
	CompletedAt *time.Time     `json:"completed_at,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

Job represents a batch processing job.

type JobStatus

type JobStatus string

JobStatus represents the state of a batch job.

const (
	JobPending   JobStatus = "pending"
	JobRunning   JobStatus = "running"
	JobCompleted JobStatus = "completed"
	JobFailed    JobStatus = "failed"
	JobCancelled JobStatus = "cancelled"
)

type Result

type Result struct {
	CustomID string                       `json:"custom_id"`
	Response *provider.CompletionResponse `json:"response,omitempty"`
	Error    *Error                       `json:"error,omitempty"`
}

Result is the outcome of a single batch item.

type Service

type Service interface {
	// Create creates a new batch job.
	Create(ctx context.Context, input *CreateInput) (*Job, error)

	// Get returns a batch job by ID.
	Get(ctx context.Context, jobID string) (*Job, error)

	// Cancel cancels a running batch job.
	Cancel(ctx context.Context, jobID string) error

	// List returns batch jobs for a tenant.
	List(ctx context.Context, tenantID string) ([]*Job, error)
}

Service manages batch processing jobs.

func NewService

func NewService(executor Executor, concurrency int) Service

NewService creates a new batch service.

Jump to

Keyboard shortcuts

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