-
Notifications
You must be signed in to change notification settings - Fork 18
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
Extract Input/Output token usage from request. #111
Open
sukumargaonkar
wants to merge
4
commits into
envoyproxy:main
Choose a base branch
from
sukumargaonkar:token-useage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e301800
Extract Input/Output token usage from request.
sukumargaonkar 2bbf807
Merge remote-tracking branch 'refs/remotes/upstream/main' into token-…
sukumargaonkar 5843f1e
Fix linting and formatting
sukumargaonkar 9a4ad44
Merge branch 'main' into token-useage
yuzisun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ site/yarn-debug.log* | |
site/yarn-error.log* | ||
site/static/.DS_Store | ||
site/temp | ||
/.idea/ | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,9 @@ modelNameHeaderKey: x-envoy-ai-gateway-model | |
// modelNameHeaderKey: x-envoy-ai-gateway-model | ||
// tokenUsageMetadata: | ||
// namespace: ai_gateway_llm_ns | ||
// key: token_usage_key | ||
// inputTokensKey: input_tokens_usage | ||
// outputTokensKey: output_tokens_usage | ||
// totalTokensKey: total_tokens_usage | ||
// rules: | ||
// - backends: | ||
// - name: kserve | ||
|
@@ -66,6 +68,13 @@ modelNameHeaderKey: x-envoy-ai-gateway-model | |
// From Envoy configuration perspective, configuring the header matching based on `x-envoy-ai-gateway-selected-backend` is enough to route the request to the selected backend. | ||
// That is because the matching decision is made by the filter and the selected backend is populated in the header `x-envoy-ai-gateway-selected-backend`. | ||
type Config struct { | ||
// MonitorContinuousUsageStats flag controls if external process monitors every response-body chunk for usage stats | ||
// when true, it will monitor for token metadata usage in every response-body chunk received during request in streaming mode | ||
// compatible with vllm's 'continuous_usage_stats' flag | ||
// when false, it will stop monitoring after detecting token metadata usage after finding it for the first time. | ||
// compatible with OpenAI's streaming response (https://platform.openai.com/docs/api-reference/chat/streaming#chat/streaming-usage) | ||
// Only affects request in streaming mode | ||
MonitorContinuousUsageStats bool `yaml:"monitorContinuousUsageStats,omitempty"` | ||
Comment on lines
+71
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you remove the change related to this? I think this is another issue and metadata is not cumulative so basically it's overriding previous ones if it's emitted in the middle. |
||
// TokenUsageMetadata is the namespace and key to be used in the filter metadata to store the usage token, optional. | ||
// If this is provided, the filter will populate the usage token in the filter metadata at the end of the | ||
// response body processing. | ||
|
@@ -90,8 +99,12 @@ type Config struct { | |
type TokenUsageMetadata struct { | ||
// Namespace is the namespace of the metadata. | ||
Namespace string `yaml:"namespace"` | ||
// Key is the key of the metadata. | ||
Key string `yaml:"key"` | ||
// InputTokensKey is the key of the metadata containing input-token count parsed from upstream-response. | ||
InputTokensKey string `yaml:"inputTokenKey"` | ||
// OutputTokensKey is the key of the metadata containing output-token count parsed from upstream-response. | ||
OutputTokensKey string `yaml:"outputTokenKey"` | ||
// TotalTokensKey is the key of the metadata containing total-token count parsed from upstream-response. | ||
TotalTokensKey string `yaml:"totalTokenKey"` | ||
} | ||
|
||
// VersionedAPISchema corresponds to LLMAPISchema in api/v1alpha1/api.go. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary change - already in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also you can have a global gitignore in your os... that's where people usually place the gitignore for something that's not generated by the project