Skip to content

Commit a7f8d8a

Browse files
authored
fix: increase test timeouts and prevent concurrent model downloads in CI
1 parent 7ef68a6 commit a7f8d8a

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎src/embedder/embedder.ts‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,32 @@ type TransformersPipeline = (texts: string[], options: Record<string, unknown>)
99

1010
export class Embedder {
1111
private static pipeline: TransformersPipeline | null = null;
12+
private static pipelinePromise: Promise<TransformersPipeline> | null = null;
1213

1314
readonly dimensions = DEFAULT_DIMENSIONS;
1415

1516
private static async getPipeline(): Promise<TransformersPipeline> {
1617
if (Embedder.pipeline) return Embedder.pipeline;
1718

18-
const mod = await import('@huggingface/transformers');
19-
const hfEndpoint = process.env.HF_ENDPOINT;
20-
if (hfEndpoint && (mod as any).env) {
21-
(mod as any).env.remoteHost = hfEndpoint;
19+
if (!Embedder.pipelinePromise) {
20+
Embedder.pipelinePromise = (async () => {
21+
const mod = await import('@huggingface/transformers');
22+
const hfEndpoint = process.env.HF_ENDPOINT;
23+
if (hfEndpoint && (mod as any).env) {
24+
(mod as any).env.remoteHost = hfEndpoint;
25+
}
26+
27+
const pipe = await mod.pipeline('feature-extraction', DEFAULT_MODEL_ID) as TransformersPipeline;
28+
Embedder.pipeline = pipe;
29+
return Embedder.pipeline;
30+
})().catch((err) => {
31+
Embedder.pipeline = null;
32+
Embedder.pipelinePromise = null;
33+
throw err;
34+
});
2235
}
2336

24-
const pipe = await mod.pipeline('feature-extraction', DEFAULT_MODEL_ID) as TransformersPipeline;
25-
Embedder.pipeline = pipe;
26-
return Embedder.pipeline;
37+
return Embedder.pipelinePromise;
2738
}
2839

2940
async embed(text: string): Promise<number[]> {

‎vitest.config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { defineConfig } from 'vitest/config';
33
export default defineConfig({
44
test: {
55
include: ['test/**/*.test.ts'],
6-
testTimeout: 30000,
7-
hookTimeout: 30000,
6+
testTimeout: 120000,
7+
hookTimeout: 120000,
88
pool: 'forks',
99
poolOptions: {
1010
forks: { singleFork: true },

0 commit comments

Comments
 (0)