Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.0.189 #3278

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion langchain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langchain",
"version": "0.0.188",
"version": "0.0.189",
"description": "Typescript bindings for langchain",
"type": "module",
"engines": {
Expand Down
77 changes: 77 additions & 0 deletions langchain/src/callbacks/tests/langchain_tracer_v1.int.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* eslint-disable no-process-env */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds code that explicitly accesses environment variables via process.env, which should be reviewed by maintainers to ensure proper handling and security.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds code that explicitly accesses environment variables via process.env, which should be reviewed by maintainers to ensure proper handling and security.

import * as uuid from "uuid";
import { test } from "@jest/globals";

import { LangChainTracerV1 } from "../handlers/tracer_langchain_v1.js";
import { OpenAI } from "../../llms/openai.js";
import { SerpAPI } from "../../tools/index.js";
import { Calculator } from "../../tools/calculator.js";
import { initializeAgentExecutorWithOptions } from "../../agents/index.js";
import { HumanMessage } from "../../schema/index.js";
import { Serialized } from "../../load/serializable.js";

const serialized: Serialized = {
lc: 1,
type: "constructor",
id: ["test"],
kwargs: {},
};

test("Test LangChain tracer", async () => {
const tracer = new LangChainTracerV1();
const chatRunId = uuid.v4();
const chainRunId = uuid.v4();
const toolRunId = uuid.v4();
const llmRunId = uuid.v4();
await tracer.handleChatModelStart(
serialized,
[[new HumanMessage("this is a message")]],
chatRunId
);
await tracer.handleLLMEnd({ generations: [[]] }, chatRunId);
await tracer.handleChainStart(serialized, { foo: "bar" }, chainRunId);
await tracer.handleToolStart(serialized, "test", toolRunId, chainRunId);
await tracer.handleLLMStart(serialized, ["test"], llmRunId, toolRunId);
await tracer.handleLLMEnd({ generations: [[]] }, llmRunId);
await tracer.handleToolEnd("output", toolRunId);
const llmRunId2 = uuid.v4();
await tracer.handleLLMStart(serialized, ["test"], llmRunId2, chainRunId);
await tracer.handleLLMEnd({ generations: [[]] }, llmRunId2);
await tracer.handleChainEnd({ foo: "bar" }, chainRunId);

const llmRunId3 = uuid.v4();
await tracer.handleLLMStart(serialized, ["test"], llmRunId3);
await tracer.handleLLMEnd({ generations: [[]] }, llmRunId3);
});

test("Test Traced Agent with concurrency", async () => {
process.env.LANGCHAIN_TRACING = "true";
const model = new OpenAI({ temperature: 0 });
const tools = [
new SerpAPI(process.env.SERPAPI_API_KEY, {
location: "Austin,Texas,United States",
hl: "en",
gl: "us",
}),
new Calculator(),
];

const executor = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "zero-shot-react-description",
verbose: true,
});

const input = `What is 24,678,987 raised to the 0.23 power?`;

console.log(`Executing with input "${input}"...`);

const [resultA, resultB, resultC] = await Promise.all([
executor.call({ input }),
executor.call({ input }),
executor.call({ input }),
]);

console.log(`Got output ${resultA.output}`);
console.log(`Got output ${resultB.output}`);
console.log(`Got output ${resultC.output}`);
});