1
- import fetch , { Response } from "node-fetch" ;
2
- import { EmbedOptions , FetchFunction } from "../.." ;
1
+ import { Response } from "node-fetch" ;
2
+ import { EmbeddingsProviderName , EmbedOptions , FetchFunction } from "../.." ;
3
3
import { withExponentialBackoff } from "../../util/withExponentialBackoff" ;
4
4
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider" ;
5
5
6
6
class HuggingFaceTEIEmbeddingsProvider extends BaseEmbeddingsProvider {
7
- private maxBatchSize = 32 ;
7
+ static providerName : EmbeddingsProviderName = "huggingface-tei" ;
8
+ maxBatchSize = 32 ;
8
9
9
10
static defaultOptions : Partial < EmbedOptions > | undefined = {
10
11
apiBase : "http://localhost:8080" ,
@@ -17,7 +18,7 @@ class HuggingFaceTEIEmbeddingsProvider extends BaseEmbeddingsProvider {
17
18
if ( ! this . options . apiBase ?. endsWith ( "/" ) ) {
18
19
this . options . apiBase += "/" ;
19
20
}
20
- this . doInfoRequest ( ) . then ( response => {
21
+ this . doInfoRequest ( ) . then ( ( response ) => {
21
22
this . options . model = response . model_id ;
22
23
this . maxBatchSize = response . max_client_batch_size ;
23
24
} ) ;
@@ -26,7 +27,9 @@ class HuggingFaceTEIEmbeddingsProvider extends BaseEmbeddingsProvider {
26
27
async embed ( chunks : string [ ] ) {
27
28
const promises = [ ] ;
28
29
for ( let i = 0 ; i < chunks . length ; i += this . maxBatchSize ) {
29
- promises . push ( this . doEmbedRequest ( chunks . slice ( i , i + this . maxBatchSize ) ) ) ;
30
+ promises . push (
31
+ this . doEmbedRequest ( chunks . slice ( i , i + this . maxBatchSize ) ) ,
32
+ ) ;
30
33
}
31
34
const results = await Promise . all ( promises ) ;
32
35
return results . flat ( ) ;
@@ -37,11 +40,11 @@ class HuggingFaceTEIEmbeddingsProvider extends BaseEmbeddingsProvider {
37
40
this . fetch ( new URL ( "embed" , this . options . apiBase ) , {
38
41
method : "POST" ,
39
42
body : JSON . stringify ( {
40
- inputs : batch
43
+ inputs : batch ,
41
44
} ) ,
42
45
headers : {
43
46
"Content-Type" : "application/json" ,
44
- }
47
+ } ,
45
48
} ) ,
46
49
) ;
47
50
if ( ! resp . ok ) {
@@ -75,9 +78,9 @@ class TEIEmbedError extends Error {
75
78
}
76
79
77
80
type TEIEmbedErrorResponse = {
78
- error : string
79
- error_type : string
80
- }
81
+ error : string ;
82
+ error_type : string ;
83
+ } ;
81
84
82
85
type TEIInfoResponse = {
83
86
model_id : string ;
@@ -86,7 +89,7 @@ type TEIInfoResponse = {
86
89
model_type : {
87
90
embedding : {
88
91
pooling : string ;
89
- }
92
+ } ;
90
93
} ;
91
94
max_concurrent_requests : number ;
92
95
max_input_length : number ;
0 commit comments