| 179 | } |
| 180 | |
| 181 | function getInvoiceDescription(stats: { |
| 182 | totalInferenceSpend: number; |
| 183 | totalTrainingSpend: number; |
| 184 | totalInputTokens: number; |
| 185 | totalOutputTokens: number; |
| 186 | totalTrainingTokens: number; |
| 187 | creditsUsed: number; |
| 188 | remainingCredits: number; |
| 189 | }) { |
| 190 | const totalTokends = stats.totalInputTokens + stats.totalOutputTokens; |
| 191 | |
| 192 | const description = [ |
| 193 | { |
| 194 | text: "Total inference spend", |
| 195 | value: "$" + stats.totalInferenceSpend.toFixed(2), |
| 196 | description: `Tokens: ${totalTokends.toLocaleString()} ($${( |
| 197 | Number(stats.totalInferenceSpend ?? 0) / Number(totalTokends ?? 0) |
| 198 | ).toFixed(7)}/token) \n |
| 199 | Input tokens: ${stats.totalInputTokens.toLocaleString()} \n |
| 200 | Output tokens: ${stats.totalOutputTokens.toLocaleString()}`, |
| 201 | }, |
| 202 | { |
| 203 | text: "Total training spend", |
| 204 | value: "$" + stats.totalTrainingSpend.toFixed(2), |
| 205 | description: "Training tokens: " + stats.totalTrainingTokens.toLocaleString(), |
| 206 | }, |
| 207 | ]; |
| 208 | |
| 209 | const creditsUsedDescription = { |
| 210 | text: "Credits used", |
| 211 | value: "-$" + stats.creditsUsed.toFixed(2), |
| 212 | description: "Remaining credits: $" + stats.remainingCredits.toFixed(2), |
| 213 | }; |
| 214 | |
| 215 | return description.concat(stats.creditsUsed > 0 ? creditsUsedDescription : []); |
| 216 | } |