@zenmux/rosetta-ai 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,7 +6,7 @@ export declare class MessagesToChatCompletionConverter {
|
|
|
6
6
|
constructor();
|
|
7
7
|
convertRequest(params: Anthropic.MessageCreateParams): OpenAI.ChatCompletionCreateParams;
|
|
8
8
|
convertResponse(response: OpenAI.ChatCompletion): Anthropic.Message;
|
|
9
|
-
private
|
|
9
|
+
private buildUsage;
|
|
10
10
|
private generateId;
|
|
11
11
|
convertStream(stream: AsyncIterable<OpenAI.ChatCompletionChunk>): AsyncIterable<Anthropic.RawMessageStreamEvent>;
|
|
12
12
|
convertStreamChunk(chunk: OpenAI.ChatCompletionChunk): Anthropic.RawMessageStreamEvent[];
|
|
@@ -139,24 +139,44 @@ class MessagesToChatCompletionConverter {
|
|
|
139
139
|
content,
|
|
140
140
|
stop_reason: this.mapFinishReasonToStopReason(choice?.finish_reason),
|
|
141
141
|
stop_sequence: null,
|
|
142
|
-
usage: this.
|
|
142
|
+
usage: this.buildUsage(response.usage),
|
|
143
143
|
container: null,
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
146
|
+
buildUsage(usage) {
|
|
147
|
+
const u = usage ?? {};
|
|
148
|
+
const inputTokens = u.prompt_tokens ?? 0;
|
|
149
|
+
const outputTokens = u.completion_tokens ?? 0;
|
|
150
|
+
const totalTokens = u.total_tokens ?? inputTokens + outputTokens;
|
|
151
|
+
const cachedTokens = u.prompt_tokens_details?.cached_tokens ?? 0;
|
|
152
|
+
const reasoningTokens = u.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
153
|
+
const webSearch = u.prompt_tokens_details?.web_search ?? 0;
|
|
151
154
|
return {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
completion_tokens: outputTokens,
|
|
156
|
+
prompt_tokens: inputTokens,
|
|
157
|
+
total_tokens: totalTokens,
|
|
158
|
+
completion_tokens_details: {
|
|
159
|
+
...u.completion_tokens_details,
|
|
160
|
+
reasoning_tokens: reasoningTokens,
|
|
161
|
+
},
|
|
162
|
+
prompt_tokens_details: {
|
|
163
|
+
...u.prompt_tokens_details,
|
|
164
|
+
cached_tokens: cachedTokens,
|
|
165
|
+
...(webSearch > 0 ? { web_search: webSearch } : {}),
|
|
166
|
+
},
|
|
167
|
+
input_tokens: inputTokens,
|
|
168
|
+
output_tokens: outputTokens,
|
|
169
|
+
cache_read_input_tokens: cachedTokens,
|
|
170
|
+
server_tool_use: webSearch > 0
|
|
171
|
+
? {
|
|
172
|
+
web_fetch_requests: 0,
|
|
173
|
+
web_search_requests: webSearch,
|
|
174
|
+
}
|
|
175
|
+
: null,
|
|
155
176
|
cache_creation_input_tokens: 0,
|
|
156
|
-
cache_creation: null,
|
|
157
|
-
inference_geo: null,
|
|
158
|
-
server_tool_use: webSearch > 0 ? { web_search_requests: webSearch, web_fetch_requests: 0 } : null,
|
|
159
177
|
service_tier: "standard",
|
|
178
|
+
audio_input_tokens: u.prompt_tokens_details?.audio_tokens ?? 0,
|
|
179
|
+
audio_cache_read_tokens: u.prompt_tokens_details?.audio_cached_tokens ?? 0,
|
|
160
180
|
};
|
|
161
181
|
}
|
|
162
182
|
generateId() {
|
|
@@ -352,13 +372,7 @@ class MessagesToChatCompletionConverter {
|
|
|
352
372
|
stop_sequence: null,
|
|
353
373
|
container: null,
|
|
354
374
|
},
|
|
355
|
-
usage:
|
|
356
|
-
output_tokens: usage?.completion_tokens ?? 0,
|
|
357
|
-
input_tokens: usage?.prompt_tokens ?? null,
|
|
358
|
-
cache_creation_input_tokens: null,
|
|
359
|
-
cache_read_input_tokens: usage?.prompt_tokens_details?.cached_tokens ?? null,
|
|
360
|
-
server_tool_use: null,
|
|
361
|
-
},
|
|
375
|
+
usage: this.buildUsage(usage),
|
|
362
376
|
});
|
|
363
377
|
events.push({ type: "message_stop" });
|
|
364
378
|
}
|