New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@braintrust/langchain-js

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@braintrust/langchain-js - npm Package Compare versions

Comparing version

to
0.0.5

4

dist/index.d.ts

@@ -1,2 +0,2 @@

import { BaseCallbackHandler, BaseCallbackHandlerInput, NewTokenIndices, HandleLLMNewTokenCallbackFields } from '@langchain/core/callbacks/base';
import { BaseCallbackHandler, BaseCallbackHandlerInput } from '@langchain/core/callbacks/base';
import { AgentAction, AgentFinish } from '@langchain/core/dist/agents';

@@ -42,3 +42,2 @@ import { DocumentInterface } from '@langchain/core/dist/documents/document';

} | undefined;
handleLLMNewToken(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[], fields?: HandleLLMNewTokenCallbackFields): Promise<void>;
handleLLMError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;

@@ -67,3 +66,2 @@ handleLLMEnd(output: LLMResult | ChatResult, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;

handleRetrieverError(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
handleCustomEvent(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): Promise<void>;
}

@@ -70,0 +68,0 @@

@@ -84,3 +84,6 @@ "use strict";

let span = parentSpan.startSpan(args);
if (Object.is(span, import_braintrust.NOOP_SPAN)) {
if (
// If the original logger is NOOP_SPAN, we don't need bother folks to configure it.
!Object.is(this.options.logger, import_braintrust.NOOP_SPAN) && Object.is(span, import_braintrust.NOOP_SPAN)
) {
console.warn(

@@ -140,13 +143,2 @@ "Braintrust logging not configured. Pass a `logger`, call `initLogger`, or run an experiment to configure Braintrust logging. Setting up a default."

}
async handleLLMNewToken(token, idx, runId, parentRunId, tags, fields) {
console.warn(
"handleLLMNewToken not implemented",
token,
idx,
runId,
parentRunId,
tags,
fields
);
}
async handleLLMError(err, runId, parentRunId, tags) {

@@ -320,12 +312,2 @@ if (this.spans.has(runId)) {

}
async handleCustomEvent(eventName, data, runId, tags, metadata) {
console.warn(
"handleCustomEvent not implemented",
eventName,
data,
runId,
tags,
metadata
);
}
};

@@ -421,2 +403,5 @@ var extractCallArgs = (llm, invocationParams, metadata) => {

}
if (!output) {
return output;
}
if (output.content) {

@@ -423,0 +408,0 @@ return output.content;

{
"name": "@braintrust/langchain-js",
"version": "0.0.4",
"version": "0.0.5",
"description": "SDK for integrating Braintrust with LangChain.js",

@@ -32,3 +32,3 @@ "main": "./dist/index.js",

"dependencies": {
"@braintrust/core": "0.0.76",
"@braintrust/core": "0.0.77",
"braintrust": "^0.0.160"

@@ -35,0 +35,0 @@ },

@@ -6,3 +6,3 @@ import { ChatPromptTemplate, PromptTemplate } from "@langchain/core/prompts";

import { ChatOpenAI } from "@langchain/openai";
import { flush, initLogger } from "braintrust";
import { flush, initLogger, NOOP_SPAN } from "braintrust";
import { http, HttpResponse } from "msw";

@@ -813,2 +813,92 @@ import { ReadableStream } from "stream/web";

});
it("should have correctly typed constructor parameters", async () => {
const logs: LogsRequest[] = [];
server.use(
http.post("https://api.openai.com/v1/chat/completions", () => {
return HttpResponse.json(CHAT_MATH);
}),
http.post(/.+logs/, async ({ request }) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
logs.push((await request.json()) as LogsRequest);
return HttpResponse.json(["4bc6305f-2175-4481-bc84-7c55a456b7ea"]);
}),
);
const handler = new BraintrustCallbackHandler({
logger: NOOP_SPAN,
});
handler.handleLLMStart(
{
name: "test",
lc: 1,
type: "secret",
id: ["test"],
},
["test"],
"test",
"test",
);
await flush();
expect(logs).toEqual([]);
});
it("should handle chain inputs/outputs with null/undefined values", async () => {
const logs: LogsRequest[] = [];
server.use(
http.post(/.+logs/, async ({ request }) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
logs.push((await request.json()) as LogsRequest);
return HttpResponse.json(["null-span-id"]);
}),
);
// Test chain with null/undefined inputs
await handler.handleChainStart(
{ id: ["TestChain"], lc: 1, type: "not_implemented" },
{ input1: "value1", input2: null, input3: undefined },
"run-1",
undefined,
["test"],
);
await handler.handleChainEnd(
{ output1: "value1", output2: null, output3: undefined },
"run-1",
undefined,
["test"],
);
await flush();
const { spans, root_span_id } = logsToSpans(logs);
expect(spans).toMatchObject([
{
root_span_id,
span_attributes: {
name: "TestChain",
type: "task",
},
input: {
input1: "value1",
input2: null,
},
metadata: {
tags: ["test"],
runId: "run-1",
},
output: {
output1: "value1",
output2: null,
},
},
]);
});
});

@@ -5,4 +5,2 @@ import { isObject } from "@braintrust/core";

BaseCallbackHandlerInput,
HandleLLMNewTokenCallbackFields,
NewTokenIndices,
} from "@langchain/core/callbacks/base";

@@ -120,3 +118,7 @@ import { AgentAction, AgentFinish } from "@langchain/core/dist/agents";

if (Object.is(span, NOOP_SPAN)) {
if (
// If the original logger is NOOP_SPAN, we don't need bother folks to configure it.
!Object.is(this.options.logger, NOOP_SPAN) &&
Object.is(span, NOOP_SPAN)
) {
console.warn(

@@ -201,21 +203,2 @@ "Braintrust logging not configured. Pass a `logger`, call `initLogger`, or run an experiment to configure Braintrust logging. Setting up a default.",

async handleLLMNewToken(
token: string,
idx: NewTokenIndices,
runId: string,
parentRunId?: string,
tags?: string[],
fields?: HandleLLMNewTokenCallbackFields,
): Promise<void> {
console.warn(
"handleLLMNewToken not implemented",
token,
idx,
runId,
parentRunId,
tags,
fields,
);
}
async handleLLMError(

@@ -498,21 +481,2 @@ err: Error,

}
async handleCustomEvent(
eventName: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: any,
runId: string,
tags?: string[],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metadata?: Record<string, any>,
): Promise<void> {
console.warn(
"handleCustomEvent not implemented",
eventName,
data,
runId,
tags,
metadata,
);
}
}

@@ -643,2 +607,6 @@

if (!output) {
return output;
}
if (output.content) {

@@ -678,4 +646,3 @@ return output.content;

);
return parsed.length === 1 ? parsed[0] : parsed;
};

@@ -6,6 +6,6 @@ import { CallbackManager } from "@langchain/core/callbacks/manager";

import { http, HttpResponse } from "msw";
import { describe, expect, it } from "vitest";
import { afterEach, describe, expect, it } from "vitest";
import { BraintrustCallbackHandler } from "./BraintrustCallbackHandler";
import { CHAT_MATH } from "./BraintrustCallbackHandler.fixtures";
import { setGlobalHandler } from "./setGlobalHandler";
import { clearGlobalHandler, setGlobalHandler } from "./setGlobalHandler";
import { server } from "./test/setup";

@@ -18,2 +18,6 @@ import { LogsRequest } from "./test/types";

describe("setGlobalHandler", () => {
afterEach(() => {
clearGlobalHandler();
});
it("should register the BraintrustCallbackHandler", async () => {

@@ -20,0 +24,0 @@ setGlobalHandler(handler);

@@ -16,1 +16,5 @@ import { BaseCallbackHandler } from "@langchain/core/callbacks/base";

};
export const clearGlobalHandler = () => {
setContextVariable(BT_HANDLER, undefined);
};

@@ -71,3 +71,3 @@ import { mergeDicts } from "@braintrust/core";

export const withLogging = (handler: BaseCallbackHandler) => {
export const withLogging = <T extends BaseCallbackHandler>(handler: T): T => {
if (process.env.VERBOSE === "false") {

@@ -74,0 +74,0 @@ return handler;

{
"extends": ["//"],
"pipeline": {
"tasks": {
"build": {

@@ -5,0 +5,0 @@ "outputs": ["**/dist/**"]

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

Sorry, the diff of this file is not supported yet