@@ -2238,4 +2238,57 @@ describe.skip("InferenceClient", () => {
2238
2238
} ,
2239
2239
TIMEOUT
2240
2240
) ;
2241
+
2242
+ describe . concurrent (
2243
+ "PublicAI" ,
2244
+ ( ) => {
2245
+ const client = new InferenceClient ( env . HF_PUBLICAI_KEY ?? "dummy" ) ;
2246
+
2247
+ HARDCODED_MODEL_INFERENCE_MAPPING [ "publicai" ] = {
2248
+ "swiss-ai/Apertus-8B-Instruct-2509" : {
2249
+ provider : "publicai" ,
2250
+ hfModelId : "swiss-ai/Apertus-8B-Instruct-2509" ,
2251
+ providerId : "swiss-ai/apertus-8b-instruct" ,
2252
+ status : "live" ,
2253
+ task : "conversational" ,
2254
+ } ,
2255
+ } ;
2256
+
2257
+ it ( "chatCompletion" , async ( ) => {
2258
+ const res = await client . chatCompletion ( {
2259
+ model : "swiss-ai/Apertus-8B-Instruct-2509" ,
2260
+ provider : "publicai" ,
2261
+ messages : [ { role : "user" , content : "Complete this sentence with words, one plus one is equal " } ] ,
2262
+ } ) ;
2263
+ if ( res . choices && res . choices . length > 0 ) {
2264
+ const completion = res . choices [ 0 ] . message ?. content ;
2265
+ expect ( completion ) . toContain ( "two" ) ;
2266
+ }
2267
+ } ) ;
2268
+
2269
+ it ( "chatCompletion stream" , async ( ) => {
2270
+ const stream = client . chatCompletionStream ( {
2271
+ model : "swiss-ai/Apertus-8B-Instruct-2509" ,
2272
+ provider : "publicai" ,
2273
+ messages : [ { role : "user" , content : "Say 'this is a test'" } ] ,
2274
+ stream : true ,
2275
+ } ) as AsyncGenerator < ChatCompletionStreamOutput > ;
2276
+
2277
+ let fullResponse = "" ;
2278
+ for await ( const chunk of stream ) {
2279
+ if ( chunk . choices && chunk . choices . length > 0 ) {
2280
+ const content = chunk . choices [ 0 ] . delta ?. content ;
2281
+ if ( content ) {
2282
+ fullResponse += content ;
2283
+ }
2284
+ }
2285
+ }
2286
+
2287
+ // Verify we got a meaningful response
2288
+ expect ( fullResponse ) . toBeTruthy ( ) ;
2289
+ expect ( fullResponse . length ) . toBeGreaterThan ( 0 ) ;
2290
+ } ) ;
2291
+ } ,
2292
+ TIMEOUT
2293
+ ) ;
2241
2294
} ) ;
0 commit comments