forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move OpenAI tests and add one for JSON mode caching (langchain-ai#3754)
- Loading branch information
1 parent
b05bba3
commit e37a3df
Showing
8 changed files
with
128 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...odels/tests/chatopenai-vision.int.test.ts → .../src/tests/chat_models-vision.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { test, expect } from "@jest/globals"; | ||
import { OpenAIEmbeddings } from "../embeddings.js"; | ||
|
||
test("Test OpenAIEmbeddings.embedQuery", async () => { | ||
const embeddings = new OpenAIEmbeddings(); | ||
const res = await embeddings.embedQuery("Hello world"); | ||
expect(typeof res[0]).toBe("number"); | ||
}); | ||
|
||
test("Test OpenAIEmbeddings.embedDocuments", async () => { | ||
const embeddings = new OpenAIEmbeddings(); | ||
const res = await embeddings.embedDocuments(["Hello world", "Bye bye"]); | ||
expect(res).toHaveLength(2); | ||
expect(typeof res[0][0]).toBe("number"); | ||
expect(typeof res[1][0]).toBe("number"); | ||
}); | ||
|
||
test("Test OpenAIEmbeddings concurrency", async () => { | ||
const embeddings = new OpenAIEmbeddings({ | ||
batchSize: 1, | ||
maxConcurrency: 2, | ||
}); | ||
const res = await embeddings.embedDocuments([ | ||
"Hello world", | ||
"Bye bye", | ||
"Hello world", | ||
"Bye bye", | ||
"Hello world", | ||
"Bye bye", | ||
]); | ||
expect(res).toHaveLength(6); | ||
expect(res.find((embedding) => typeof embedding[0] !== "number")).toBe( | ||
undefined | ||
); | ||
}); | ||
|
||
test("Test timeout error thrown from SDK", async () => { | ||
await expect(async () => { | ||
const model = new OpenAIEmbeddings({ | ||
timeout: 1, | ||
}); | ||
await model.embedDocuments([ | ||
"Hello world", | ||
"Bye bye", | ||
"Hello world", | ||
"Bye bye", | ||
"Hello world", | ||
"Bye bye", | ||
]); | ||
}).rejects.toThrow(); | ||
}); | ||
|
||
test("Test OpenAI embeddings with an invalid org throws", async () => { | ||
await expect(async () => { | ||
const model = new OpenAIEmbeddings({ | ||
configuration: { | ||
organization: "NOT_REAL", | ||
}, | ||
}); | ||
await model.embedDocuments([ | ||
"Hello world", | ||
"Bye bye", | ||
"Hello world", | ||
"Bye bye", | ||
"Hello world", | ||
"Bye bye", | ||
]); | ||
}).rejects.toThrow(); | ||
}); |
4 changes: 2 additions & 2 deletions
4
...in/src/llms/tests/openai-chat.int.test.ts → ...chain-openai/src/tests/legacy.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
langchain/src/llms/tests/openai.int.test.ts → ...ngchain-openai/src/tests/llms.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters