(value: T | T[])
| 209 | * @returns The truncated JSON string |
| 210 | */ |
| 211 | export function getTruncatedJsonString<T>(value: T | T[]): string { |
| 212 | if (typeof value === 'string') { |
| 213 | // Some values are already JSON strings, so we don't need to duplicate the JSON parsing |
| 214 | return truncateGenAiStringInput(value); |
| 215 | } |
| 216 | if (Array.isArray(value)) { |
| 217 | // truncateGenAiMessages returns an array of strings, so we need to stringify it |
| 218 | const truncatedMessages = truncateGenAiMessages(value); |
| 219 | return JSON.stringify(truncatedMessages); |
| 220 | } |
| 221 | // value is an object, so we need to stringify it |
| 222 | return JSON.stringify(value); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Extract system instructions from messages array. |
no test coverage detected