parent
cfbb4f32ab
commit
c87a7c0ddf
8 changed files with 100 additions and 111 deletions
@ -1,12 +0,0 @@ |
|||||||
export function getPercentage(portion: number, total: number): number { |
|
||||||
if (portion <= 0 || total <= 0) { |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
if (portion >= total) { |
|
||||||
return 100; |
|
||||||
} |
|
||||||
|
|
||||||
const percentage = (portion / total) * 100; |
|
||||||
return Math.round(percentage); |
|
||||||
} |
|
@ -1,29 +0,0 @@ |
|||||||
const NEW_LINE = '\n'.charCodeAt(0); |
|
||||||
|
|
||||||
export async function readAICourseLessonStream( |
|
||||||
reader: ReadableStreamDefaultReader<Uint8Array>, |
|
||||||
{ |
|
||||||
onStream, |
|
||||||
onStreamEnd, |
|
||||||
}: { |
|
||||||
onStream?: (lesson: string) => void; |
|
||||||
onStreamEnd?: (lesson: string) => void; |
|
||||||
}, |
|
||||||
) { |
|
||||||
const decoder = new TextDecoder('utf-8'); |
|
||||||
let result = ''; |
|
||||||
|
|
||||||
while (true) { |
|
||||||
const { value, done } = await reader.read(); |
|
||||||
if (done) { |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
result += decoder.decode(value); |
|
||||||
onStream?.(result); |
|
||||||
} |
|
||||||
|
|
||||||
onStream?.(result); |
|
||||||
onStreamEnd?.(result); |
|
||||||
reader.releaseLock(); |
|
||||||
} |
|
Loading…
Reference in new issue