@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.
package/dist/index.cjs CHANGED
@@ -130,6 +130,9 @@ async function* streamFromOpenAI(client, req, options) {
130
130
  const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
131
131
  body[param] = effectiveMaxTokens;
132
132
  }
133
+ const t0 = process.hrtime.bigint();
134
+ let t1;
135
+ let t2;
133
136
  let stream;
134
137
  let responseHeaders;
135
138
  try {
@@ -142,6 +145,7 @@ async function* streamFromOpenAI(client, req, options) {
142
145
  } else {
143
146
  stream = await apiPromise;
144
147
  }
148
+ t1 = process.hrtime.bigint();
145
149
  } catch (err) {
146
150
  if (isAbortError(err)) {
147
151
  yield { type: "end", finishReason: "aborted" };
@@ -173,6 +177,7 @@ async function* streamFromOpenAI(client, req, options) {
173
177
  const delta = choice.delta;
174
178
  const finishReason = choice.finish_reason;
175
179
  if (delta?.content) {
180
+ if (t2 === void 0) t2 = process.hrtime.bigint();
176
181
  yield { type: "token", text: delta.content };
177
182
  }
178
183
  if (delta?.tool_calls) {
@@ -242,6 +247,14 @@ async function* streamFromOpenAI(client, req, options) {
242
247
  endEvent.vendorMetadata = metadata;
243
248
  }
244
249
  }
250
+ if (t1 !== void 0) {
251
+ const t3 = process.hrtime.bigint();
252
+ endEvent.clientTiming = {
253
+ requestToHeadersMs: Number(t1 - t0) / 1e6,
254
+ ...t2 !== void 0 ? { headersToFirstTokenMs: Number(t2 - t1) / 1e6 } : {},
255
+ totalMs: Number(t3 - t0) / 1e6
256
+ };
257
+ }
245
258
  yield endEvent;
246
259
  }
247
260
  function appendOpenAIAssistantToolCall(history, toolCalls) {
@@ -2673,6 +2686,7 @@ var groqManifest = {
2673
2686
  var GROQ_METADATA_EXTRACTOR = makeMetadataExtractor([
2674
2687
  { header: "x-request-id", key: "request_id" },
2675
2688
  { header: "x-groq-region", key: "region" },
2689
+ { header: "openai-processing-ms", key: "processing_ms", numeric: true },
2676
2690
  { header: "x-ratelimit-remaining-requests", key: "requests_remaining", numeric: true },
2677
2691
  { header: "x-ratelimit-remaining-tokens", key: "tokens_remaining", numeric: true }
2678
2692
  ]);