Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track credit consumption in AI bot #1809

Merged
merged 11 commits into from
Nov 22, 2024
Merged

Track credit consumption in AI bot #1809

merged 11 commits into from
Nov 22, 2024

Conversation

jurgenwerk
Copy link
Contributor

@jurgenwerk jurgenwerk commented Nov 18, 2024

This PR adds a mechanism to AI bot which tracks the AI-related cost, where it fetches the dollar cost from OpenRouter after ai bot streaming is done, converts to credits and writes it to the credit ledger.

Below is an example how the credits ledger looks like after a couple of interactions with the AI bot. You can see that it first tries to spend the plan's allowance credits, and when that's gone it spends the extra credits:

image

Copy link

github-actions bot commented Nov 18, 2024

Host Test Results

    1 files  ±0      1 suites  ±0   19m 36s ⏱️ ±0s
685 tests ±0  684 ✔️ ±0  1 💤 ±0  0 ±0 
690 runs  ±0  689 ✔️ ±0  1 💤 ±0  0 ±0 

Results for commit a34f106. ± Comparison against base commit 5617013.

♻️ This comment has been updated with latest results.

@jurgenwerk
Copy link
Contributor Author

jurgenwerk commented Nov 19, 2024

As an interesting observation, when users simply say "hello" to the bot, the response will cost them around 1-3 credits, sometimes up to 5.

For editing cards, and for longer responses, this cost can go up to 10-15 or more. So it looks like free plan users (100 credits) will be able to only have a couple interactions with the free plan's allowance.

packages/ai-bot/lib/ai-cost.ts Outdated Show resolved Hide resolved
subscriptionCycleId: subscriptionCycle.id,
});
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would be worth tracking the generation ID.

Copy link
Contributor Author

@jurgenwerk jurgenwerk Nov 22, 2024

Choose a reason for hiding this comment

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

I think now with this simple variant this may not be necessary but later on when we introduce jobs and queues, we could save the generation id there (in the serialized job) and have it available for inspection if needed.

@jurgenwerk jurgenwerk merged commit 096b1ad into main Nov 22, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants