( options: RunOptions | RunOptionsStream, )
| 249 | public async run(options: RunOptionsStream): Promise<RunResponseStream>; |
| 250 | public async run(options: RunOptions): Promise<RunResponse>; |
| 251 | public async run( |
| 252 | options: RunOptions | RunOptionsStream, |
| 253 | ): Promise<RunResponse | RunResponseStream> { |
| 254 | // logger('pipe.run', this.pipe.name, 'RUN'); |
| 255 | |
| 256 | const endpoint = '/v1/pipes/run'; |
| 257 | // logger('pipe.run.baseUrl.endpoint', getApiUrl() + endpoint); |
| 258 | // logger('pipe.run.options'); |
| 259 | // logger(options, {depth: null, colors: true}); |
| 260 | |
| 261 | const providerString = this.pipe.model.split(':')[0]; |
| 262 | const modelProvider = getProvider(providerString); |
| 263 | const isAnthropic = modelProvider === ANTHROPIC; |
| 264 | const hasTools = this.pipe.tools.length > 0; |
| 265 | |
| 266 | // For SDK |
| 267 | // Run the given pipe name |
| 268 | if (options.name) { |
| 269 | this.pipe = {...this.pipe, name: options.name}; |
| 270 | } |
| 271 | |
| 272 | // For SDK |
| 273 | // Run the pipe against the given Pipe API key |
| 274 | if (options.apiKey) { |
| 275 | this.request = new Request({ |
| 276 | apiKey: options.apiKey, |
| 277 | baseUrl: this.baseUrl, |
| 278 | ...((options.llmKey && {llmKey: options.llmKey}) || {}), |
| 279 | }); |
| 280 | } |
| 281 | |
| 282 | if (options.llmKey && !options.apiKey) { |
| 283 | this.request = new Request({ |
| 284 | apiKey: this.entityApiKey, |
| 285 | baseUrl: this.baseUrl, |
| 286 | llmKey: options.llmKey, |
| 287 | }); |
| 288 | } |
| 289 | |
| 290 | let stream = this.isStreamRequested(options); |
| 291 | |
| 292 | // Anthropic models don't support streaming with tools. |
| 293 | if (isAnthropic && hasTools && stream) { |
| 294 | this.warnIfToolsWithStream(stream); |
| 295 | stream = false; |
| 296 | } |
| 297 | |
| 298 | let runTools = options.runTools ?? true; |
| 299 | |
| 300 | // Do not run tools if they are explicitly provided in the options. |
| 301 | if (options.tools && options.tools?.length) { |
| 302 | runTools = false; |
| 303 | } |
| 304 | |
| 305 | delete options.runTools; |
| 306 | |
| 307 | const body = {...options, stream}; |
| 308 |
no test coverage detected