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

JS[major]: Evaluate #621

Merged
merged 55 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0467902
init commit evaluate
bracesproul Apr 23, 2024
db78107
more _ExperimentManager
bracesproul Apr 23, 2024
9a2cd84
more utils and placeholders
bracesproul Apr 23, 2024
7cb8cf7
implemented some more code
bracesproul Apr 23, 2024
95589b3
more code
bracesproul Apr 23, 2024
31d35d8
more jsdoc
bracesproul Apr 23, 2024
25607d2
implemented all!
bracesproul Apr 24, 2024
5f5571e
major strides
bracesproul Apr 24, 2024
9cd5680
my tests pas
bracesproul Apr 24, 2024
bbf96e5
fix copying
bracesproul Apr 24, 2024
d43f2b8
move code around, add test
bracesproul Apr 24, 2024
f4b8ee5
updates
bracesproul Apr 25, 2024
e6a4a99
custom evaluator
bracesproul Apr 25, 2024
1554cbf
updates
bracesproul Apr 25, 2024
b5767fd
cr
bracesproul Apr 25, 2024
e2808ab
format
bracesproul Apr 25, 2024
d878278
iterable to generator
bracesproul Apr 25, 2024
0d541c1
lol it works
bracesproul Apr 25, 2024
e92e379
lots of tests
bracesproul Apr 26, 2024
4d0be08
added befo all and afta all for creating n deleting datasets
bracesproul Apr 26, 2024
d150e20
cr
bracesproul Apr 26, 2024
174a4a5
Merge branch 'main' into brace/js-evaluate
bracesproul Apr 26, 2024
73aae2b
Cleanup code, drop unnecessary code
bracesproul Apr 26, 2024
7191def
fix flaky test
bracesproul Apr 26, 2024
2325748
lint
bracesproul Apr 26, 2024
4ae3974
Merge branch 'main' into brace/js-evaluate
bracesproul Apr 26, 2024
5764ad6
nit
bracesproul Apr 26, 2024
f2d9049
vscs
hinthornw Apr 26, 2024
aa0a5db
merge
hinthornw Apr 26, 2024
acf4df0
Merge branch 'main' into brace/js-evaluate
hinthornw Apr 26, 2024
0f0fc42
cr
bracesproul Apr 26, 2024
57af814
bonk examples async iterator
bracesproul Apr 26, 2024
5346a3e
Merge branch 'main' into brace/js-evaluate
bracesproul Apr 26, 2024
47a7e53
always wrap in traceable
bracesproul Apr 27, 2024
b69bd1a
Fix build
bracesproul Apr 27, 2024
3093ffc
fix atee sync
bracesproul Apr 29, 2024
d4394d2
chore: lint files
bracesproul Apr 29, 2024
1025a94
chore: lint files
bracesproul Apr 29, 2024
681ffaa
chore: lint files
bracesproul Apr 29, 2024
ec3c565
Switched throw error to console error
bracesproul Apr 29, 2024
6f5e0d6
target can be runnable
bracesproul Apr 29, 2024
e0f0aef
myRunnable.invoke.bind(myRunnable)
bracesproul Apr 29, 2024
d310bd3
Better error msg
bracesproul Apr 29, 2024
fd9a0b2
Merge branch 'main' of https://github.com/langchain-ai/langsmith-sdk …
bracesproul Apr 29, 2024
c4b491e
support LANGSMITH_TRACING
hinthornw Apr 29, 2024
795efee
fixup
hinthornw Apr 29, 2024
f324db9
Add revision ID and fix dataset version
hinthornw Apr 29, 2024
d1da2ce
Merge and add tests
hinthornw Apr 30, 2024
c72ffa2
Merge branch 'main' into brace/js-evaluate
hinthornw Apr 30, 2024
59af7f4
add tests
hinthornw Apr 30, 2024
92fb28e
Update version
hinthornw Apr 30, 2024
e4022a8
again
hinthornw Apr 30, 2024
261dfe3
tracing enabled
hinthornw Apr 30, 2024
0e1cd6a
warn
hinthornw Apr 30, 2024
a56755d
check ls and lc env vars
bracesproul Apr 30, 2024
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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"cSpell.words": ["atee"],
"python.testing.pytestArgs": ["python"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
"eslint.workingDirectories": [
"./js"
]
Expand Down
2 changes: 1 addition & 1 deletion js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ yarn add langchain
Tracing can be activated by setting the following environment variables or by manually specifying the LangChainTracer.

```typescript
process.env["LANGCHAIN_TRACING_V2"] = "true";
process.env["LANGSMITH_TRACING"] = "true";
process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com";
process.env["LANGCHAIN_API_KEY"] = "<YOUR-LANGSMITH-API-KEY>";
// process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set
Expand Down
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.21",
"version": "0.1.22",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"packageManager": "[email protected]",
"files": [
Expand Down Expand Up @@ -195,4 +195,4 @@
},
"./package.json": "./package.json"
}
}
}
73 changes: 63 additions & 10 deletions js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@
getRuntimeEnvironment,
} from "./utils/env.js";

import { RunEvaluator } from "./evaluation/evaluator.js";
import {
EvaluationResult,
EvaluationResults,
RunEvaluator,
} from "./evaluation/evaluator.js";
import { __version__ } from "./index.js";
import { assertUuid } from "./utils/_uuid.js";

interface ClientConfig {
apiUrl?: string;
Expand Down Expand Up @@ -152,7 +157,6 @@
treeFilter?: string;
/**
* The values to include in the response.
*
*/
select?: string[];
}
Expand All @@ -174,14 +178,15 @@

interface FeedbackCreate {
id: string;
run_id: string;
run_id: string | null;
key: string;
score?: ScoreType;
value?: ValueType;
correction?: object | null;
comment?: string | null;
feedback_source?: feedback_source | KVMap | null;
feedbackConfig?: FeedbackConfig;
session_id?: string;
}

interface FeedbackUpdate {
Expand Down Expand Up @@ -317,12 +322,6 @@
.replace(/^'(.*)'$/, "$1");
}

function assertUuid(str: string): void {
if (!uuid.validate(str)) {
throw new Error(`Invalid UUID: ${str}`);
}
}

const handle429 = async (response?: Response) => {
if (response?.status === 429) {
const retryAfter =
Expand Down Expand Up @@ -2193,7 +2192,7 @@
}

public async createFeedback(
runId: string,
runId: string | null,
key: string,
{
score,
Expand All @@ -2205,6 +2204,7 @@
sourceRunId,
feedbackId,
feedbackConfig,
projectId,
}: {
score?: ScoreType;
value?: ValueType;
Expand All @@ -2216,8 +2216,15 @@
sourceRunId?: string;
feedbackId?: string;
eager?: boolean;
projectId?: string;
}
): Promise<Feedback> {
if (!runId && !projectId) {
throw new Error("One of runId or projectId must be provided");
}
if (runId && projectId) {
throw new Error("Only one of runId or projectId can be provided");
}
const feedback_source: feedback_source = {
type: feedbackSourceType ?? "api",
metadata: sourceInfo ?? {},
Expand Down Expand Up @@ -2245,6 +2252,7 @@
comment,
feedback_source: feedback_source,
feedbackConfig,
session_id: projectId,
};
const url = `${this.apiUrl}/feedback`;
const response = await this.caller.call(fetch, url, {
Expand Down Expand Up @@ -2430,4 +2438,49 @@
yield* tokens;
}
}

_selectEvalResults(
results: EvaluationResult | EvaluationResults
): Array<EvaluationResult> {
let results_: Array<EvaluationResult>;
if ("results" in results) {
results_ = results.results;
} else {
results_ = [results];
}
return results_;
}

public async logEvaluationFeedback(
evaluatorResponse: EvaluationResult | EvaluationResults,
run?: Run,
sourceInfo?: { [key: string]: any }

Check warning on line 2457 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: Array<EvaluationResult> =
this._selectEvalResults(evaluatorResponse);
for (const res of results) {
let sourceInfo_ = sourceInfo || {};
if (res.evaluatorInfo) {
sourceInfo_ = { ...res.evaluatorInfo, ...sourceInfo_ };
}
let runId_: string | null = null;
if (res.targetRunId) {
runId_ = res.targetRunId;
} else if (run) {
runId_ = run.id;
}

await this.createFeedback(runId_, res.key, {
score: res.score,
value: res.value,
comment: res.comment,
correction: res.correction,
sourceInfo: sourceInfo_,
sourceRunId: res.sourceRunId,
feedbackConfig: res.feedbackConfig as FeedbackConfig | undefined,
feedbackSourceType: "model",
});
}
return results;
}
}
Loading
Loading