feat: add OpenAI generation stats
This commit is contained in:
@@ -8,6 +8,16 @@ type TextStreamUpdate = {
|
||||
citations?: any;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
error?: any;
|
||||
usage?: ResponseUsage;
|
||||
};
|
||||
|
||||
type ResponseUsage = {
|
||||
/** Including images and tools if any */
|
||||
prompt_tokens: number;
|
||||
/** The tokens generated */
|
||||
completion_tokens: number;
|
||||
/** Sum of the above two fields */
|
||||
total_tokens: number;
|
||||
};
|
||||
|
||||
// createOpenAITextStream takes a responseBody with a SSE response,
|
||||
@@ -59,7 +69,11 @@ async function* openAIStreamToIterator(
|
||||
continue;
|
||||
}
|
||||
|
||||
yield { done: false, value: parsedData.choices?.[0]?.delta?.content ?? '' };
|
||||
yield {
|
||||
done: false,
|
||||
value: parsedData.choices?.[0]?.delta?.content ?? '',
|
||||
usage: parsedData.usage
|
||||
};
|
||||
} catch (e) {
|
||||
console.error('Error extracting delta from SSE event:', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user