| 80 | } |
| 81 | |
| 82 | private addCacheControlToContent(content: any, addCaching: boolean): any { |
| 83 | if (!addCaching) return content; |
| 84 | |
| 85 | if (typeof content === "string") { |
| 86 | return [ |
| 87 | { |
| 88 | type: "text", |
| 89 | text: content, |
| 90 | cache_control: { type: "ephemeral" }, |
| 91 | }, |
| 92 | ]; |
| 93 | } |
| 94 | |
| 95 | if (Array.isArray(content)) { |
| 96 | // For array content, add cache_control to the last text item |
| 97 | return content.map((part, idx) => { |
| 98 | if (part.type === "text" && idx === content.length - 1) { |
| 99 | return { |
| 100 | ...part, |
| 101 | cache_control: { type: "ephemeral" }, |
| 102 | }; |
| 103 | } |
| 104 | return part; |
| 105 | }); |
| 106 | } |
| 107 | |
| 108 | return content; |
| 109 | } |
| 110 | |
| 111 | protected modifyChatBody( |
| 112 | body: ChatCompletionCreateParams, |