@octomil/browser 1.3.0 → 1.4.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.
package/dist/index.cjs CHANGED
@@ -34646,7 +34646,51 @@ function createTransformersJsLocalResponsesRuntime(options = {}) {
34646
34646
  return toResponse(request, config.model, generatedText);
34647
34647
  },
34648
34648
  async *stream(request) {
34649
- const response = await this.create(request);
34649
+ const generator = await getGenerator(config);
34650
+ const messages = buildMessages(request, config.maxInputChars);
34651
+ const generationInput = renderGenerationInput(generator, messages);
34652
+ const pending = [];
34653
+ let wake = null;
34654
+ const push = (item) => {
34655
+ pending.push(item);
34656
+ if (wake) {
34657
+ wake();
34658
+ wake = null;
34659
+ }
34660
+ };
34661
+ const pull = async () => {
34662
+ while (pending.length === 0) {
34663
+ await new Promise((r) => {
34664
+ wake = r;
34665
+ });
34666
+ }
34667
+ return pending.shift();
34668
+ };
34669
+ const genPromise = generator(generationInput, {
34670
+ max_new_tokens: request.maxOutputTokens ?? config.maxNewTokens,
34671
+ temperature: request.temperature ?? config.temperature,
34672
+ top_p: request.topP ?? config.topP,
34673
+ repetition_penalty: config.repetitionPenalty,
34674
+ do_sample: (request.temperature ?? config.temperature) > 0,
34675
+ return_full_text: false,
34676
+ callback_function: (text) => {
34677
+ if (typeof text === "string" && text.length > 0) {
34678
+ push({ kind: "token", text });
34679
+ }
34680
+ }
34681
+ }).then(() => push({ kind: "done" })).catch((err) => push({ kind: "error", error: err }));
34682
+ let fullText = "";
34683
+ while (true) {
34684
+ const item = await pull();
34685
+ if (item.kind === "error") {
34686
+ throw item.error instanceof Error ? item.error : new Error(String(item.error));
34687
+ }
34688
+ if (item.kind === "done") break;
34689
+ fullText += item.text;
34690
+ yield { type: "text_delta", delta: item.text };
34691
+ }
34692
+ await genPromise;
34693
+ const response = toResponse(request, config.model, fullText);
34650
34694
  const firstOutput = response.output[0];
34651
34695
  if (firstOutput?.type === "tool_call") {
34652
34696
  yield {
@@ -34656,8 +34700,6 @@ function createTransformersJsLocalResponsesRuntime(options = {}) {
34656
34700
  name: firstOutput.toolCall?.name,
34657
34701
  argumentsDelta: firstOutput.toolCall?.arguments
34658
34702
  };
34659
- } else if (firstOutput?.type === "text" && firstOutput.text) {
34660
- yield { type: "text_delta", delta: firstOutput.text };
34661
34703
  }
34662
34704
  yield { type: "done", response };
34663
34705
  }