| 1 | import { ToolCallDelta } from "../.."; |
| 2 | |
| 3 | export function closeTag(openingTag: string): string { |
| 4 | return `</${openingTag.slice(1)}`; |
| 5 | } |
| 6 | |
| 7 | export function splitAtCodeblocksAndNewLines(content: string) { |
| 8 | return content.split(/(```|\n)/g).filter(Boolean); |
| 9 | } |
| 10 | |
| 11 | function randomLettersAndNumbers(length: number): string { |
| 12 | const characters = |
| 13 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
| 14 | let result = ""; |
| 15 | for (let i = 0; i < length; i++) { |
| 16 | result += characters.charAt(Math.floor(Math.random() * characters.length)); |
| 17 | } |
| 18 | return result; |
| 19 | } |
| 20 | |
| 21 | export function generateOpenAIToolCallId(): string { |
| 22 | return `call_${randomLettersAndNumbers(24)}`; |
| 23 | } |
| 24 | |
| 25 | export function createDelta( |
| 26 | name: string, |
| 27 | args: string, |
| 28 | id: string, |
| 29 | ): ToolCallDelta { |
| 30 | return { |
| 31 | type: "function", |
| 32 | function: { |
| 33 | name, |
| 34 | arguments: args, |
| 35 | }, |
| 36 | id, |
| 37 | }; |
| 38 | } |