( templates: Record<string, string>, variables: Record<string, string> )
| 495 | } |
| 496 | |
| 497 | function createTaskChatMessages( |
| 498 | templates: Record<string, string>, |
| 499 | variables: Record<string, string> |
| 500 | ) { |
| 501 | // TODO: can we do this as a javascript tag function? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals |
| 502 | const messages: Record<string, string> = {}; |
| 503 | |
| 504 | // Iterate over each template |
| 505 | for (const [templateKey, templateValue] of Object.entries(templates)) { |
| 506 | let content = templateValue; |
| 507 | |
| 508 | // Replace placeholders in the template with values from variables |
| 509 | for (const [variableKey, variableValue] of Object.entries(variables)) { |
| 510 | content = content.replace( |
| 511 | new RegExp(`{${variableKey}}`, 'g'), |
| 512 | variableValue |
| 513 | ); |
| 514 | } |
| 515 | |
| 516 | messages[templateKey] = content; |
| 517 | } |
| 518 | |
| 519 | return messages; |
| 520 | } |
| 521 | |
| 522 | export function prepareTasksForInference( |
| 523 | task: LLMTask, |
no outgoing calls
no test coverage detected