langsmith
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -7,7 +7,8 @@ import * as fs from "fs"; | ||
import { setEnvironmentVariable } from "../utils/env.js"; | ||
import { spawn } from "child_process"; | ||
const currentFileName = __filename; | ||
const currentDirName = __dirname; | ||
const exec = util.promisify(child_process.exec); | ||
const program = new Command(); | ||
async function getDockerComposeCommand() { | ||
const exec = util.promisify(child_process.exec); | ||
try { | ||
@@ -106,3 +107,3 @@ await exec("docker compose --version"); | ||
} | ||
class PlusCommand { | ||
class SmithCommand { | ||
constructor({ dockerComposeCommand }) { | ||
@@ -121,2 +122,8 @@ Object.defineProperty(this, "dockerComposeCommand", { | ||
}); | ||
Object.defineProperty(this, "dockerComposeDevFile", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: "" | ||
}); | ||
Object.defineProperty(this, "ngrokPath", { | ||
@@ -130,11 +137,29 @@ enumerable: true, | ||
this.dockerComposeFile = path.join(path.dirname(currentFileName), "docker-compose.yaml"); | ||
this.dockerComposeDevFile = path.join(path.dirname(currentFileName), "docker-compose.dev.yaml"); | ||
this.ngrokPath = path.join(path.dirname(currentFileName), "docker-compose.ngrok.yaml"); | ||
} | ||
async executeCommand(command) { | ||
return new Promise((resolve, reject) => { | ||
const child = spawn(command[0], command.slice(1), { stdio: "inherit" }); | ||
child.on("error", (error) => { | ||
console.error(`error: ${error.message}`); | ||
reject(error); | ||
}); | ||
child.on("close", (code) => { | ||
if (code !== 0) { | ||
reject(new Error(`Process exited with code ${code}`)); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
static async create() { | ||
const dockerComposeCommand = await getDockerComposeCommand(); | ||
return new PlusCommand({ dockerComposeCommand }); | ||
return new SmithCommand({ dockerComposeCommand }); | ||
} | ||
async start(args) { | ||
if (args.dev) { | ||
setEnvironmentVariable("_LANGCHAINPLUS_IMAGE_PREFIX", "rc-"); | ||
setEnvironmentVariable("_LANGSMITH_IMAGE_PREFIX", "rc-"); | ||
} | ||
@@ -146,6 +171,6 @@ if (args.openaiApiKey) { | ||
if (args.expose) { | ||
await this.startAndExpose(args.ngrokAuthtoken); | ||
await this.startAndExpose(args.ngrokAuthtoken, args.dev); | ||
} | ||
else { | ||
await this.startLocal(); | ||
await this.startLocal(args.dev); | ||
} | ||
@@ -155,3 +180,3 @@ } | ||
if (args.dev) { | ||
setEnvironmentVariable("_LANGCHAINPLUS_IMAGE_PREFIX", "rc-"); | ||
setEnvironmentVariable("_LANGSMITH_IMAGE_PREFIX", "rc-"); | ||
} | ||
@@ -164,5 +189,5 @@ const command = [ | ||
]; | ||
await exec(command.join(" ")); | ||
await this.executeCommand(command); | ||
} | ||
async startLocal() { | ||
async startLocal(dev) { | ||
const command = [ | ||
@@ -172,11 +197,12 @@ ...this.dockerComposeCommand, | ||
this.dockerComposeFile, | ||
"up", | ||
"--quiet-pull", | ||
"--wait", | ||
]; | ||
await exec(command.join(" ")); | ||
if (dev) { | ||
command.push("-f", this.dockerComposeDevFile); | ||
} | ||
command.push("up", "--quiet-pull", "--wait"); | ||
await this.executeCommand(command); | ||
console.info("LangSmith server is running at http://localhost:1984. To connect locally, set the following environment variable when running your LangChain application."); | ||
console.info("\tLANGCHAIN_TRACING_V2=true"); | ||
} | ||
async startAndExpose(ngrokAuthToken) { | ||
async startAndExpose(ngrokAuthToken, dev) { | ||
const configPath = await createNgrokConfig(ngrokAuthToken); | ||
@@ -189,7 +215,8 @@ const command = [ | ||
this.ngrokPath, | ||
"up", | ||
"--quiet-pull", | ||
"--wait", | ||
]; | ||
await exec(command.join(" ")); | ||
if (dev) { | ||
command.push("-f", this.dockerComposeDevFile); | ||
} | ||
command.push("up", "--quiet-pull", "--wait"); | ||
await this.executeCommand(command); | ||
console.info("ngrok is running. You can view the dashboard at http://0.0.0.0:4040"); | ||
@@ -211,3 +238,3 @@ const ngrokUrl = await getNgrokUrl(); | ||
]; | ||
await exec(command.join(" ")); | ||
await this.executeCommand(command); | ||
} | ||
@@ -223,2 +250,3 @@ async status() { | ||
]; | ||
const exec = util.promisify(child_process.exec); | ||
const result = await exec(command.join(" ")); | ||
@@ -240,8 +268,10 @@ const servicesStatus = JSON.parse(result.stdout); | ||
.option("--dev", "Run the development version of the LangSmith server") | ||
.option("--openai-api-key <openaiApiKey>", "Your OpenAI API key. If this is set, the server will be able to process text and return enhanced plus results.") | ||
.action(async (args) => (await PlusCommand.create()).start(args)); | ||
.option("--openai-api-key <openaiApiKey>", "Your OpenAI API key. If not provided, the OpenAI API Key will be read" + | ||
" from the OPENAI_API_KEY environment variable. If neither are provided," + | ||
" some features of LangSmith will not be available.") | ||
.action(async (args) => (await SmithCommand.create()).start(args)); | ||
const stopCommand = new Command("stop") | ||
.command("stop") | ||
.description("Stop the LangSmith server") | ||
.action(async () => (await PlusCommand.create()).stop()); | ||
.action(async () => (await SmithCommand.create()).stop()); | ||
const pullCommand = new Command("pull") | ||
@@ -251,7 +281,7 @@ .command("pull") | ||
.option("--dev", "Pull the development version of the LangSmith server") | ||
.action(async (args) => (await PlusCommand.create()).pull(args)); | ||
.action(async (args) => (await SmithCommand.create()).pull(args)); | ||
const statusCommand = new Command("status") | ||
.command("status") | ||
.description("Get the status of the LangSmith server") | ||
.action(async () => (await PlusCommand.create()).status()); | ||
.action(async () => (await SmithCommand.create()).status()); | ||
program | ||
@@ -258,0 +288,0 @@ .description("Manage the LangSmith server") |
@@ -7,2 +7,3 @@ import * as fs from "fs"; | ||
import { setEnvironmentVariable } from "../utils/env.js"; | ||
import { spawn } from "child_process"; | ||
@@ -12,7 +13,6 @@ const currentFileName = __filename; | ||
const exec = util.promisify(child_process.exec); | ||
const program = new Command(); | ||
async function getDockerComposeCommand(): Promise<string[]> { | ||
const exec = util.promisify(child_process.exec); | ||
try { | ||
@@ -127,5 +127,6 @@ await exec("docker compose --version"); | ||
class PlusCommand { | ||
class SmithCommand { | ||
dockerComposeCommand: string[] = []; | ||
dockerComposeFile = ""; | ||
dockerComposeDevFile = ""; | ||
ngrokPath = ""; | ||
@@ -139,2 +140,6 @@ | ||
); | ||
this.dockerComposeDevFile = path.join( | ||
path.dirname(currentFileName), | ||
"docker-compose.dev.yaml" | ||
); | ||
this.ngrokPath = path.join( | ||
@@ -146,5 +151,24 @@ path.dirname(currentFileName), | ||
async executeCommand(command: string[]) { | ||
return new Promise<void>((resolve, reject) => { | ||
const child = spawn(command[0], command.slice(1), { stdio: "inherit" }); | ||
child.on("error", (error) => { | ||
console.error(`error: ${error.message}`); | ||
reject(error); | ||
}); | ||
child.on("close", (code) => { | ||
if (code !== 0) { | ||
reject(new Error(`Process exited with code ${code}`)); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
public static async create() { | ||
const dockerComposeCommand = await getDockerComposeCommand(); | ||
return new PlusCommand({ dockerComposeCommand }); | ||
return new SmithCommand({ dockerComposeCommand }); | ||
} | ||
@@ -154,3 +178,3 @@ | ||
if (args.dev) { | ||
setEnvironmentVariable("_LANGCHAINPLUS_IMAGE_PREFIX", "rc-"); | ||
setEnvironmentVariable("_LANGSMITH_IMAGE_PREFIX", "rc-"); | ||
} | ||
@@ -162,5 +186,5 @@ if (args.openaiApiKey) { | ||
if (args.expose) { | ||
await this.startAndExpose(args.ngrokAuthtoken); | ||
await this.startAndExpose(args.ngrokAuthtoken, args.dev); | ||
} else { | ||
await this.startLocal(); | ||
await this.startLocal(args.dev); | ||
} | ||
@@ -171,3 +195,3 @@ } | ||
if (args.dev) { | ||
setEnvironmentVariable("_LANGCHAINPLUS_IMAGE_PREFIX", "rc-"); | ||
setEnvironmentVariable("_LANGSMITH_IMAGE_PREFIX", "rc-"); | ||
} | ||
@@ -181,6 +205,6 @@ | ||
]; | ||
await exec(command.join(" ")); | ||
await this.executeCommand(command); | ||
} | ||
async startLocal() { | ||
async startLocal(dev: boolean) { | ||
const command = [ | ||
@@ -190,7 +214,8 @@ ...this.dockerComposeCommand, | ||
this.dockerComposeFile, | ||
"up", | ||
"--quiet-pull", | ||
"--wait", | ||
]; | ||
await exec(command.join(" ")); | ||
if (dev) { | ||
command.push("-f", this.dockerComposeDevFile); | ||
} | ||
command.push("up", "--quiet-pull", "--wait"); | ||
await this.executeCommand(command); | ||
console.info( | ||
@@ -202,3 +227,3 @@ "LangSmith server is running at http://localhost:1984. To connect locally, set the following environment variable when running your LangChain application." | ||
async startAndExpose(ngrokAuthToken: string | null) { | ||
async startAndExpose(ngrokAuthToken: string | null, dev: boolean) { | ||
const configPath = await createNgrokConfig(ngrokAuthToken); | ||
@@ -211,7 +236,8 @@ const command = [ | ||
this.ngrokPath, | ||
"up", | ||
"--quiet-pull", | ||
"--wait", | ||
]; | ||
await exec(command.join(" ")); | ||
if (dev) { | ||
command.push("-f", this.dockerComposeDevFile); | ||
} | ||
command.push("up", "--quiet-pull", "--wait"); | ||
await this.executeCommand(command); | ||
console.info( | ||
@@ -239,3 +265,3 @@ "ngrok is running. You can view the dashboard at http://0.0.0.0:4040" | ||
]; | ||
await exec(command.join(" ")); | ||
await this.executeCommand(command); | ||
} | ||
@@ -251,2 +277,3 @@ async status() { | ||
]; | ||
const exec = util.promisify(child_process.exec); | ||
const result = await exec(command.join(" ")); | ||
@@ -276,5 +303,7 @@ const servicesStatus = JSON.parse(result.stdout); | ||
"--openai-api-key <openaiApiKey>", | ||
"Your OpenAI API key. If this is set, the server will be able to process text and return enhanced plus results." | ||
"Your OpenAI API key. If not provided, the OpenAI API Key will be read" + | ||
" from the OPENAI_API_KEY environment variable. If neither are provided," + | ||
" some features of LangSmith will not be available." | ||
) | ||
.action(async (args: string[]) => (await PlusCommand.create()).start(args)); | ||
.action(async (args: string[]) => (await SmithCommand.create()).start(args)); | ||
@@ -284,3 +313,3 @@ const stopCommand = new Command("stop") | ||
.description("Stop the LangSmith server") | ||
.action(async () => (await PlusCommand.create()).stop()); | ||
.action(async () => (await SmithCommand.create()).stop()); | ||
@@ -291,3 +320,3 @@ const pullCommand = new Command("pull") | ||
.option("--dev", "Pull the development version of the LangSmith server") | ||
.action(async (args: string[]) => (await PlusCommand.create()).pull(args)); | ||
.action(async (args: string[]) => (await SmithCommand.create()).pull(args)); | ||
@@ -297,3 +326,3 @@ const statusCommand = new Command("status") | ||
.description("Get the status of the LangSmith server") | ||
.action(async () => (await PlusCommand.create()).status()); | ||
.action(async () => (await SmithCommand.create()).status()); | ||
@@ -300,0 +329,0 @@ program |
@@ -60,3 +60,3 @@ import * as uuid from "uuid"; | ||
if (!isLocal && !this.apiKey) { | ||
throw new Error("API key must be provided when using hosted LangChain+ API"); | ||
throw new Error("API key must be provided when using hosted LangSmith API"); | ||
} | ||
@@ -63,0 +63,0 @@ } |
{ | ||
"name": "langsmith", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.", | ||
@@ -5,0 +5,0 @@ "files": [ |
# LangSmith Client SDK | ||
This package contains the TypeScript client for interacting with the [LangSmith platform](https://www.langchain.plus/). | ||
This package contains the TypeScript client for interacting with the [LangSmith platform](https://smith.langchain.com/). | ||
@@ -17,3 +17,3 @@ To install: | ||
1. Set up an account with LangSmith or host your [local server](https://docs.langchain.plus/docs/getting-started/local_installation). | ||
1. Set up an account with LangSmith or host your [local server](https://docs.smith.langchain.com/docs/getting-started/local_installation). | ||
2. Log traces. | ||
@@ -26,5 +26,5 @@ 3. Debug, Create Datasets, and Evaluate Runs. | ||
Sign up for [LangSmith](https://www.langchain.plus/) using your GitHub, Discord accounts, or an email address and password. If you sign up with an email, make sure to verify your email address before logging in. | ||
Sign up for [LangSmith](https://smith.langchain.com/) using your GitHub, Discord accounts, or an email address and password. If you sign up with an email, make sure to verify your email address before logging in. | ||
Then, create a unique API key on the [Settings Page](https://www.langchain.plus/settings), which is found in the menu at the top right corner of the page. | ||
Then, create a unique API key on the [Settings Page](https://smith.langchain.com/settings), which is found in the menu at the top right corner of the page. | ||
@@ -51,4 +51,4 @@ Note: Save the API Key in a secure location. It will not be shown again. | ||
process.env["LANGCHAIN_TRACING_V2"] = "true"; | ||
process.env["LANGCHAIN_ENDPOINT"] = "https://api.langchain.plus"; // or your own server | ||
process.env["LANGCHAIN_API_KEY"] = "<YOUR-LANGCHAINPLUS-API-KEY>"; | ||
process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"; // or your own server | ||
process.env["LANGCHAIN_API_KEY"] = "<YOUR-LANGSMITH-API-KEY>"; | ||
// process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set | ||
@@ -84,4 +84,4 @@ ``` | ||
```typescript | ||
process.env["LANGCHAIN_ENDPOINT"] = "https://api.langchain.plus"; // or your own server | ||
process.env["LANGCHAIN_API_KEY"] = "<YOUR-LANGCHAINPLUS-API-KEY>"; | ||
process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"; // or your own server | ||
process.env["LANGCHAIN_API_KEY"] = "<YOUR-LANGSMITH-API-KEY>"; | ||
// process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set | ||
@@ -184,3 +184,3 @@ ``` | ||
For this example, we will do so using the Client, but you can also do this using | ||
the web interface, as explained in the [LangSmith docs](https://docs.langchain.plus/docs/). | ||
the web interface, as explained in the [LangSmith docs](https://docs.smith.langchain.com/docs/). | ||
@@ -267,2 +267,2 @@ ```typescript | ||
To learn more about the LangSmith platform, check out the [docs](https://docs.langchain.plus/docs/). | ||
To learn more about the LangSmith platform, check out the [docs](https://docs.smith.langchain.com/docs/). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138414
51
3413
36