-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin/ai-proxy): improve the robustness of anthropic's statistics
There is a bit difference in the usage data between ai providers, and considering the variability of it, this PR attempts to improve the robustness during the process of transforming the usage data when: no usage data provided in the upstream response; some possible changes in structure of usage data in the future; In #12781 , it is arbitrarily believed that the usage data is always included and the data struct won't change. This may be a potential issue throwing an error. Therefore, this PR is a follow-up one to prevent from it. (cherry picked from commit a22d696) Co-authored-by: Robin Xiang <liverpool8056@163.com>
- Loading branch information
1 parent
7f9c132
commit 043ee5d
Showing
4 changed files
with
182 additions
and
9 deletions.
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
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
15 changes: 15 additions & 0 deletions
15
spec/fixtures/ai-proxy/anthropic/llm-v1-chat/responses/malformed_usage_response.json
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"content": [ | ||
{ | ||
"text": "The sum of 1 + 1 is 2.", | ||
"type": "text" | ||
} | ||
], | ||
"model": "claude-2.1", | ||
"stop_reason": "end_turn", | ||
"stop_sequence": "string", | ||
"usage": { | ||
"foo": 0, | ||
"bar": 0 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
spec/fixtures/ai-proxy/anthropic/llm-v1-chat/responses/no_usage_response.json
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"content": [ | ||
{ | ||
"text": "The sum of 1 + 1 is 2.", | ||
"type": "text" | ||
} | ||
], | ||
"model": "claude-2.1", | ||
"stop_reason": "end_turn", | ||
"stop_sequence": "string" | ||
} |