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 usage per user #49

Merged
merged 7 commits into from
Mar 14, 2023
Merged

Conversation

AlexHTW
Copy link
Contributor

@AlexHTW AlexHTW commented Mar 11, 2023

Total tokens of each request are stored along with their date information in a JSON file per user.
A user can retrieve their current daily and monthly total token usage and the implied $-cost using the /stats command.

The feature can be used to split costs with the users (fairly) or just to inform each user of their usage.

Looking forward to your feedback on the idea and the implementation!

The next step would be to include a way for the admin to retrieve the daily/monthly information for any user. I think it would be enough to log it (maybe at program start?).

A further feature I am planning with this is to add the option of (daily/monthly) token usage limits per user. This would give the admin complete control of the costs, allow him to invite less trusted users and finally also sell token "credit".

Of course, for the final vision the costs of Dall-E and Whisper requests also need to be tracked.

@AlexHTW AlexHTW marked this pull request as draft March 11, 2023 07:42
@AlexHTW
Copy link
Contributor Author

AlexHTW commented Mar 11, 2023

Changed PR to WIP, will add Dall-E and Whisper usage tracking later today. Releasing with only chat usage tracking would lead to compatibility issues of the user JSON files between versions.

@AlexHTW AlexHTW changed the title Track token usage per user WIP: Track token usage per user Mar 11, 2023
@n3d1117
Copy link
Owner

n3d1117 commented Mar 11, 2023

Looking good @AlexHTW! Let me know when it's ready for review

@AlexHTW AlexHTW force-pushed the track-token-usage-per-user branch from 0a0ac66 to 896b09f Compare March 12, 2023 00:25
@AlexHTW AlexHTW marked this pull request as ready for review March 14, 2023 01:58
@AlexHTW
Copy link
Contributor Author

AlexHTW commented Mar 14, 2023

Hey @n3d1117 ,
I am done. I implemented usage history for chat, images and transcription.
/stats command returns usage information for current day and month.
Looking forward to your review!

@AlexHTW AlexHTW changed the title WIP: Track token usage per user Track token usage per user Mar 14, 2023
@AlexHTW AlexHTW changed the title Track token usage per user Track usage per user Mar 14, 2023
@n3d1117
Copy link
Owner

n3d1117 commented Mar 14, 2023

This is amazing! Thanks @AlexHTW

@n3d1117 n3d1117 merged commit b39436d into n3d1117:main Mar 14, 2023
@AlexHTW AlexHTW deleted the track-token-usage-per-user branch March 27, 2023 20:53
@GuillaumeMoscou
Copy link

Great improvement! How can I, as an admin, use it to view the statistics for each user?

@AlexHTW
Copy link
Contributor Author

AlexHTW commented Apr 3, 2023

Thanks @GuillaumeMoscou!
You can look inside the /usage_log .json files for the current $-amount spent by each user and guest user. *
There are currently no commands that let the admin see stats of other users in Telegram.
Can you provide more feedback, what stats you would want to see and how you would prefer to get them? I have some ideas, but would love to hear yours first.

* if you're using the docker image, here are some suggestions how to have a look at files inside

@GuillaumeMoscou
Copy link

Thanks @GuillaumeMoscou! You can look inside the /usage_log .json files for the current $-amount spent by each user and guest user. * There are currently no commands that let the admin see stats of other users in Telegram. Can you provide more feedback, what stats you would want to see and how you would prefer to get them? I have some ideas, but would love to hear yours first.

Thank you very much, this fulfills my needs.

An enhancement would be to have access to it through a command, such as /stat_users (only available for the admin chat).

As for the type of information, it would be the number of tokens for the past month and the last three days. Personally, I don't look at the cost, so that information wouldn't be useful to me.

@AlexHTW
Copy link
Contributor Author

AlexHTW commented Apr 3, 2023

Happy to hear the log files are sufficient for now.
I will definitely keep your enhancement idea in the back of my mind. There are quite a lot of other improvements I want to get to first, though.

@AlexHTW AlexHTW mentioned this pull request Apr 4, 2023
3 tasks
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.

3 participants