MCPcopy Index your code
hub / github.com/OpenPipe/OpenPipe / getInvoiceDescription

Function getInvoiceDescription

app/src/server/tasks/generateInvoices.task.ts:181–216  ·  view source on GitHub ↗
(stats: {
  totalInferenceSpend: number;
  totalTrainingSpend: number;
  totalInputTokens: number;
  totalOutputTokens: number;
  totalTrainingTokens: number;
  creditsUsed: number;
  remainingCredits: number;
})

Source from the content-addressed store, hash-verified

179}
180
181function 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}

Callers 1

createInvoiceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected