Spaces:
Runtime error
Runtime error
make tokens count working for non-streaming as well
Browse filesFiles changed (2)
36 unmodified lines3738394041424352 unmodified lines9697989910010110210310410510610710810911011111293 unmodified lines20620720820921021121236 unmodified lineslet showTokenModal = false;let loading = false;let latency = 0;let tokensCount = 0;let abortController: AbortController | undefined = undefined;let waitForNonStreaming = true;52 unmodified linesif (streamingMessage) {streamingMessage.content = content;conversation.messages = [...conversation.messages];tokensCount += 1;}},abortController);} else {waitForNonStreaming = true;const newMessage = await handleNonStreamingResponse(hf, conversation);// check if the user did not abort the requestif (waitForNonStreaming) {conversation.messages = [...conversation.messages, newMessage];}}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></div><buttontype="button"36 unmodified lines3738394041424352 unmodified lines9697989910010110210310410510610710810911011111211311411511693 unmodified lines21021121221321421521636 unmodified lineslet showTokenModal = false;let loading = false;let latency = 0;let generatedTokensCount = 0;let abortController: AbortController | undefined = undefined;let waitForNonStreaming = true;52 unmodified linesif (streamingMessage) {streamingMessage.content = content;conversation.messages = [...conversation.messages];generatedTokensCount += 1;}},abortController);} else {waitForNonStreaming = true;const { message: newMessage, completion_tokens: newTokensCount } = await handleNonStreamingResponse(hf,conversation);// check if the user did not abort the requestif (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">{generatedTokensCount} tokens · Latency {latency}ms</span></div><buttontype="button"
37 unmodified lines383940414243448 unmodified lines5354555657585937 unmodified linesexport async function handleNonStreamingResponse(hf: HfInference,conversation: Conversation): Promise<ChatCompletionInputMessage> {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;}throw new Error("No response from the model");}37 unmodified lines383940414243448 unmodified lines53545556575859606137 unmodified linesexport async function handleNonStreamingResponse(hf: HfInference,conversation: Conversation): 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) {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