Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
yuiseki committed Jan 12, 2025
1 parent bb97fe8 commit 5db6ae6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 36 deletions.
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
moduleNameMapper: {
"@/(.*)$": "<rootDir>/src/$1",
},
testTimeout: 60 * 1000,
globalSetup: "<rootDir>/src/tests/setup.ts",
};
42 changes: 31 additions & 11 deletions src/app/api/ai/surface/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,37 @@
import { POST } from "./route";

describe("POST /api/ai/surface", () => {
it("response something", async () => {
const requestObj = {
json: async () => ({
query: "台東区のラーメン屋を教えて",
pastMessages: undefined,
}),
} as any;
describe("without pastMessages", () => {
it("response something", async () => {
const requestObj = {
json: async () => ({
query: "台東区のラーメン屋を教えて",
pastMessages: undefined,
}),
} as any;

const res = await POST(requestObj);
const body = await res.json();
expect(res.status).toBe(200);
expect(body.surface.length).toBeGreaterThanOrEqual(1);
const res = await POST(requestObj);
const body = await res.json();
expect(res.status).toBe(200);
expect(body.surface.length).toBeGreaterThanOrEqual(1);
expect(body.surface).toContain("台東区");
});
});

describe("with pastMessages", () => {
it("response something", async () => {
const requestObj = {
json: async () => ({
query: "ラーメン屋を表示して",
pastMessages: ["台東区を表示して"],
}),
} as any;

const res = await POST(requestObj);
const body = await res.json();
expect(res.status).toBe(200);
expect(body.surface.length).toBeGreaterThanOrEqual(1);
expect(body.surface).toContain("台東区");
});
});
});
44 changes: 19 additions & 25 deletions src/utils/langchain/chains/loadTridentSurfaceChain/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import { ChatOllama } from "@langchain/ollama";
import { OllamaEmbeddings } from "@langchain/ollama";
import { loadTridentSurfaceChain } from ".";
import { MemoryVectorStore } from "langchain/vectorstores/memory";

// 60s
const TEST_TIMEOUT = 60000;
import { getChatModel } from "@/utils/trident/getChatModel";
import { getEmbeddingModel } from "@/utils/trident/getEmbeddingModel";

describe("loadTridentSurfaceChain", () => {
it(
"should return a RunnableSequence",
async () => {
const llm = new ChatOllama({
model: "qwen2.5:1.5b",
});
const embeddings = new OllamaEmbeddings({
model: "snowflake-arctic-embed:22m",
});
const vectorStore = new MemoryVectorStore(embeddings);
const chain = await loadTridentSurfaceChain({ llm, vectorStore });
expect(chain).toBeDefined();
const result = await chain.invoke({
input: "台東区のラーメン屋を教えて",
});
console.info("result", result.content);
expect(result.content).toBeDefined();
},
TEST_TIMEOUT
);
it("return a RunnableSequence", async () => {
const llm = getChatModel();
const embeddings = getEmbeddingModel();
const vectorStore = new MemoryVectorStore(embeddings);
const chain = await loadTridentSurfaceChain({ llm, vectorStore });
expect(chain).toBeDefined();
});
it("result contain 台東区", async () => {
const llm = getChatModel();
const embeddings = getEmbeddingModel();
const vectorStore = new MemoryVectorStore(embeddings);
const chain = await loadTridentSurfaceChain({ llm, vectorStore });
const result = await chain.invoke({
input: "台東区のラーメン屋を教えて",
});
expect(result.content).toContain("台東区");
});
});

0 comments on commit 5db6ae6

Please sign in to comment.