(c echo.Context)
| 635 | } |
| 636 | |
| 637 | func (re *RequestExtractor) SetOpenResponsesRequest(c echo.Context) error { |
| 638 | input, ok := c.Get(CONTEXT_LOCALS_KEY_LOCALAI_REQUEST).(*schema.OpenResponsesRequest) |
| 639 | if !ok || input.Model == "" { |
| 640 | return echo.ErrBadRequest |
| 641 | } |
| 642 | |
| 643 | // Convert input items to Messages (this will be done in the endpoint handler) |
| 644 | // We store the input in the request for the endpoint to process |
| 645 | cfg, ok := c.Get(CONTEXT_LOCALS_KEY_MODEL_CONFIG).(*config.ModelConfig) |
| 646 | if !ok || cfg == nil { |
| 647 | return echo.ErrBadRequest |
| 648 | } |
| 649 | |
| 650 | // Extract or generate the correlation ID (Open Responses uses x-request-id) |
| 651 | correlationID := c.Request().Header.Get("x-request-id") |
| 652 | if correlationID == "" { |
| 653 | correlationID = uuid.New().String() |
| 654 | } |
| 655 | c.Response().Header().Set("x-request-id", correlationID) |
| 656 | |
| 657 | // Use the request context directly - Echo properly supports context cancellation! |
| 658 | reqCtx := c.Request().Context() |
| 659 | c1, cancel := context.WithCancel(re.applicationConfig.Context) |
| 660 | |
| 661 | // Cancel when request context is cancelled (client disconnects) |
| 662 | go func() { |
| 663 | select { |
| 664 | case <-reqCtx.Done(): |
| 665 | cancel() |
| 666 | case <-c1.Done(): |
| 667 | // Already cancelled |
| 668 | } |
| 669 | }() |
| 670 | |
| 671 | // Add the correlation ID to the new context |
| 672 | ctxWithCorrelationID := context.WithValue(c1, CorrelationIDKey, correlationID) |
| 673 | ctxWithCorrelationID = distributedhdr.Inherit(ctxWithCorrelationID, reqCtx) |
| 674 | |
| 675 | input.Context = ctxWithCorrelationID |
| 676 | input.Cancel = cancel |
| 677 | |
| 678 | err := MergeOpenResponsesConfig(cfg, input) |
| 679 | if err != nil { |
| 680 | return err |
| 681 | } |
| 682 | |
| 683 | if cfg.Model == "" { |
| 684 | xlog.Debug("replacing empty cfg.Model with input value", "input.Model", input.Model) |
| 685 | cfg.Model = input.Model |
| 686 | } |
| 687 | |
| 688 | c.Set(CONTEXT_LOCALS_KEY_LOCALAI_REQUEST, input) |
| 689 | c.Set(CONTEXT_LOCALS_KEY_MODEL_CONFIG, cfg) |
| 690 | |
| 691 | return nil |
| 692 | } |
| 693 | |
| 694 | // MergeOpenResponsesConfig merges request parameters into the model configuration. |
no test coverage detected