Zipstack / unstract

No-code LLM Platform to launch APIs and ETL Pipelines to structure unstructured documents
https://unstract.com
GNU Affero General Public License v3.0
2.23k stars 127 forks source link

FEAT: Display Token Usage in the UI #357

Closed tahierhussain closed 4 months ago

tahierhussain commented 4 months ago

What

  1. API to fetch the token usage data.
  2. UI changes to display the token usage data (format - Total Token Count).

-

Why

The token usage for prompt runs was not being displayed to the user earlier.

-

How

NA

-

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

Yes, there are quite a few changes in multiple components, so there is a possibility that this PR may affect other features.

-

Database Migrations

NA

Env Config

NA

Relevant Docs

NA

Related Issues or PRs

https://github.com/Zipstack/unstract-cloud/pull/104

Dependencies Versions

NA

Notes on Testing

NA

Screenshots

image

Checklist

I have read and understood the [Contribution Guidelines]().

hari-kuriakose commented 4 months ago

@tahierhussain I assume the token usage is in the format <embedding>|<prompt>|<completion>|<total>. Can we please add this to the PR description?

  1. Is the total tokens usage calculation correct? From the screenshot, usage of both prompts seems to be less by 1. e.g. 1 + 808 + 3 = 811 instead of 812

  2. Are we showing a tooltip with explanation of display format on hover over token usage?

tahierhussain commented 4 months ago

@tahierhussain I assume the token usage is in the format <embedding>|<prompt>|<completion>|<total>. Can we please add this to the PR description?

  1. Is the total tokens usage calculation correct? From the screenshot, usage of both prompts seems to be less by 1. e.g. 1 + 808 + 3 = 811 instead of 812
  2. Are we showing a tooltip with explanation of display format on hover over token usage?

@hari-kuriakose I have updated the PR description.

  1. Thanks for the catch. You're right. The calculation is not correct. @gaya3-zipstack @Deepak-Kesavan Looks like the total value is not including the embedding tokens. I have verified it by checking the db. Can you please check this?

  2. Yes, a tooltip is added which explains the format.

gaya3-zipstack commented 4 months ago

@tahierhussain I assume the token usage is in the format <embedding>|<prompt>|<completion>|<total>. Can we please add this to the PR description?

  1. Is the total tokens usage calculation correct? From the screenshot, usage of both prompts seems to be less by 1. e.g. 1 + 808 + 3 = 811 instead of 812
  2. Are we showing a tooltip with explanation of display format on hover over token usage?

@hari-kuriakose I have updated the PR description.

  1. Thanks for the catch. You're right. The calculation is not correct. @gaya3-zipstack @Deepak-Kesavan Looks like the total value is not including the embedding tokens. I have verified it by checking the db. Can you please check this?
  2. Yes, a tooltip is added which explains the format.

@tahierhussain @hari-kuriakose @Deepak-Kesavan On point (1), looking at the token usage logging, total_tokens is a field which seems to be applicable only to LLM tokens and not embedding tokens as shown in the image below. If we need to add the embedding token also to the total then we need to change the SDK code to do so . My understanding is that users are only concerned about LLM token count. So do we really need to change "total count" to "total LLM count" instead?

image

Deepak-Kesavan commented 4 months ago

@tahierhussain Can you update the screenshot with latest changes?

tahierhussain commented 4 months ago

@tahierhussain Can you update the screenshot with latest changes?

@Deepak-Kesavan The current screenshot is the updated one.

hari-kuriakose commented 4 months ago

@tahierhussain I assume the token usage is in the format <embedding>|<prompt>|<completion>|<total>. Can we please add this to the PR description?

  1. Is the total tokens usage calculation correct? From the screenshot, usage of both prompts seems to be less by 1. e.g. 1 + 808 + 3 = 811 instead of 812
  2. Are we showing a tooltip with explanation of display format on hover over token usage?

@hari-kuriakose I have updated the PR description.

  1. Thanks for the catch. You're right. The calculation is not correct. @gaya3-zipstack @Deepak-Kesavan Looks like the total value is not including the embedding tokens. I have verified it by checking the db. Can you please check this?
  2. Yes, a tooltip is added which explains the format.

@tahierhussain @hari-kuriakose @Deepak-Kesavan On point (1), looking at the token usage logging, total_tokens is a field which seems to be applicable only to LLM tokens and not embedding tokens as shown in the image below. If we need to add the embedding token also to the total then we need to change the SDK code to do so . My understanding is that users are only concerned about LLM token count. So do we really need to change "total count" to "total LLM count" instead?

image

@gaya3-zipstack @tahierhussain Showing the token usage for LLM alone is good enough. We can show the total alone for now, but maybe a break down can be provided in the tooltip later.

sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud