helper

package
v1.0.4-preview.5 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: AGPL-3.0 Imports: 29 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 (
	InitialScannerBufferSize    = 64 << 10 // 64KB (64*1024)
	DefaultMaxScannerBufferSize = 64 << 20 // 64MB (64*1024*1024) default SSE buffer size
	DefaultPingInterval         = 10 * time.Second
)

Variables

This section is empty.

Functions

func BuildBillingExprRequestInputFromRequest

func BuildBillingExprRequestInputFromRequest(request dto.Request, headers map[string]string) (billingexpr.RequestInput, error)

func ClaudeChunkData

func ClaudeChunkData(c *gin.Context, resp dto.ClaudeResponse, data string)

func ClaudeData

func ClaudeData(c *gin.Context, resp dto.ClaudeResponse) error

func Done

func Done(c *gin.Context)

func ExtendWriteDeadline added in v1.0.4

func ExtendWriteDeadline(c *gin.Context)

func FlushWriter

func FlushWriter(c *gin.Context) (err error)

func GenerateFinalUsageResponse

func GenerateFinalUsageResponse(id string, createAt int64, model string, usage dto.Usage) *dto.ChatCompletionsStreamResponse

func GenerateStartEmptyResponse

func GenerateStartEmptyResponse(id string, createAt int64, model string, systemFingerprint *string) *dto.ChatCompletionsStreamResponse

func GenerateStopResponse

func GenerateStopResponse(id string, createAt int64, model string, finishReason string) *dto.ChatCompletionsStreamResponse

func GetAndValidAudioRequest

func GetAndValidAudioRequest(c *gin.Context, relayMode int) (*dto.AudioRequest, error)

func GetAndValidOpenAIImageRequest

func GetAndValidOpenAIImageRequest(c *gin.Context, relayMode int) (*dto.ImageRequest, error)

func GetAndValidateClaudeRequest

func GetAndValidateClaudeRequest(c *gin.Context) (textRequest *dto.ClaudeRequest, err error)

func GetAndValidateEmbeddingRequest

func GetAndValidateEmbeddingRequest(c *gin.Context, relayMode int) (*dto.EmbeddingRequest, error)

func GetAndValidateGeminiBatchEmbeddingRequest

func GetAndValidateGeminiBatchEmbeddingRequest(c *gin.Context) (*dto.GeminiBatchEmbeddingRequest, error)

func GetAndValidateGeminiEmbeddingRequest

func GetAndValidateGeminiEmbeddingRequest(c *gin.Context) (*dto.GeminiEmbeddingRequest, error)

func GetAndValidateGeminiRequest

func GetAndValidateGeminiRequest(c *gin.Context) (*dto.GeminiChatRequest, error)

func GetAndValidateRequest

func GetAndValidateRequest(c *gin.Context, format types.RelayFormat) (request dto.Request, err error)

func GetAndValidateRerankRequest

func GetAndValidateRerankRequest(c *gin.Context) (*dto.RerankRequest, error)

func GetAndValidateResponsesCompactionRequest

func GetAndValidateResponsesCompactionRequest(c *gin.Context) (*dto.OpenAIResponsesCompactionRequest, error)

func GetAndValidateResponsesRequest

func GetAndValidateResponsesRequest(c *gin.Context) (*dto.OpenAIResponsesRequest, error)

func GetAndValidateTextRequest

func GetAndValidateTextRequest(c *gin.Context, relayMode int) (*dto.GeneralOpenAIRequest, error)

func GetLocalRealtimeID

func GetLocalRealtimeID(c *gin.Context) string

func GetResponseID

func GetResponseID(c *gin.Context) string

func HandleGroupRatio

func HandleGroupRatio(ctx *gin.Context, relayInfo *relaycommon.RelayInfo) types.GroupRatioInfo

HandleGroupRatio checks for "auto_group" in the context and updates the group ratio and relayInfo.UsingGroup if present

func HasModelBillingConfig

func HasModelBillingConfig(modelName string) bool

func ModelMappedHelper

func ModelMappedHelper(c *gin.Context, info *common.RelayInfo, request dto.Request) error

func ModelPriceHelper

func ModelPriceHelper(c *gin.Context, info *relaycommon.RelayInfo, promptTokens int, meta *types.TokenCountMeta) (types.PriceData, error)

func ModelPriceHelperPerCall

func ModelPriceHelperPerCall(c *gin.Context, info *relaycommon.RelayInfo) (types.PriceData, error)

ModelPriceHelperPerCall 按次/按量计费的 PriceHelper (MJ、Task)

func NewStreamScanner

func NewStreamScanner(reader io.Reader) *bufio.Scanner

func ObjectData

func ObjectData(c *gin.Context, object interface{}) error

func PingData

func PingData(c *gin.Context) error

func ResolveIncomingBillingExprRequestInput

func ResolveIncomingBillingExprRequestInput(c *gin.Context, info *relaycommon.RelayInfo) (billingexpr.RequestInput, error)

func ResponseChunkData

func ResponseChunkData(c *gin.Context, resp dto.ResponsesStreamResponse, data string) error

func SetEventStreamHeaders

func SetEventStreamHeaders(c *gin.Context)

func StreamScannerHandler

func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo, dataHandler func(data string, sr *StreamResult))

func StringData

func StringData(c *gin.Context, str string) error

func WssError

func WssError(c *gin.Context, ws *websocket.Conn, openaiError types.OpenAIError)

func WssObject

func WssObject(c *gin.Context, ws *websocket.Conn, object interface{}) error

func WssString

func WssString(c *gin.Context, ws *websocket.Conn, str string) error

Types

type StreamResult

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

StreamResult is passed to each dataHandler invocation, providing methods to record soft errors, signal fatal stops, or mark normal completion. StreamScannerHandler checks IsStopped() after each callback invocation.

func (*StreamResult) Done

func (r *StreamResult) Done()

Done signals that the handler has finished processing normally (e.g., Dify "message_end"). The stream stops after this chunk.

func (*StreamResult) Error

func (r *StreamResult) Error(err error)

Error records a soft error. The stream continues processing. Can be called multiple times per chunk.

func (*StreamResult) IsStopped

func (r *StreamResult) IsStopped() bool

IsStopped returns whether Stop() or Done() was called during this chunk.

func (*StreamResult) Stop

func (r *StreamResult) Stop(err error)

Stop records a fatal error and marks the stream to stop after this chunk.

Jump to

Keyboard shortcuts

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