mod_body_process

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: 26 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

Index

Constants

View Source
const (
	ModBodyProcess               = "mod_body_process"
	BodyProcessResponseConfigKey = "mod_body_process.response_config"
)
View Source
const UnknownModel = "unknown"

Variables

This section is empty.

Functions

func BodyProcessConfigCheck

func BodyProcessConfigCheck(config *BodyProcessConfig) error

func EstimateContentToken added in v1.8.3

func EstimateContentToken(val string) int64

EstimateContentToken estimates the token count of a response body chunk (roughly 4 bytes per token). The implementation lives in bfe_model_protocol/utils and is kept re-exported here for compatibility.

func GetAuditData

func GetAuditData(ev Event) ([]byte, error)

func GetHTTPClient

func GetHTTPClient() *http.Client

func ProductRuleConfLoad

func ProductRuleConfLoad(filename string) (productRuleConf, error)

func SetAuditData

func SetAuditData(ev Event, data []byte) error

func SetHTTPClient

func SetHTTPClient(client *http.Client)

Types

type BPError added in v1.8.1

type BPError struct {
	Err error
}

func (*BPError) Error added in v1.8.1

func (e *BPError) Error() string

func (*BPError) Unwrap added in v1.8.1

func (e *BPError) Unwrap() error

type BodyProcessConfig

type BodyProcessConfig struct {
	Dec  string
	Enc  string
	Proc []ProcConf // processing steps
}

type BodyProcessor

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

BodyProcessor 扩展中断支持

func NewBodyProcessor

func NewBodyProcessor(source io.ReadCloser) *BodyProcessor

NewBodyProcessor 创建处理器

func (*BodyProcessor) AddProcessor

func (bp *BodyProcessor) AddProcessor(p EventProcessor)

func (*BodyProcessor) Close

func (bp *BodyProcessor) Close() error

Close 实现io.Closer接口

func (*BodyProcessor) CreateEventDecoder

func (bp *BodyProcessor) CreateEventDecoder(fac EventDecoderFac)

func (*BodyProcessor) CreateEventEncoder

func (bp *BodyProcessor) CreateEventEncoder(fac EventEncoderFac)

func (*BodyProcessor) FillBuffer

func (bp *BodyProcessor) FillBuffer() error

FillBuffer 公开的缓冲区填充方法 安全地从源读取并处理一个数据块

func (*BodyProcessor) GetSource

func (bp *BodyProcessor) GetSource() io.ReadCloser

func (*BodyProcessor) OnReject

func (bp *BodyProcessor) OnReject(fn func(error, *BodyProcessor))

注册中断回调

func (*BodyProcessor) Read

func (bp *BodyProcessor) Read(p []byte) (n int, err error)

Read 实现io.Reader接口(支持中断)

func (*BodyProcessor) RejectionResponse

func (bp *BodyProcessor) RejectionResponse() *RejectionError

RejectionResponse 获取中断响应(如在反向代理中使用)

type ConfModBodyProcess

type ConfModBodyProcess struct {
	Basic struct {
		ProductRulePath string
	}

	Log struct {
		OpenDebug bool
	}
}

func ConfLoad

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

func (*ConfModBodyProcess) Check

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

type ContentAudit

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

func NewContentAudit

func NewContentAudit(urlStr string, replace bool) (*ContentAudit, error)

func (*ContentAudit) Process

func (caf *ContentAudit) Process(evs []Event) ([]Event, error)

type ContentTypeDecoder

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

func (*ContentTypeDecoder) Decode

func (ctd *ContentTypeDecoder) Decode() ([]Event, error)

type Event

type Event interface {
	// GetType() string
	// GetData() []byte
	ToBytes() []byte // 转换为字节数组

	// GetQuotaUsage extracts the quota usage of this event. authStyle is
	// the detected protocol/auth style of the request; it selects the
	// protocol adapter that decides stream termination and the final
	// usage event (unknown styles fall back to the openai adapter).
	GetQuotaUsage(authStyle string) QuotaUsage
}

type EventDecoder

type EventDecoder interface {
	// return:
	//  events, nil - len(events) > 0, success
	//  events, nil - len(events) = 0, 没有更多数据, eof
	//  nil, error - 发生错误
	Decode() ([]Event, error)
}

func NewContentTypeDecoder

func NewContentTypeDecoder(source io.Reader, contentType string) (EventDecoder, error)

func NewJsonDecoder

func NewJsonDecoder(source io.Reader) (EventDecoder, error)

func NewLineDecoder

func NewLineDecoder(source io.Reader) (EventDecoder, error)

func NewSSEEventDecoder

func NewSSEEventDecoder(source io.Reader) (EventDecoder, error)

type EventDecoderFac

type EventDecoderFac func(source io.Reader) (EventDecoder, error)

type EventDecoderFacWithReq

type EventDecoderFacWithReq func(source io.Reader, req bfe_basic.Request) (EventDecoder, error)

type EventEncoder

type EventEncoder interface {
	Encode(events []Event) (int, error)
}

func NewGeneralEncoder

func NewGeneralEncoder(dest io.Writer) (EventEncoder, error)

type EventEncoderFac

type EventEncoderFac func(dest io.Writer) (EventEncoder, error)

type EventProcessor

type EventProcessor interface {
	Process(events []Event) ([]Event, error)
}

type EventProcessorFunc

type EventProcessorFunc func([]Event) ([]Event, error)

ProcessorFunc 简化处理器实现

func (EventProcessorFunc) Process

func (f EventProcessorFunc) Process(events []Event) ([]Event, error)

type GeneralEncoder

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

func (*GeneralEncoder) Encode

func (enc *GeneralEncoder) Encode(events []Event) (int, error)

type JsonDecoder

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

func (*JsonDecoder) Decode

func (dec *JsonDecoder) Decode() ([]Event, error)

type LineDecoder

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

func (*LineDecoder) Decode

func (dec *LineDecoder) Decode() ([]Event, error)

type ModuleBodyProcess

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

func NewModuleBodyProcess

func NewModuleBodyProcess() *ModuleBodyProcess

func (*ModuleBodyProcess) DoRequestProcess

func (m *ModuleBodyProcess) DoRequestProcess(req *bfe_basic.Request, conf *BodyProcessConfig) *BodyProcessor

func (*ModuleBodyProcess) DoResponseProcess

func (m *ModuleBodyProcess) DoResponseProcess(req *bfe_basic.Request, res *bfe_http.Response, conf *BodyProcessConfig) *BodyProcessor

func (*ModuleBodyProcess) Init

func (*ModuleBodyProcess) Name

func (m *ModuleBodyProcess) Name() string

type ModuleBodyProcessState

type ModuleBodyProcessState struct {
	ReqTotal   *metrics.Counter
	ReqProcess *metrics.Counter
	ResProcess *metrics.Counter
	InFlight   *metrics.Gauge
}

type ProcConf

type ProcConf struct {
	Name   string
	Params []string
}

type ProcessRuleTable

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

func NewTokenRuleTable

func NewTokenRuleTable() *ProcessRuleTable

func (*ProcessRuleTable) Search

func (t *ProcessRuleTable) Search(product string) (processRuleList, bool)

func (*ProcessRuleTable) Update

func (t *ProcessRuleTable) Update(conf productRuleConf)

type ProductRules

type ProductRules map[string]processRuleList

type ProductRulesFile

type ProductRulesFile map[string]processRuleFileList

type QuotaUsage added in v1.8.3

type QuotaUsage struct {
	//return from reponse
	PromptTokens       int64 // number of tokens in the prompt
	CompletionTokens   int64 // number of tokens in the completion
	CacheReadTokens    int64 // usage.cache_read_tokens, already included in PromptTokens
	CacheWriteTokens   int64 // usage.cache_write_tokens, already included in PromptTokens (normalized for Anthropic)
	CacheWriteTokens1h int64 // 1h-TTL cache write tokens (usage.cache_creation.ephemeral_1h_input_tokens), already included in CacheWriteTokens
	AudioInputTokens   int64 // usage.audio_input_tokens, already included in PromptTokens
	AudioOutputTokens  int64 // usage.audio_output_tokens, already included in CompletionTokens
	ImageInputTokens   int64 // usage.image_input_tokens / input_token_details.image_tokens, already included in PromptTokens
	VideoCount         int64 // number of generated videos for video generation models
	ImageCount         int64 // number of generated images for image generation models
	UsedQuota          int64 // used quota for this request

	// Usage presence (issue #1414): whether this event carried a usage object
	// at all, and whether that object carried the prompt/input token field.
	// Classification and billing decisions key on these instead of "some
	// value is > 0", so an upstream that explicitly reports all-zero usage is
	// told apart from one that reports no usage.
	UsagePresent  bool
	PromptPresent bool

	//estimate for current response
	CurrentTokens int64 //effect when IsGuess is true
	IsGuess       bool  //true = is estimate: this event carries no usage object

	//response completion status (issue #1352)
	IsFinalUsage  bool //true = this event carries the final usage of the response
	IsTermination bool //true = this event terminates the response stream (message_stop, [DONE])
}

type QuotaUsageProcessor added in v1.8.4

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

calc quota in response stage

func NewQuotaUsageProcessor added in v1.8.4

func NewQuotaUsageProcessor(req *bfe_basic.Request, res *bfe_http.Response) *QuotaUsageProcessor

func (*QuotaUsageProcessor) Process added in v1.8.4

func (caf *QuotaUsageProcessor) Process(events []Event) ([]Event, error)

type RawEvent

type RawEvent []byte

func (*RawEvent) GetQuotaUsage added in v1.8.4

func (e *RawEvent) GetQuotaUsage(authStyle string) QuotaUsage

func (*RawEvent) ToBytes

func (e *RawEvent) ToBytes() []byte

type RejectionError

type RejectionError struct {
	Message    string
	StatusCode int
}

RejectionError 自定义错误类型

func (*RejectionError) Error

func (e *RejectionError) Error() string

type SSEEvent

type SSEEvent struct {
	ID        *string
	Event     *string
	DataLines [][]byte
	Retry     *int
	Comments  [][]byte
	RawLines  [][]byte
	// contains filtered or unexported fields
}

func (*SSEEvent) AppendDataLine added in v1.8.3

func (e *SSEEvent) AppendDataLine(b []byte)

func (*SSEEvent) GetAuditData added in v1.8.3

func (e *SSEEvent) GetAuditData() []byte

func (*SSEEvent) GetData added in v1.8.3

func (e *SSEEvent) GetData() []byte

func (*SSEEvent) GetQuotaUsage added in v1.8.3

func (e *SSEEvent) GetQuotaUsage(authStyle string) QuotaUsage

func (*SSEEvent) SetData added in v1.8.3

func (e *SSEEvent) SetData(v []byte)

func (*SSEEvent) SetEvent added in v1.8.3

func (e *SSEEvent) SetEvent(v *string)

func (*SSEEvent) SetID added in v1.8.3

func (e *SSEEvent) SetID(v *string)

func (*SSEEvent) SetJsonField added in v1.8.3

func (e *SSEEvent) SetJsonField(jpath string, newValue string) error

func (*SSEEvent) ToBytes

func (e *SSEEvent) ToBytes() []byte

type SSEEventDecoder

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

func (*SSEEventDecoder) Decode

func (d *SSEEventDecoder) Decode() ([]Event, error)

type TextFilterContactItem

type TextFilterContactItem struct {
	ContactType   string
	ContactString string
	Position      string
}

type TextFilterDetailItem

type TextFilterDetailItem struct {
	RiskLevel string
	RiskCode  string
	Position  string
	Text      string
}

type TextFilterResult

type TextFilterResult struct {
	Code           int32
	Message        string
	RequestId      string
	RiskLevel      string
	RiskCode       string
	SentimentScore float32
	ResultText     string

	Details  []TextFilterDetailItem
	Contacts []TextFilterContactItem
}

Jump to

Keyboard shortcuts

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