batch

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBatchClosed  = errors.New("batch processor closed")
	ErrBatchTimeout = errors.New("batch timeout")
	ErrBatchFull    = errors.New("batch queue full")
)

Functions

This section is empty.

Types

type BatchConfig

type BatchConfig struct {
	MaxBatchSize   int           `json:"max_batch_size"`
	MaxWaitTime    time.Duration `json:"max_wait_time"`
	QueueSize      int           `json:"queue_size"`
	Workers        int           `json:"workers"`
	RetryOnFailure bool          `json:"retry_on_failure"`
}

BatchConfig 配置批处理器。

func DefaultBatchConfig

func DefaultBatchConfig() BatchConfig

默认BatchConfig 返回合理的默认值 。

type BatchHandler

type BatchHandler func(ctx context.Context, requests []*Request) []*Response

BatchHandler处理一批请求.

type BatchProcessor

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

批量处理器为高效处理而批出多个LLM请求.

func NewBatchProcessor

func NewBatchProcessor(config BatchConfig, handler BatchHandler) *BatchProcessor

NewBatchProcessor创建了新的分批处理器.

func (*BatchProcessor) Close

func (bp *BatchProcessor) Close()

关闭批量处理器 。

func (*BatchProcessor) Stats

func (bp *BatchProcessor) Stats() BatchStats

Stats 返回处理器统计 。

func (*BatchProcessor) Submit

func (bp *BatchProcessor) Submit(ctx context.Context, req *Request) <-chan *Response

提交请求并返回响应的通道 。

func (*BatchProcessor) SubmitSync

func (bp *BatchProcessor) SubmitSync(ctx context.Context, req *Request) (*Response, error)

SontentSync 提交请求并等待回复.

type BatchStats

type BatchStats struct {
	Submitted int64 `json:"submitted"`
	Batched   int64 `json:"batched"`
	Completed int64 `json:"completed"`
	Failed    int64 `json:"failed"`
	Queued    int   `json:"queued"`
}

BatchStats包含处理器统计.

func (BatchStats) BatchEfficiency

func (s BatchStats) BatchEfficiency() float64

批量效果返回平均批量大小 。

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message 表示聊天消息.

type Request

type Request struct {
	ID       string         `json:"id"`
	Model    string         `json:"model"`
	Messages []Message      `json:"messages"`
	Params   map[string]any `json:"params,omitempty"`
}

请求是一组中单个LLM请求.

type Response

type Response struct {
	ID      string `json:"id"`
	Content string `json:"content"`
	Error   error  `json:"error,omitempty"`
	Tokens  int    `json:"tokens"`
}

Response 表示单个 LLM 响应.

Jump to

Keyboard shortcuts

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