Spaces:
Runtime error
Runtime error
make tokens count working for non-streaming as well
Browse filesFiles changed (2)
36 unmodified lines373839404041424352 unmodified lines969798999910010110210310410510610610710810911011111211311411511693 unmodified lines21021121220921321421521636 unmodified lines let showTokenModal = false; let loading = false; let latency = 0; let tokensCount = 0; let generatedTokensCount = 0; let abortController: AbortController | undefined = undefined; let waitForNonStreaming = true;
52 unmodified lines if (streamingMessage) { streamingMessage.content = content; conversation.messages = [...conversation.messages]; tokensCount += 1; generatedTokensCount += 1; } }, abortController ); } else { waitForNonStreaming = true; const newMessage = await handleNonStreamingResponse(hf, conversation); const { message: newMessage, completion_tokens: newTokensCount } = await handleNonStreamingResponse( hf, conversation ); // check if the user did not abort the request if (waitForNonStreaming) { conversation.messages = [...conversation.messages, newMessage]; generatedTokensCount += newTokensCount; } }
93 unmodified lines <IconDelete /> </button> <div class="flex-1 items-center justify-center text-center text-sm text-gray-500"> <span class="max-xl:hidden">{tokensCount} tokens 路 Latency {latency}ms</span> <span class="max-xl:hidden">{generatedTokensCount} tokens 路 Latency {latency}ms</span> </div> <button type="button"37 unmodified lines38394041414243448 unmodified lines5354555656575859606137 unmodified linesexport async function handleNonStreamingResponse( hf: HfInference, conversation: Conversation): Promise<ChatCompletionInputMessage> {): Promise<{ message: ChatCompletionInputMessage; completion_tokens: number }> { const { model, systemMessage } = conversation; const messages = [ ...(isSystemPromptSupported(model) && systemMessage.content?.length ? [systemMessage] : []),8 unmodified lines });
if (response.choices && response.choices.length > 0) { return response.choices[0].message; const { message } = response.choices[0]; const { completion_tokens } = response.usage; return { message, completion_tokens }; } throw new Error("No response from the model");}src/lib/components/InferencePlayground/InferencePlayground.svelte+8-4
src/lib/components/InferencePlayground/inferencePlaygroundUtils.ts+4-2