ai-utils.js
Version:
Build AI applications, chatbots, and agents with JavaScript and TypeScript.
19 lines (18 loc) • 689 B
JavaScript
export function extractSuccessfulModelCalls(modelCallEvents) {
return modelCallEvents
.filter((event) => "status" in event && event.status === "success")
.map((event) => ({
model: event.metadata.model,
settings: event.settings,
response: event.response,
type: eventTypeToCostType[event.type],
}));
}
const eventTypeToCostType = {
"image-generation-finished": "image-generation",
"json-generation-finished": "json-generation",
"text-embedding-finished": "text-embedding",
"text-generation-finished": "text-generation",
"text-streaming-finished": "text-streaming",
"transcription-finished": "transcription",
};