diff --git a/src/components/Generator.tsx b/src/components/Generator.tsx index 48f2151..505fea3 100644 --- a/src/components/Generator.tsx +++ b/src/components/Generator.tsx @@ -43,6 +43,8 @@ export default () => { const moderationInterval = Number(import.meta.env.PUBLIC_MODERATION_INTERVAL ?? '2000') + createEffect(() => currentError() && trackEvent('error', { code: currentError()!.code })) + const isHigher = () => { const distanceToBottom = footer.offsetTop - window.innerHeight const currentScrollHeight = window.scrollY @@ -201,7 +203,7 @@ export default () => { } const handleSubmit = async() => { - trackEvent(inputValue() ? 'send' : `${recording() ? 'end' : 'start'}Record`, recording() ? undefined : { length: messageList().length }) + !inputValue() && trackEvent(`${recording() ? 'end' : 'start'}-record`) if (recording()) { stopRecording() @@ -254,6 +256,8 @@ export default () => { const smoothToBottom = () => toBottom('smooth') const instantToBottom = () => toBottom('instant') + const formatTokenCount = (messages: ChatMessage[]) => encoder() && `<=${Math.ceil(countTokens(encoder()!, messages)!.total / 1000)}k` + const requestWithLatestMessage = async() => { setStreaming(true) setCurrentAssistantMessage('') @@ -298,6 +302,13 @@ export default () => { setCurrentError({ code: `${res.status} ${res.statusText}`, message }) throw new Error('Request failed') } + + trackEvent('send', { + model: payload.model, + temperature: payload.temperature, + originalTokenCont: formatTokenCount((systemMsg ? [systemMsg, ...messageList()] : messageList())), + tokenCount: formatTokenCount(requestMessageList), + }) const data = res.body if (!data) throw new Error('No data') @@ -391,8 +402,8 @@ export default () => { document.dispatchEvent(new MessagesEvent('clearMessages', messageList().length + Number(Boolean(currentSystemRoleSettings())))) inputRef.value = '' inputRef.style.height = 'auto' + trackEvent('clear', { totalTokenCount: formatTokenCount(messageList()) }) tokenCountCache.clear() - trackEvent('clear', { length: messageList().length }) batch(() => { setInputValue('') setMessageList([]) @@ -415,7 +426,7 @@ export default () => { const retryLastFetch = () => { if (messageList().length > 0) { - trackEvent('retry', { length: messageList().length, lastMessage: messageList().at(-1)!.role }) + trackEvent('retry', { lastMessage: messageList().at(-1)!.role }) const lastMessage = messageList()[messageList().length - 1] if (lastMessage.role === 'assistant') setMessageList(messageList().slice(0, -1))