Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: few shot example filtering in js #975

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith",
"version": "0.1.50",
"version": "0.1.51",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "[email protected]",
"files": [
Expand Down Expand Up @@ -276,4 +276,4 @@
},
"./package.json": "./package.json"
}
}
}
13 changes: 11 additions & 2 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@
treeFilter?: string;
isRoot?: boolean;
dataSourceType?: string;
}): Promise<any> {

Check warning on line 1274 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
let projectIds_ = projectIds || [];
if (projectNames) {
projectIds_ = [
Expand Down Expand Up @@ -1559,7 +1559,7 @@
`Failed to list shared examples: ${response.status} ${response.statusText}`
);
}
return result.map((example: any) => ({

Check warning on line 1562 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
...example,
_hostUrl: this.getHostUrl(),
}));
Expand Down Expand Up @@ -2238,13 +2238,22 @@
public async similarExamples(
inputs: KVMap,
datasetId: string,
limit: number
limit: number,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we update teh typedoc :)

{
filter,
}: {
filter?: string;
} = {}
): Promise<ExampleSearch[]> {
const data = {
const data: KVMap = {
limit: limit,
inputs: inputs,
};

if (filter !== undefined) {
data["filter"] = filter;
}

assertUuid(datasetId);
const response = await this.caller.call(
fetch,
Expand Down Expand Up @@ -2660,7 +2669,7 @@
}

const feedbackResult = await evaluator.evaluateRun(run_, referenceExample);
const [_, feedbacks] = await this._logEvaluationFeedback(

Check warning on line 2672 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
feedbackResult,
run_,
sourceInfo
Expand Down Expand Up @@ -2990,7 +2999,7 @@
async _logEvaluationFeedback(
evaluatorResponse: EvaluationResult | EvaluationResults,
run?: Run,
sourceInfo?: { [key: string]: any }

Check warning on line 3002 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
): Promise<[results: EvaluationResult[], feedbacks: Feedback[]]> {
const evalResults: Array<EvaluationResult> =
this._selectEvalResults(evaluatorResponse);
Expand Down Expand Up @@ -3029,7 +3038,7 @@
public async logEvaluationFeedback(
evaluatorResponse: EvaluationResult | EvaluationResults,
run?: Run,
sourceInfo?: { [key: string]: any }

Check warning on line 3041 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
): Promise<EvaluationResult[]> {
const [results] = await this._logEvaluationFeedback(
evaluatorResponse,
Expand Down Expand Up @@ -3095,7 +3104,7 @@
promptIdentifier: string,
like: boolean
): Promise<LikePromptResponse> {
const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);

Check warning on line 3107 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
const response = await this.caller.call(
fetch,
`${this.apiUrl}/likes/${owner}/${promptName}`,
Expand Down Expand Up @@ -3200,7 +3209,7 @@
}

public async getPrompt(promptIdentifier: string): Promise<Prompt | null> {
const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);

Check warning on line 3212 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
const response = await this.caller.call(
fetch,
`${this.apiUrl}/repos/${owner}/${promptName}`,
Expand Down Expand Up @@ -3244,7 +3253,7 @@
);
}

const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);

Check warning on line 3256 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
if (!(await this._currentTenantIsOwner(owner))) {
throw await this._ownerConflictError("create a prompt", owner);
}
Expand Down Expand Up @@ -3273,7 +3282,7 @@

public async createCommit(
promptIdentifier: string,
object: any,

Check warning on line 3285 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

Unexpected any. Specify a different type
options?: {
parentCommitHash?: string;
}
Expand All @@ -3282,7 +3291,7 @@
throw new Error("Prompt does not exist, you must create it first.");
}

const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);

Check warning on line 3294 in js/src/client.ts

View workflow job for this annotation

GitHub Actions / Check linting

'_' is assigned a value but never used
const resolvedParentCommitHash =
options?.parentCommitHash === "latest" || !options?.parentCommitHash
? await this._getLatestCommitHash(`${owner}/${promptName}`)
Expand Down
2 changes: 1 addition & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export type {
export { RunTree, type RunTreeConfig } from "./run_trees.js";

// Update using yarn bump-version
export const __version__ = "0.1.50";
export const __version__ = "0.1.51";
15 changes: 14 additions & 1 deletion js/src/tests/few_shot.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { v4 as uuidv4 } from "uuid";

const TESTING_DATASET_NAME = `test_dataset_few_shot_js_${uuidv4()}`;

test("evaluate can evaluate", async () => {
test("few shot search", async () => {
const client = new Client();

const schema: KVMap = {
Expand Down Expand Up @@ -33,6 +33,7 @@ test("evaluate can evaluate", async () => {
const res = await client.createExamples({
inputs: [{ name: "foo" }, { name: "bar" }],
outputs: [{ output: 2 }, { output: 3 }],
metadata: [{ somekey: "somevalue" }, { somekey: "someothervalue" }],
datasetName: TESTING_DATASET_NAME,
});
if (res.length !== 2) {
Expand Down Expand Up @@ -62,4 +63,16 @@ test("evaluate can evaluate", async () => {
expect(examples.length).toBe(2);
expect(examples[0].inputs).toEqual({ name: "foo" });
expect(examples[1].inputs).toEqual({ name: "bar" });

const filtered_examples = await client.similarExamples(
{ name: "foo" },
dataset.id,
1,
{
filter: "eq(metadata.somekey, 'somevalue')",
}
);

expect(filtered_examples.length).toBe(1);
expect(filtered_examples[0].inputs).toEqual({ name: "foo" });
});
Loading