()
| 54 | } |
| 55 | |
| 56 | func (i *responsesInterceptionBase) newResponsesService() responses.ResponseService { |
| 57 | opts := []option.RequestOption{option.WithBaseURL(i.cfg.BaseURL), option.WithAPIKey(i.cfg.Key)} |
| 58 | |
| 59 | // Add extra headers if configured. |
| 60 | // Some providers require additional headers that are not added by the SDK. |
| 61 | // TODO(ssncferreira): remove as part of https://github.com/coder/aibridge/issues/192 |
| 62 | for key, value := range i.cfg.ExtraHeaders { |
| 63 | opts = append(opts, option.WithHeader(key, value)) |
| 64 | } |
| 65 | |
| 66 | // Forward client headers to upstream. This middleware runs after the SDK |
| 67 | // has built the request, and replaces the outgoing headers with the sanitized |
| 68 | // client headers plus provider auth. |
| 69 | if i.clientHeaders != nil { |
| 70 | opts = append(opts, option.WithMiddleware(func(req *http.Request, next option.MiddlewareNext) (*http.Response, error) { |
| 71 | req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.authHeaderName) |
| 72 | return next(req) |
| 73 | })) |
| 74 | } |
| 75 | |
| 76 | // Add API dump middleware if configured |
| 77 | if mw := apidump.NewBridgeMiddleware(i.cfg.APIDumpDir, i.providerName, i.Model(), i.id, i.logger, quartz.NewReal()); mw != nil { |
| 78 | opts = append(opts, option.WithMiddleware(mw)) |
| 79 | } |
| 80 | |
| 81 | return responses.NewResponseService(opts...) |
| 82 | } |
| 83 | |
| 84 | func (i *responsesInterceptionBase) ID() uuid.UUID { |
| 85 | return i.id |
no test coverage detected