-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Please review closely because I am not a JS dev Adds two few shot related methods for indexing and finding similar examples to the js langsmith client. Mirrors implementations in python here: https://github.com/langchain-ai/langsmith-sdk/pull/925/files#diff-619399e55cdfbfd5de40fb5e942606b34a9d5e16c289ae44e02d7a4a46d82e4fR14
- Loading branch information
1 parent
f66be6f
commit ce1bc34
Showing
4 changed files
with
184 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,4 +276,4 @@ | |
}, | ||
"./package.json": "./package.json" | ||
} | ||
} | ||
} |
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,65 @@ | ||
import { KVMap, ExampleSearch } from "../schemas.js"; | ||
import { Client } from "../index.js"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
const TESTING_DATASET_NAME = `test_dataset_few_shot_js_${uuidv4()}`; | ||
|
||
test("evaluate can evaluate", async () => { | ||
const client = new Client(); | ||
|
||
const schema: KVMap = { | ||
type: "object", | ||
properties: { | ||
name: { type: "string" }, | ||
}, | ||
required: ["name"], | ||
additionalProperties: false, | ||
}; | ||
|
||
const has_dataset = await client.hasDataset({ | ||
datasetName: TESTING_DATASET_NAME, | ||
}); | ||
if (has_dataset === true) { | ||
await client.deleteDataset({ datasetName: TESTING_DATASET_NAME }); | ||
} | ||
|
||
const dataset = await client.createDataset(TESTING_DATASET_NAME, { | ||
description: | ||
"For testing purposed. Is created & deleted for each test run.", | ||
inputsSchema: schema, | ||
}); | ||
|
||
// create examples | ||
const res = await client.createExamples({ | ||
inputs: [{ name: "foo" }, { name: "bar" }], | ||
outputs: [{ output: 2 }, { output: 3 }], | ||
datasetName: TESTING_DATASET_NAME, | ||
}); | ||
if (res.length !== 2) { | ||
throw new Error("Failed to create examples"); | ||
} | ||
|
||
await client.indexDataset({ datasetId: dataset.id }); | ||
|
||
let i = 0; | ||
let examples: ExampleSearch[] = []; | ||
while (i < 10) { | ||
examples = await client.similarExamples( | ||
{ name: "foo" }, | ||
dataset.id, | ||
// specify limit of 5 so you return all examples | ||
5 | ||
); | ||
if (examples.length === 2) { | ||
break; | ||
} | ||
|
||
// sleep for one second | ||
await new Promise((r) => setTimeout(r, 1000)); | ||
i++; | ||
} | ||
|
||
expect(examples.length).toBe(2); | ||
expect(examples[0].inputs).toEqual({ name: "foo" }); | ||
expect(examples[1].inputs).toEqual({ name: "bar" }); | ||
}); |