ExecuteModelCall 执行模型调用(通过中间件栈)
( ctx context.Context, req *ModelRequest, finalHandler ModelCallHandler, )
| 40 | |
| 41 | // ExecuteModelCall 执行模型调用(通过中间件栈) |
| 42 | func (s *Stack) ExecuteModelCall( |
| 43 | ctx context.Context, |
| 44 | req *ModelRequest, |
| 45 | finalHandler ModelCallHandler, |
| 46 | ) (*ModelResponse, error) { |
| 47 | // 构建中间件链 |
| 48 | handler := finalHandler |
| 49 | for i := len(s.middlewares) - 1; i >= 0; i-- { |
| 50 | m := s.middlewares[i] |
| 51 | currentHandler := handler |
| 52 | handler = func(ctx context.Context, req *ModelRequest) (*ModelResponse, error) { |
| 53 | return m.WrapModelCall(ctx, req, currentHandler) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return handler(ctx, req) |
| 58 | } |
| 59 | |
| 60 | // ExecuteToolCall 执行工具调用(通过中间件栈) |
| 61 | func (s *Stack) ExecuteToolCall( |
no test coverage detected