-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow manually specified client in run tree with no env vars (#463)
We were initializing a client by default every time, which means if you don't have an env var set, you can't use the run tree. Should we remove the thrown error altogether on client initialization? Why was that added in the first place? @hinthornw @dqbd
- Loading branch information
1 parent
e56ea50
commit 5e074f7
Showing
3 changed files
with
39 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-disable no-process-env */ | ||
|
||
import { jest } from "@jest/globals"; | ||
import { Client } from "../client.js"; | ||
import { RunTree } from "../run_trees.js"; | ||
|
||
test.concurrent( | ||
"Should work with manually set API key", | ||
async () => { | ||
const key = process.env.LANGCHAIN_API_KEY; | ||
delete process.env.LANGCHAIN_API_KEY; | ||
const langchainClient = new Client({ | ||
autoBatchTracing: true, | ||
callerOptions: { maxRetries: 0 }, | ||
timeout_ms: 30_000, | ||
apiKey: key, | ||
}); | ||
const callSpy = jest | ||
.spyOn((langchainClient as any).caller, "call") | ||
.mockResolvedValue({ | ||
ok: true, | ||
text: () => "", | ||
}); | ||
const projectName = "__test_persist_update_run_tree"; | ||
const runTree = new RunTree({ | ||
name: "Test Run Tree", | ||
inputs: { input: "foo1" }, | ||
client: langchainClient, | ||
project_name: projectName, | ||
}); | ||
await runTree.postRun(); | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
expect(callSpy).toHaveBeenCalled(); | ||
}, | ||
180_000 | ||
); |