MCPcopy Create free account
hub / github.com/astercloud/aster / NewStructuredOutputMiddleware

Function NewStructuredOutputMiddleware

pkg/middleware/structured_output.go:34–55  ·  view source on GitHub ↗

NewStructuredOutputMiddleware 创建中间件实例

(cfg *StructuredOutputMiddlewareConfig)

Source from the content-addressed store, hash-verified

32
33// NewStructuredOutputMiddleware 创建中间件实例
34func NewStructuredOutputMiddleware(cfg *StructuredOutputMiddlewareConfig) (*StructuredOutputMiddleware, error) {
35 if cfg == nil {
36 return nil, errors.New("structured output config is nil")
37 }
38
39 parser := cfg.Parser
40 if parser == nil {
41 parser = structured.NewJSONParser()
42 }
43
44 priority := cfg.Priority
45 if priority == 0 {
46 priority = 60
47 }
48
49 return &StructuredOutputMiddleware{
50 BaseMiddleware: NewBaseMiddleware("structured_output", priority),
51 spec: cfg.Spec,
52 parser: parser,
53 allowError: cfg.AllowError || cfg.Spec.AllowTextBackup,
54 }, nil
55}
56
57// WrapModelCall 尝试解析结构化输出
58func (m *StructuredOutputMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error) {

Calls 2

NewJSONParserFunction · 0.92
NewBaseMiddlewareFunction · 0.85