mod_ai_batch

package
v1.8.9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mod_ai_batch implements OpenAI Batch API (/v1/files, /v1/batches) passthrough support: operation classification, upload line/byte counting, response field extraction, batch-level key affinity bindings, and the reserve/settle/release orchestration of post-paid batch quota. Request and response bodies are never rewritten; batch traffic streams end to end without retry buffering (see bfe_server.isBatchPassthroughMode).

Index

Constants

View Source
const (
	OwnerCheckMissAllowLog = "allow_log" // pass through + counter (default)
	OwnerCheckMissDeny     = "deny"      // reject with 404
)

OwnerCheckMiss policies for downloads whose BATCH_FILE binding is missing (expired TTL, Redis write failure at upload, etc.).

View Source
const (
	ModAiBatch = "mod_ai_batch"
)

Variables

This section is empty.

Functions

func BatchActiveCount

func BatchActiveCount(apiKeyId string) int64

BatchActiveCount returns the number of in-flight batches of the apikey (entries older than the 24h completion window are purged first).

func BatchGlobalFileCeilings

func BatchGlobalFileCeilings() (int64, int64)

BatchGlobalFileCeilings returns the global hard ceilings (maxFileBytes, maxFileLines); 0 or negative means the ceiling is disabled.

Types

type BatchDataConf

type BatchDataConf struct {
	Version string `json:"Version"`

	// MaxFileBytes/MaxFileLines are the global hard ceilings, enforced on
	// both upload and download. 0 or negative disables the ceiling (not
	// recommended for production).
	MaxFileBytes int64 `json:"MaxFileBytes"`
	MaxFileLines int64 `json:"MaxFileLines"`

	// Reserve estimation defaults used when the price row carries no
	// limits.max_input_tokens/max_output_tokens (see mod_ai_token_auth).
	ReserveInputTokens  int64 `json:"ReserveInputTokens"`
	ReserveOutputTokens int64 `json:"ReserveOutputTokens"`
	// ReservePerLineMicros is the RMB reserve per input line in 1e-6 yuan
	// (micros). The model-specific usage is priced exactly at settle time
	// from the result file; this per-line reference only sizes the reserve.
	ReservePerLineMicros int64 `json:"ReservePerLineMicros"`

	// MaxLineParseBytes bounds the per-line parse buffer when scanning a
	// batch result file for usage (guards against abnormal lines).
	MaxLineParseBytes int64 `json:"MaxLineParseBytes"`

	// OwnerCheckMissPolicy: allow_log (default) | deny.
	OwnerCheckMissPolicy string `json:"OwnerCheckMissPolicy"`
}

BatchDataConf is the hot-reloadable configuration (mod_ai_batch.data). Effective per-request file limits are min(bound rate-limit policies' batch_limits, these global hard ceilings); see mod_ai_rate_limit.

type ConfModAiBatch

type ConfModAiBatch struct {
	Basic struct {
		ProductRulePath string // path for mod_ai_batch.data
	}

	// redis conf for BATCH_* state keys (same cluster as QUOTA_* and the
	// AIKeyAffinity bindings). Empty Bns disables batch state/affinity
	// (fail-open: passthrough continues, counters record the misses).
	Redis struct {
		Bns            string // bns name for redis proxy
		ConnectTimeout int    // connect timeout (ms)
		ReadTimeout    int    // read timeout (ms)
		WriteTimeout   int    // write timeout (ms)
		MaxIdle        int    // max idle connections in pool
		MaxActive      int    // max active connections in pool, 0 = unlimited
		Password       string // redis password, ignore if not set
	}

	Log struct {
		OpenDebug bool // whether open debug
	}
}

ConfModAiBatch is the startup-fixed configuration of mod_ai_batch. All tunable knobs live in the hot-reloadable mod_ai_batch.data instead: in this codebase .conf files are loaded once at Init (reloadHandlers only cover the .data file), and these batch knobs are expected to be tuned while the batch feature is being rolled out.

func ConfLoad

func ConfLoad(filePath string, confRoot string) (*ConfModAiBatch, error)

load config from config file

func (*ConfModAiBatch) Check

func (cfg *ConfModAiBatch) Check(confRoot string) error

type ModuleAiBatch

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

func NewModuleAiBatch

func NewModuleAiBatch() *ModuleAiBatch

func (*ModuleAiBatch) Init

func (*ModuleAiBatch) Name

func (m *ModuleAiBatch) Name() string

Jump to

Keyboard shortcuts

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