Skip to content

Commit

Permalink
Stop masking project creation errors (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Sep 10, 2024
1 parent ab446df commit 4561fbf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
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.53",
"version": "0.1.54",
"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"
}
}
}
25 changes: 14 additions & 11 deletions js/scripts/bump-version.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { readFileSync, writeFileSync } from 'fs';
import process from 'process';
const packageJson = JSON.parse(readFileSync('package.json'));
import { readFileSync, writeFileSync } from "fs";
import process from "process";
const packageJson = JSON.parse(readFileSync("package.json"));

let newVersion;
if (process.argv.length > 2) {
newVersion = process.argv[2];
newVersion = process.argv[2];
} else {
const versionParts = packageJson.version.split('.');
versionParts[2] = parseInt(versionParts[2]) + 1;
newVersion = versionParts.join('.');
const versionParts = packageJson.version.split(".");
versionParts[2] = parseInt(versionParts[2]) + 1;
newVersion = versionParts.join(".");
}
console.log(`Bumping version to ${newVersion}`);

packageJson.version = newVersion;
writeFileSync('package.json', JSON.stringify(packageJson, null, 2));
writeFileSync("package.json", JSON.stringify(packageJson, null, 2) + "\n");

const indexFilePath = 'src/index.ts';
let indexFileContent = readFileSync(indexFilePath, 'utf-8');
indexFileContent = indexFileContent.replace(/export const __version__ = "[0-9]+\.[0-9]+\.[0-9]+";/g, `export const __version__ = "${newVersion}";`);
const indexFilePath = "src/index.ts";
let indexFileContent = readFileSync(indexFilePath, "utf-8");
indexFileContent = indexFileContent.replace(
/export const __version__ = "[0-9]+\.[0-9]+\.[0-9]+";/g,
`export const __version__ = "${newVersion}";`
);
writeFileSync(indexFilePath, indexFileContent);
19 changes: 4 additions & 15 deletions js/src/evaluation/_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,11 @@ export class _ExperimentManager {
async _getProject(firstExample: Example): Promise<TracerSession> {
let project: TracerSession;
if (!this._experiment) {
try {
const projectMetadata = await this._getExperimentMetadata();
project = await this._createProject(firstExample, projectMetadata);
this._experiment = project;
} catch (e) {
if (String(e).includes("already exists")) {
throw e;
}
throw new Error(
`Experiment ${this._experimentName} already exists. Please use a different name.`
);
}
} else {
project = this._experiment;
const projectMetadata = await this._getExperimentMetadata();
project = await this._createProject(firstExample, projectMetadata);
this._experiment = project;
}
return project;
return this._experiment;
}

protected async _printExperimentStart(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export { RunTree, type RunTreeConfig } from "./run_trees.js";
export { overrideFetchImplementation } from "./singletons/fetch.js";

// Update using yarn bump-version
export const __version__ = "0.1.53";
export const __version__ = "0.1.54";
26 changes: 26 additions & 0 deletions js/src/tests/client.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,32 @@ test.concurrent("Test run stats", async () => {
expect(stats).toBeDefined();
});

test("Test createProject raises LangSmithConflictError on duplicate name", async () => {
const client = new Client();
const projectName = `test_project_${uuidv4()}`;

try {
// Create the project for the first time
await client.createProject({ projectName });

// Attempt to create the project with the same name again
await expect(client.createProject({ projectName })).rejects.toThrow(
expect.objectContaining({
name: "LangSmithConflictError",
})
);
} finally {
try {
// Clean up: delete the project
if (await client.hasProject({ projectName })) {
await client.deleteProject({ projectName });
}
} catch (e) {
// Everyone has those days.
}
}
});

test("Test list prompts", async () => {
const client = new Client();
const uid = uuidv4();
Expand Down

0 comments on commit 4561fbf

Please sign in to comment.