Skip to content

Commit

Permalink
fix(js): Log instead of throw errors on 404 (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Sep 24, 2024
1 parent dbb3a42 commit 575deaa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 33 additions & 0 deletions js/src/tests/traceable.test.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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();

Expand Down

0 comments on commit 575deaa

Please sign in to comment.