@zenmux/rosetta-ai 0.13.0 → 0.14.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,42 @@ 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
|
+
reasoning_tokens: reasoningTokens,
|
|
160
|
+
},
|
|
161
|
+
prompt_tokens_details: {
|
|
162
|
+
cached_tokens: cachedTokens,
|
|
163
|
+
...(webSearch > 0 ? { web_search: webSearch } : {}),
|
|
164
|
+
},
|
|
165
|
+
input_tokens: inputTokens,
|
|
166
|
+
output_tokens: outputTokens,
|
|
167
|
+
cache_read_input_tokens: cachedTokens,
|
|
168
|
+
server_tool_use: webSearch > 0
|
|
169
|
+
? {
|
|
170
|
+
web_fetch_requests: 0,
|
|
171
|
+
web_search_requests: webSearch,
|
|
172
|
+
}
|
|
173
|
+
: null,
|
|
155
174
|
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
175
|
service_tier: "standard",
|
|
176
|
+
audio_input_tokens: u.prompt_tokens_details?.audio_tokens ?? 0,
|
|
177
|
+
audio_cache_read_tokens: u.prompt_tokens_details?.audio_cached_tokens ?? 0,
|
|
160
178
|
};
|
|
161
179
|
}
|
|
162
180
|
generateId() {
|
|
@@ -352,13 +370,7 @@ class MessagesToChatCompletionConverter {
|
|
|
352
370
|
stop_sequence: null,
|
|
353
371
|
container: null,
|
|
354
372
|
},
|
|
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
|
-
},
|
|
373
|
+
usage: this.buildUsage(usage),
|
|
362
374
|
});
|
|
363
375
|
events.push({ type: "message_stop" });
|
|
364
376
|
}
|