diff --git a/js/src/client.ts b/js/src/client.ts index 786310d33..e44e9d921 100644 --- a/js/src/client.ts +++ b/js/src/client.ts @@ -730,7 +730,7 @@ export class Client { immediatelyTriggerBatch || this.autoBatchQueue.size > this.pendingAutoBatchedRunLimit ) { - await this.drainAutoBatchQueue(); + await this.drainAutoBatchQueue().catch(console.error); } if (this.autoBatchQueue.size > 0) { this.autoBatchTimeout = setTimeout( diff --git a/js/src/tests/traceable.test.ts b/js/src/tests/traceable.test.ts index 0686e1ec9..9720701d1 100644 --- a/js/src/tests/traceable.test.ts +++ b/js/src/tests/traceable.test.ts @@ -1,7 +1,9 @@ +import { jest } from "@jest/globals"; import { RunTree, RunTreeConfig } from "../run_trees.js"; import { ROOT, traceable, withRunTree } from "../traceable.js"; import { getAssumedTreeFromCalls } from "./utils/tree.js"; import { mockClient } from "./utils/mock_client.js"; +import { Client, overrideFetchImplementation } from "../index.js"; test("basic traceable implementation", async () => { const { client, callSpy } = mockClient(); @@ -26,6 +28,37 @@ test("basic traceable implementation", async () => { }); }); +test("404s should only log, not throw an error", async () => { + const overriddenFetch = jest.fn(() => + Promise.resolve({ + ok: false, + status: 404, + statusText: "Expected test error", + json: () => Promise.resolve({}), + text: () => Promise.resolve("Expected test error."), + }) + ); + overrideFetchImplementation(overriddenFetch); + const client = new Client({ + apiUrl: "https://foobar.notreal", + }); + const llm = traceable( + async function* llm(input: string) { + const response = input.repeat(2).split(""); + for (const char of response) { + yield char; + } + }, + { client, tracingEnabled: true } + ); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + for await (const _ of llm("Hello world")) { + // pass + } + expect(overriddenFetch).toHaveBeenCalled(); +}); + test("nested traceable implementation", async () => { const { client, callSpy } = mockClient();