Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hwchase17/langchainjs into …
Browse files Browse the repository at this point in the history
…webllm
  • Loading branch information
jacoblee93 committed May 13, 2024
2 parents 56021bc + a57d58e commit 41a489d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 42 deletions.
13 changes: 0 additions & 13 deletions langchain/src/load/tests/__snapshots__/load.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,6 @@ kwargs:
"
`;

exports[`serialize + deserialize llm with optional deps 1`] = `
"lc: 1
type: constructor
id:
- langchain
- llms
- cohere
- Cohere
kwargs:
temperature: 0.5
"
`;

exports[`serialize + deserialize llmchain with list output parser 1`] = `
"lc: 1
type: constructor
Expand Down
37 changes: 8 additions & 29 deletions langchain/src/load/tests/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { test, expect } from "@jest/globals";
import { stringify } from "yaml";
import { z } from "zod";
import { RunnableSequence } from "@langchain/core/runnables";
import { Cohere } from "@langchain/cohere";
import { OpenAI, ChatOpenAI } from "@langchain/openai";

import {
Expand Down Expand Up @@ -161,26 +160,6 @@ test("serialize + deserialize llm", async () => {
expect(JSON.stringify(llm3, null, 2)).toBe(str);
});

test("serialize + deserialize llm with optional deps", async () => {
const llm = new Cohere({ temperature: 0.5, apiKey: "cohere-key" });
const str = JSON.stringify(llm, null, 2);
expect(stringify(JSON.parse(str))).toMatchSnapshot();
const llm2 = await load<Cohere>(
str,
{ COHERE_API_KEY: "cohere-key" },
{ "langchain/llms/cohere": { Cohere } }
);
expect(llm2).toBeInstanceOf(Cohere);
expect(JSON.stringify(llm2, null, 2)).toBe(str);
const llm3 = await load<Cohere>(
str,
{ COHERE_API_KEY: "cohere-key" },
{ "langchain/llms/cohere": import("@langchain/cohere") }
);
expect(llm3).toBeInstanceOf(Cohere);
expect(JSON.stringify(llm3, null, 2)).toBe(str);
});

test("serialize + deserialize llm chain string prompt", async () => {
const llm = new OpenAI({
temperature: 0.5,
Expand Down Expand Up @@ -455,30 +434,30 @@ test.skip("serialize + deserialize agent", async () => {
});

test("override name of objects when serialising", async () => {
const llm = new Cohere({ temperature: 0.5, apiKey: "cohere-key" });
const llm = new OpenAI({ temperature: 0.5, apiKey: "openai-key" });
const str = JSON.stringify(llm, null, 2);

class MangledName extends Cohere {}
const llm2 = await load<Cohere>(
class MangledName extends OpenAI {}
const llm2 = await load<OpenAI>(
str,
{ COHERE_API_KEY: "cohere-key" },
{ "langchain/llms/cohere": { Cohere: MangledName } }
{ OPENAI_API_KEY: "openai-key" },
{ "langchain/llms/openai": { OpenAI: MangledName } }
);
expect(JSON.stringify(llm2, null, 2)).toBe(str);
});

test("Should load traces even if the constructor name changes (minified environments)", async () => {
const llm = new Cohere({ temperature: 0.5, apiKey: "cohere-key" });
const llm = new OpenAI({ temperature: 0.5, apiKey: "openai-key" });
Object.defineProperty(llm.constructor, "name", {
value: "x",
});
const str = JSON.stringify(llm, null, 2);
console.log(str);

const llm2 = await load<Cohere>(
const llm2 = await load<OpenAI>(
str,
{ COHERE_API_KEY: "cohere-key" },
{ "langchain/llms/cohere": { Cohere } }
{ "langchain/llms/openai": { OpenAI } }
);
console.log(JSON.stringify(llm2, null, 2));
expect(JSON.stringify(llm2, null, 2)).toBe(str);
Expand Down

0 comments on commit 41a489d

Please sign in to comment.