@@ -2,7 +2,8 @@ import { assert, describe, expect, it } from "vitest";
22
33import type { ChatCompletionStreamOutput } from "@huggingface/tasks" ;
44
5- import { chatCompletion , HfInference , textToImage } from "../src" ;
5+ import type { TextToImageArgs } from "../src" ;
6+ import { chatCompletion , chatCompletionStream , HfInference , textGeneration , textToImage } from "../src" ;
67import { textToVideo } from "../src/tasks/cv/textToVideo" ;
78import { readTestFile } from "./test-files" ;
89import "./vcr" ;
@@ -1176,6 +1177,85 @@ describe.concurrent("HfInference", () => {
11761177 TIMEOUT
11771178 ) ;
11781179
1180+ describe . concurrent (
1181+ "Hyperbolic" ,
1182+ ( ) => {
1183+ HARDCODED_MODEL_ID_MAPPING . hyperbolic = {
1184+ "meta-llama/Llama-3.2-3B-Instruct" : "meta-llama/Llama-3.2-3B-Instruct" ,
1185+ "meta-llama/Llama-3.3-70B-Instruct" : "meta-llama/Llama-3.3-70B-Instruct" ,
1186+ "stabilityai/stable-diffusion-2" : "SD2" ,
1187+ "meta-llama/Llama-3.1-405B" : "meta-llama/Meta-Llama-3.1-405B-Instruct" ,
1188+ } ;
1189+
1190+ it ( "chatCompletion - hyperbolic" , async ( ) => {
1191+ const res = await chatCompletion ( {
1192+ accessToken : env . HF_HYPERBOLIC_KEY ,
1193+ model : "meta-llama/Llama-3.2-3B-Instruct" ,
1194+ provider : "hyperbolic" ,
1195+ messages : [ { role : "user" , content : "Complete this sentence with words, one plus one is equal " } ] ,
1196+ temperature : 0.1 ,
1197+ } ) ;
1198+
1199+ expect ( res ) . toBeDefined ( ) ;
1200+ expect ( res . choices ) . toBeDefined ( ) ;
1201+ expect ( res . choices ?. length ) . toBeGreaterThan ( 0 ) ;
1202+
1203+ if ( res . choices && res . choices . length > 0 ) {
1204+ const completion = res . choices [ 0 ] . message ?. content ;
1205+ expect ( completion ) . toBeDefined ( ) ;
1206+ expect ( typeof completion ) . toBe ( "string" ) ;
1207+ expect ( completion ) . toContain ( "two" ) ;
1208+ }
1209+ } ) ;
1210+
1211+ it ( "chatCompletion stream" , async ( ) => {
1212+ const stream = chatCompletionStream ( {
1213+ accessToken : env . HF_HYPERBOLIC_KEY ,
1214+ model : "meta-llama/Llama-3.3-70B-Instruct" ,
1215+ provider : "hyperbolic" ,
1216+ messages : [ { role : "user" , content : "Complete the equation 1 + 1 = , just the answer" } ] ,
1217+ } ) as AsyncGenerator < ChatCompletionStreamOutput > ;
1218+ let out = "" ;
1219+ for await ( const chunk of stream ) {
1220+ if ( chunk . choices && chunk . choices . length > 0 ) {
1221+ out += chunk . choices [ 0 ] . delta . content ;
1222+ }
1223+ }
1224+ expect ( out ) . toContain ( "2" ) ;
1225+ } ) ;
1226+
1227+ it ( "textToImage" , async ( ) => {
1228+ const res = await textToImage ( {
1229+ accessToken : env . HF_HYPERBOLIC_KEY ,
1230+ model : "stabilityai/stable-diffusion-2" ,
1231+ provider : "hyperbolic" ,
1232+ inputs : "award winning high resolution photo of a giant tortoise" ,
1233+ parameters : {
1234+ height : 128 ,
1235+ width : 128 ,
1236+ } ,
1237+ } satisfies TextToImageArgs ) ;
1238+ expect ( res ) . toBeInstanceOf ( Blob ) ;
1239+ } ) ;
1240+
1241+ it ( "textGeneration" , async ( ) => {
1242+ const res = await textGeneration ( {
1243+ accessToken : env . HF_HYPERBOLIC_KEY ,
1244+ model : "meta-llama/Llama-3.1-405B" ,
1245+ provider : "hyperbolic" ,
1246+ inputs : "Paris is" ,
1247+ parameters : {
1248+ temperature : 0 ,
1249+ top_p : 0.01 ,
1250+ max_new_tokens : 10 ,
1251+ } ,
1252+ } ) ;
1253+ expect ( res ) . toMatchObject ( { generated_text : "...the capital and most populous city of France," } ) ;
1254+ } ) ;
1255+ } ,
1256+ TIMEOUT
1257+ ) ;
1258+
11791259 describe . concurrent (
11801260 "Novita" ,
11811261 ( ) => {
0 commit comments