From 7b0f118c8e00ce75c78c6f6fe369917559dcef96 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Tue, 24 Sep 2024 10:23:38 -0700 Subject: [PATCH 1/2] Avoid throwing errors on 404 --- js/src/client.ts | 2 +- js/src/tests/traceable.test.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/js/src/client.ts b/js/src/client.ts index 7aebb76e3..79e871c59 100644 --- a/js/src/client.ts +++ b/js/src/client.ts @@ -722,7 +722,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..ce2a9e48a 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,36 @@ 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 + } +}); + test("nested traceable implementation", async () => { const { client, callSpy } = mockClient(); From d0041af5a292a90b8de09d67136be6d821a3bf42 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Tue, 24 Sep 2024 10:42:41 -0700 Subject: [PATCH 2/2] Add assertion to test --- js/src/tests/traceable.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/tests/traceable.test.ts b/js/src/tests/traceable.test.ts index ce2a9e48a..9720701d1 100644 --- a/js/src/tests/traceable.test.ts +++ b/js/src/tests/traceable.test.ts @@ -56,6 +56,7 @@ test("404s should only log, not throw an error", async () => { for await (const _ of llm("Hello world")) { // pass } + expect(overriddenFetch).toHaveBeenCalled(); }); test("nested traceable implementation", async () => {