Skip to content

Commit

Permalink
feat: enhance event tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Nov 10, 2024
1 parent fe26e9c commit 47772a0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/Generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`, recording() ? undefined : { length: messageList().length })

if (recording()) {
stopRecording()
Expand Down Expand Up @@ -298,6 +300,13 @@ export default () => {
setCurrentError({ code: `${res.status} ${res.statusText}`, message })
throw new Error('Request failed')
}

trackEvent('send', {
model: payload.model,
temperature: payload.temperature,
originalTokenCont: encoder() && countTokens(encoder()!, systemMsg ? [systemMsg, ...messageList()] : messageList())!.total,
tokenCount: encoder() && `<=${Math.ceil(countTokens(encoder()!, requestMessageList)!.total / 1000)}k`,
})
const data = res.body
if (!data)
throw new Error('No data')
Expand Down

1 comment on commit 47772a0

@vercel
Copy link

@vercel vercel bot commented on 47772a0 Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.