mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

:tokyo_tower: Feature request: OpenAI tokens usage information returned in add and query methods.

Open Panczo opened this issue 2 years ago • 2 comments

🚀 The feature

I was looking at docs and previous issues but couldn't find any information about consumed OpenAI tokens. According to the OpenAI documentation, they return following information in they response:

  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 7,
    "total_tokens": 12
  }

It'd be very useful to have such information, as right now I cannot track/measure programmatically consumed OpenAI tokens. So I imagine that if I'll put some option to query or add config, data about usage will be returned in the response, something like below:

result = naval_chat_bot.add("https://www.youtube.com/watch?v=3qHkcs3kG44", config=add_config)
result['source'] => some source id
result['usage'] => usage data info

result = test_chat_bot.query('some happy little query', )
result['response_message'] => 'generated response'
result['usage'] => usage data info

It can be even simplified using some kind of proxy flag, so the whole OpenAI response will be returned.

Motivation, pitch

I'm working on a web app, where each user can have his own sources db. I don't want to force someone to put/use his own OpenAI api key, instead I want to control user tokens usage programmatically.

Panczo avatar Sep 06 '23 20:09 Panczo

Good idea, this should definitely be on the list of things to add, however this isn't a quick thing to introduce so I must ask for some patience. thanks.

cachho avatar Sep 11 '23 06:09 cachho

Hi @cachho any news about this feature?

Panczo avatar Mar 17 '24 16:03 Panczo

:+1:

Panczo avatar Jul 07 '24 17:07 Panczo