@jambonz/llm 0.5.0 → 0.5.2

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.
@@ -117,6 +117,9 @@ async function* streamFromOpenAI(client, req, options) {
117
117
  const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
118
118
  body[param] = effectiveMaxTokens;
119
119
  }
120
+ const t0 = process.hrtime.bigint();
121
+ let t1;
122
+ let t2;
120
123
  let stream;
121
124
  let responseHeaders;
122
125
  try {
@@ -129,6 +132,7 @@ async function* streamFromOpenAI(client, req, options) {
129
132
  } else {
130
133
  stream = await apiPromise;
131
134
  }
135
+ t1 = process.hrtime.bigint();
132
136
  } catch (err) {
133
137
  if (isAbortError(err)) {
134
138
  yield { type: "end", finishReason: "aborted" };
@@ -160,6 +164,7 @@ async function* streamFromOpenAI(client, req, options) {
160
164
  const delta = choice.delta;
161
165
  const finishReason = choice.finish_reason;
162
166
  if (delta?.content) {
167
+ if (t2 === void 0) t2 = process.hrtime.bigint();
163
168
  yield { type: "token", text: delta.content };
164
169
  }
165
170
  if (delta?.tool_calls) {
@@ -229,6 +234,14 @@ async function* streamFromOpenAI(client, req, options) {
229
234
  endEvent.vendorMetadata = metadata;
230
235
  }
231
236
  }
237
+ if (t1 !== void 0) {
238
+ const t3 = process.hrtime.bigint();
239
+ endEvent.clientTiming = {
240
+ requestToHeadersMs: Number(t1 - t0) / 1e6,
241
+ ...t2 !== void 0 ? { headersToFirstTokenMs: Number(t2 - t1) / 1e6 } : {},
242
+ totalMs: Number(t3 - t0) / 1e6
243
+ };
244
+ }
232
245
  yield endEvent;
233
246
  }
234
247
  function appendOpenAIAssistantToolCall(history, toolCalls) {
@@ -2660,6 +2673,7 @@ var groqManifest = {
2660
2673
  var GROQ_METADATA_EXTRACTOR = makeMetadataExtractor([
2661
2674
  { header: "x-request-id", key: "request_id" },
2662
2675
  { header: "x-groq-region", key: "region" },
2676
+ { header: "openai-processing-ms", key: "processing_ms", numeric: true },
2663
2677
  { header: "x-ratelimit-remaining-requests", key: "requests_remaining", numeric: true },
2664
2678
  { header: "x-ratelimit-remaining-tokens", key: "tokens_remaining", numeric: true }
2665
2679
  ]);