* Asynchronously creates a local pipe configuration file. * * This function performs the following steps: * 1. Retrieves all available pipes. * 2. Slugifies the provided pipe name. * 3. Checks if a pipe with the same name already exists. * 4. If the pipe exists, prompts the user to confirm ove
(pipe: Pipe)
| 234 | * @returns {Promise<void>} - A promise that resolves when the pipe is successfully created. |
| 235 | */ |
| 236 | async function createLocalPipe(pipe: Pipe) { |
| 237 | try { |
| 238 | const allPipes = await getAvailablePipes(); |
| 239 | |
| 240 | const pipeNameSlugified = slugify(pipe.name); |
| 241 | |
| 242 | const hasPipe = allPipes.some(p => p === pipeNameSlugified); |
| 243 | |
| 244 | if (hasPipe) { |
| 245 | const pipeInfo = await p.group( |
| 246 | { |
| 247 | overwrite: () => |
| 248 | p.confirm({ |
| 249 | message: `PIPE: ${color.cyan(pipe.name)} already exists. Do you want to overwrite it?`, |
| 250 | initialValue: false |
| 251 | }) |
| 252 | }, |
| 253 | { |
| 254 | onCancel: () => { |
| 255 | p.cancel('Operation cancelled.'); |
| 256 | process.exit(0); |
| 257 | } |
| 258 | } |
| 259 | ); |
| 260 | |
| 261 | if (!pipeInfo.overwrite) { |
| 262 | p.outro(`Skipped …`); |
| 263 | return; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | const toolData = await getToolsPipeData(pipe.tools); |
| 268 | |
| 269 | const toolCalls = toolData.map(tool => tool.toolCall); |
| 270 | const pipeNameCamelCase = camelCase('pipe-' + pipe.name); |
| 271 | |
| 272 | const messages = pipe.messages.map(message => ({ |
| 273 | ...(message.name && { name: message.name }), |
| 274 | role: message.role, |
| 275 | content: message.content |
| 276 | })); |
| 277 | |
| 278 | const pipeContent = `import { PipeI } from '@baseai/core'; |
| 279 | ${toolData.map(tool => tool.importPath).join('\n')} |
| 280 | |
| 281 | const ${pipeNameCamelCase} = (): PipeI => ({ |
| 282 | // Replace with your API key https://langbase.com/docs/api-reference/api-keys |
| 283 | apiKey: process.env.LANGBASE_API_KEY!, |
| 284 | name: \`${pipe.name}\`, |
| 285 | description: \`${pipe.description}\`, |
| 286 | status: \`${pipe.status}\`, |
| 287 | model: \`${pipe.model}\`, |
| 288 | stream: ${pipe.stream}, |
| 289 | json: ${pipe.json}, |
| 290 | store: ${pipe.store}, |
| 291 | moderate: ${pipe.moderate || true}, |
| 292 | top_p: ${pipe.top_p}, |
| 293 | max_tokens: ${pipe.max_tokens}, |
no test coverage detected