Skip to content

Commit

Permalink
Merge branch 'main' into infra/fix-sdk-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
langchain-infra authored Nov 1, 2023
2 parents 7124efb + 0c04410 commit 307f035
Show file tree
Hide file tree
Showing 20 changed files with 861 additions and 270 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langsmith",
"version": "0.0.43",
"version": "0.0.45",
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
"files": [
"dist/",
Expand Down
1 change: 1 addition & 0 deletions js/src/cli/docker-compose.beta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- PORT=1985
- LANGCHAIN_ENV=local_docker
- LOG_LEVEL=warning
- LANGSMITH_LICENSE_KEY=${LANGSMITH_LICENSE_KEY}
ports:
- 1985:1985
depends_on:
Expand Down
2 changes: 2 additions & 0 deletions js/src/cli/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
version: '3'
services:
# TODO: Move to the regular docker-compose.yaml once deployed
langchain-hub:
image: langchain/${_LANGSMITH_IMAGE_PREFIX-}langchainhub-backend:latest
environment:
- PORT=1985
- LANGCHAIN_ENV=local_docker
- LOG_LEVEL=warning
- LANGSMITH_LICENSE_KEY=${LANGSMITH_LICENSE_KEY}
ports:
- 1985:1985
depends_on:
Expand Down
12 changes: 7 additions & 5 deletions js/src/cli/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as child_process from "child_process";
import * as fs from "fs";
import * as path from "path";
import * as util from "util";
import { Command } from "commander";
import * as child_process from "child_process";

import {
getLangChainEnvVars,
getRuntimeEnvironment,
setEnvironmentVariable,
} from "../utils/env.js";

import { Command } from "commander";
import { spawn } from "child_process";

const currentFileName = __filename;
Expand Down Expand Up @@ -332,9 +334,9 @@ const startCommand = new Command("start")
)
.option(
"--langsmith-license-key <langsmithLicenseKey>",
"The LangSmith license key to use for LangSmith. If not provided," +
" the LangSmith license key will be read from the LANGSMITH_LICENSE_KEY" +
" environment variable. If neither are provided, Langsmith will not start up."
"The LangSmith license key to use for LangSmith. If not provided, the LangSmith" +
" License Key will be read from the LANGSMITH_LICENSE_KEY environment variable." +
" If neither are provided, the Langsmith application will not spin up."
)
.action(async (args) => {
const smith = await SmithCommand.create();
Expand Down
91 changes: 90 additions & 1 deletion js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
import {
DataType,
Dataset,
DatasetShareSchema,
Example,
ExampleCreate,
ExampleUpdate,
Expand Down Expand Up @@ -584,6 +585,91 @@ export class Client {
return runs as Run[];
}

public async readDatasetSharedSchema(
datasetId?: string,
datasetName?: string
): Promise<DatasetShareSchema> {
if (!datasetId && !datasetName) {
throw new Error("Either datasetId or datasetName must be given");
}
if (!datasetId) {
const dataset = await this.readDataset({ datasetName });
datasetId = dataset.id;
}
const response = await this.caller.call(
fetch,
`${this.apiUrl}/datasets/${datasetId}/share`,
{
method: "GET",
headers: this.headers,
signal: AbortSignal.timeout(this.timeout_ms),
}
);
const shareSchema = await response.json();
shareSchema.url = `${this.getHostUrl()}/public/${
shareSchema.share_token
}/d`;
return shareSchema as DatasetShareSchema;
}

public async shareDataset(
datasetId?: string,
datasetName?: string
): Promise<DatasetShareSchema> {
if (!datasetId && !datasetName) {
throw new Error("Either datasetId or datasetName must be given");
}
if (!datasetId) {
const dataset = await this.readDataset({ datasetName });
datasetId = dataset.id;
}
const data = {
dataset_id: datasetId,
};
const response = await this.caller.call(
fetch,
`${this.apiUrl}/datasets/${datasetId}/share`,
{
method: "PUT",
headers: this.headers,
body: JSON.stringify(data),
signal: AbortSignal.timeout(this.timeout_ms),
}
);
const shareSchema = await response.json();
shareSchema.url = `${this.getHostUrl()}/public/${
shareSchema.share_token
}/d`;
return shareSchema as DatasetShareSchema;
}

public async unshareDataset(datasetId: string): Promise<void> {
const response = await this.caller.call(
fetch,
`${this.apiUrl}/datasets/${datasetId}/share`,
{
method: "DELETE",
headers: this.headers,
signal: AbortSignal.timeout(this.timeout_ms),
}
);
await raiseForStatus(response, "unshare dataset");
}

public async readSharedDataset(shareToken: string): Promise<Dataset> {
const response = await this.caller.call(
fetch,
`${this.apiUrl}/public/${shareToken}/datasets`,
{
method: "GET",
headers: this.headers,
signal: AbortSignal.timeout(this.timeout_ms),
}
);
const dataset = await response.json();
return dataset as Dataset;
}

public async createProject({
projectName,
projectExtra,
Expand Down Expand Up @@ -1158,6 +1244,7 @@ export class Client {
feedbackSourceType = "api",
sourceRunId,
feedbackId,
eager = false,
}: {
score?: ScoreType;
value?: ValueType;
Expand All @@ -1167,6 +1254,7 @@ export class Client {
feedbackSourceType?: FeedbackSourceType;
sourceRunId?: string;
feedbackId?: string;
eager?: boolean;
}
): Promise<Feedback> {
const feedback_source: feedback_source = {
Expand All @@ -1190,7 +1278,8 @@ export class Client {
comment,
feedback_source: feedback_source,
};
const response = await this.caller.call(fetch, `${this.apiUrl}/feedback`, {
const url = `${this.apiUrl}/feedback` + (eager ? "/eager" : "");
const response = await this.caller.call(fetch, url, {
method: "POST",
headers: { ...this.headers, "Content-Type": "application/json" },
body: JSON.stringify(feedback),
Expand Down
2 changes: 1 addition & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export { Client } from "./client.js";

export { Dataset, Example, TracerSession, Run, Feedback } from "./schemas.js";

export { RunTree } from "./run_trees.js";
export { RunTree, RunTreeConfig } from "./run_trees.js";
8 changes: 8 additions & 0 deletions js/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ export interface Dataset extends BaseDataset {
id: string;
created_at: string;
modified_at: string;
example_count?: number;
session_count?: number;
last_session_start_time?: number;
}
export interface DatasetShareSchema {
dataset_id: string;
share_token: string;
url: string;
}

export interface FeedbackSourceBase {
Expand Down
Loading

0 comments on commit 307f035

Please sign in to comment.