(
messages: Message[],
context: { [k: string]: string },
)
| 447 | } |
| 448 | |
| 449 | export function prependUserContext( |
| 450 | messages: Message[], |
| 451 | context: { [k: string]: string }, |
| 452 | ): Message[] { |
| 453 | if (process.env.NODE_ENV === 'test') { |
| 454 | return messages |
| 455 | } |
| 456 | |
| 457 | if (Object.entries(context).length === 0) { |
| 458 | return messages |
| 459 | } |
| 460 | |
| 461 | return [ |
| 462 | createUserMessage({ |
| 463 | content: `<system-reminder>\nAs you answer the user's questions, you can use the following context:\n${Object.entries( |
| 464 | context, |
| 465 | ) |
| 466 | .map(([key, value]) => `# ${key}\n${value}`) |
| 467 | .join('\n')} |
| 468 | |
| 469 | IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.\n</system-reminder>\n`, |
| 470 | isMeta: true, |
| 471 | }), |
| 472 | ...messages, |
| 473 | ] |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Log metrics about context and system prompt size |
no test coverage detected