langsmith
Advanced tools
Comparing version 0.0.33 to 0.0.34
@@ -6,3 +6,3 @@ import * as fs from "fs"; | ||
import * as child_process from "child_process"; | ||
import { setEnvironmentVariable } from "../utils/env.js"; | ||
import { getDockerEnvironment, getLangChainEnvVars, getRuntimeEnvironment, setEnvironmentVariable, } from "../utils/env.js"; | ||
import { spawn } from "child_process"; | ||
@@ -263,2 +263,18 @@ const currentFileName = __filename; | ||
} | ||
async env() { | ||
const env = await getRuntimeEnvironment(); | ||
const dockerEnv = await getDockerEnvironment(); | ||
const envVars = await getLangChainEnvVars(); | ||
const envDict = { | ||
...env, | ||
...dockerEnv, | ||
...envVars, | ||
}; | ||
// Pretty print | ||
const maxKeyLength = Math.max(...Object.keys(envDict).map((key) => key.length)); | ||
console.info("LangChain Environment:"); | ||
for (const [key, value] of Object.entries(envDict)) { | ||
console.info(`${key.padEnd(maxKeyLength)}: ${value}`); | ||
} | ||
} | ||
} | ||
@@ -317,2 +333,8 @@ const startCommand = new Command("start") | ||
}); | ||
const envCommand = new Command("env") | ||
.description("Get relevant environment information for the LangSmith server") | ||
.action(async () => { | ||
const smith = await SmithCommand.create(); | ||
await smith.env(); | ||
}); | ||
program | ||
@@ -323,3 +345,4 @@ .description("Manage the LangSmith server") | ||
.addCommand(pullCommand) | ||
.addCommand(statusCommand); | ||
.addCommand(statusCommand) | ||
.addCommand(envCommand); | ||
program.parse(process.argv); |
@@ -6,3 +6,8 @@ import * as fs from "fs"; | ||
import * as child_process from "child_process"; | ||
import { setEnvironmentVariable } from "../utils/env.js"; | ||
import { | ||
getDockerEnvironment, | ||
getLangChainEnvVars, | ||
getRuntimeEnvironment, | ||
setEnvironmentVariable, | ||
} from "../utils/env.js"; | ||
import { spawn } from "child_process"; | ||
@@ -291,2 +296,21 @@ | ||
} | ||
async env() { | ||
const env = await getRuntimeEnvironment(); | ||
const dockerEnv = await getDockerEnvironment(); | ||
const envVars = await getLangChainEnvVars(); | ||
const envDict = { | ||
...env, | ||
...dockerEnv, | ||
...envVars, | ||
}; | ||
// Pretty print | ||
const maxKeyLength = Math.max( | ||
...Object.keys(envDict).map((key) => key.length) | ||
); | ||
console.info("LangChain Environment:"); | ||
for (const [key, value] of Object.entries(envDict)) { | ||
console.info(`${key.padEnd(maxKeyLength)}: ${value}`); | ||
} | ||
} | ||
} | ||
@@ -362,2 +386,9 @@ | ||
const envCommand = new Command("env") | ||
.description("Get relevant environment information for the LangSmith server") | ||
.action(async () => { | ||
const smith = await SmithCommand.create(); | ||
await smith.env(); | ||
}); | ||
program | ||
@@ -368,4 +399,5 @@ .description("Manage the LangSmith server") | ||
.addCommand(pullCommand) | ||
.addCommand(statusCommand); | ||
.addCommand(statusCommand) | ||
.addCommand(envCommand); | ||
program.parse(process.argv); |
@@ -51,2 +51,3 @@ import { AsyncCallerParams } from "./utils/async_caller.js"; | ||
} | ||
export type FeedbackSourceType = "model" | "api" | "app"; | ||
export declare class Client { | ||
@@ -146,3 +147,3 @@ private apiKey?; | ||
sourceInfo?: object; | ||
feedbackSourceType?: "API" | "MODEL"; | ||
feedbackSourceType?: FeedbackSourceType; | ||
sourceRunId?: string; | ||
@@ -158,6 +159,8 @@ }): Promise<Feedback>; | ||
deleteFeedback(feedbackId: string): Promise<void>; | ||
listFeedback({ runIds, }?: { | ||
listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, }?: { | ||
runIds?: string[]; | ||
feedbackKeys?: string[]; | ||
feedbackSourceTypes?: FeedbackSourceType[]; | ||
}): AsyncIterable<Feedback>; | ||
} | ||
export {}; |
@@ -34,2 +34,14 @@ import * as uuid from "uuid"; | ||
} | ||
function hideInputs(inputs) { | ||
if (getEnvironmentVariable("LANGCHAIN_HIDE_INPUTS") === "true") { | ||
return {}; | ||
} | ||
return inputs; | ||
} | ||
function hideOutputs(outputs) { | ||
if (getEnvironmentVariable("LANGCHAIN_HIDE_OUTPUTS") === "true") { | ||
return {}; | ||
} | ||
return outputs; | ||
} | ||
export class Client { | ||
@@ -157,2 +169,6 @@ constructor(config = {}) { | ||
}; | ||
runCreate.inputs = hideInputs(runCreate.inputs); | ||
if (runCreate.outputs) { | ||
runCreate.outputs = hideOutputs(runCreate.outputs); | ||
} | ||
const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, { | ||
@@ -167,2 +183,8 @@ method: "POST", | ||
async updateRun(runId, run) { | ||
if (run.inputs) { | ||
run.inputs = hideInputs(run.inputs); | ||
} | ||
if (run.outputs) { | ||
run.outputs = hideOutputs(run.outputs); | ||
} | ||
const headers = { ...this.headers, "Content-Type": "application/json" }; | ||
@@ -650,16 +672,10 @@ const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, { | ||
sourceInfo: sourceInfo_, | ||
feedbackSourceType: "MODEL", | ||
feedbackSourceType: "model", | ||
}); | ||
} | ||
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "API", sourceRunId, }) { | ||
let feedback_source; | ||
if (feedbackSourceType === "API") { | ||
feedback_source = { type: "api", metadata: sourceInfo ?? {} }; | ||
} | ||
else if (feedbackSourceType === "MODEL") { | ||
feedback_source = { type: "model", metadata: sourceInfo ?? {} }; | ||
} | ||
else { | ||
throw new Error(`Unknown feedback source type ${feedbackSourceType}`); | ||
} | ||
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, }) { | ||
const feedback_source = { | ||
type: feedbackSourceType ?? "api", | ||
metadata: sourceInfo ?? {}, | ||
}; | ||
if (sourceRunId !== undefined && | ||
@@ -731,3 +747,3 @@ feedback_source?.metadata !== undefined && | ||
} | ||
async *listFeedback({ runIds, } = {}) { | ||
async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, } = {}) { | ||
const queryParams = new URLSearchParams(); | ||
@@ -737,2 +753,12 @@ if (runIds) { | ||
} | ||
if (feedbackKeys) { | ||
for (const key of feedbackKeys) { | ||
queryParams.append("key", key); | ||
} | ||
} | ||
if (feedbackSourceTypes) { | ||
for (const type of feedbackSourceTypes) { | ||
queryParams.append("source", type); | ||
} | ||
} | ||
for await (const feedbacks of this._getPaginated("/feedback", queryParams)) { | ||
@@ -739,0 +765,0 @@ yield* feedbacks; |
@@ -21,2 +21,26 @@ declare global { | ||
export declare function getRuntimeEnvironment(): Promise<RuntimeEnvironment>; | ||
export declare function getDockerEnvironment(): Promise<{ | ||
dockerVersion: string | undefined; | ||
dockerComposeCommand: string | undefined; | ||
dockerComposeVersion: string | undefined; | ||
}>; | ||
/** | ||
* Retrieves the LangChain-specific environment variables from the current runtime environment. | ||
* Sensitive keys (containing the word "key") have their values redacted for security. | ||
* | ||
* @returns {Record<string, string>} | ||
* - A record of LangChain-specific environment variables. | ||
*/ | ||
export declare function getLangChainEnvVars(): Record<string, string>; | ||
/** | ||
* Retrieves the environment variables from the current runtime environment. | ||
* | ||
* This function is designed to operate in a variety of JS environments, | ||
* including Node.js, Deno, browsers, etc. | ||
* | ||
* @returns {Record<string, string> | undefined} | ||
* - A record of environment variables if available. | ||
* - `undefined` if the environment does not support or allows access to environment variables. | ||
*/ | ||
export declare function getEnvironmentVariables(): Record<string, string> | undefined; | ||
export declare function getEnvironmentVariable(name: string): string | undefined; | ||
@@ -23,0 +47,0 @@ export declare function setEnvironmentVariable(name: string, value: string): void; |
@@ -0,1 +1,2 @@ | ||
import { exec } from "child_process"; | ||
export const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined"; | ||
@@ -52,2 +53,98 @@ export const isWebWorker = () => typeof globalThis === "object" && | ||
} | ||
export async function getDockerEnvironment() { | ||
const getDockerVersion = () => new Promise((resolve) => { | ||
exec("docker --version", (error, stdout) => { | ||
if (error) { | ||
resolve(undefined); | ||
} | ||
else { | ||
resolve(stdout.trim()); | ||
} | ||
}); | ||
}); | ||
const getDockerComposeCommand = () => new Promise((resolve) => { | ||
exec("which docker-compose", (error, stdout) => { | ||
if (error) { | ||
resolve(undefined); | ||
} | ||
else { | ||
resolve(stdout.trim()); | ||
} | ||
}); | ||
}); | ||
const getDockerComposeVersion = () => new Promise((resolve) => { | ||
exec("docker-compose --version", (error, stdout) => { | ||
if (error) { | ||
resolve(undefined); | ||
} | ||
else { | ||
resolve(stdout.trim()); | ||
} | ||
}); | ||
}); | ||
const [dockerVersion, dockerComposeCommand, dockerComposeVersion] = await Promise.all([ | ||
getDockerVersion(), | ||
getDockerComposeCommand(), | ||
getDockerComposeVersion(), | ||
]); | ||
return { | ||
dockerVersion, | ||
dockerComposeCommand, | ||
dockerComposeVersion, | ||
}; | ||
} | ||
/** | ||
* Retrieves the LangChain-specific environment variables from the current runtime environment. | ||
* Sensitive keys (containing the word "key") have their values redacted for security. | ||
* | ||
* @returns {Record<string, string>} | ||
* - A record of LangChain-specific environment variables. | ||
*/ | ||
export function getLangChainEnvVars() { | ||
const allEnvVars = getEnvironmentVariables() || {}; | ||
const envVars = {}; | ||
for (const [key, value] of Object.entries(allEnvVars)) { | ||
if (key.startsWith("LANGCHAIN_") && typeof value === "string") { | ||
envVars[key] = value; | ||
} | ||
} | ||
for (const key in envVars) { | ||
if (key.toLowerCase().includes("key") && typeof envVars[key] === "string") { | ||
const value = envVars[key]; | ||
envVars[key] = | ||
value.slice(0, 2) + "*".repeat(value.length - 4) + value.slice(-2); | ||
} | ||
} | ||
return envVars; | ||
} | ||
/** | ||
* Retrieves the environment variables from the current runtime environment. | ||
* | ||
* This function is designed to operate in a variety of JS environments, | ||
* including Node.js, Deno, browsers, etc. | ||
* | ||
* @returns {Record<string, string> | undefined} | ||
* - A record of environment variables if available. | ||
* - `undefined` if the environment does not support or allows access to environment variables. | ||
*/ | ||
export function getEnvironmentVariables() { | ||
try { | ||
// Check for Node.js environment | ||
// eslint-disable-next-line no-process-env | ||
if (typeof process !== "undefined" && process.env) { | ||
// eslint-disable-next-line no-process-env | ||
Object.entries(process.env).reduce((acc, [key, value]) => { | ||
acc[key] = String(value); | ||
return acc; | ||
}, {}); | ||
} | ||
// For browsers and other environments, we may not have direct access to env variables | ||
// Return undefined or any other fallback as required. | ||
return undefined; | ||
} | ||
catch (e) { | ||
// Catch any errors that might occur while trying to access environment variables | ||
return undefined; | ||
} | ||
} | ||
export function getEnvironmentVariable(name) { | ||
@@ -54,0 +151,0 @@ // Certain Deno setups will throw an error if you try to access environment variables |
{ | ||
"name": "langsmith", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.", | ||
@@ -5,0 +5,0 @@ "files": [ |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances 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
176642
4418
1
10
46