From 15f0288385892a3262186a0ec7cc785e39869776 Mon Sep 17 00:00:00 2001 From: Victor Mustar Date: Mon, 7 Oct 2024 12:31:40 +0200 Subject: [PATCH 1/4] README update --- README.md | 63 ++++++++++++++++++++---------------- packages/inference/README.md | 23 ++++++------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 42a4d5e2d..91103a9d6 100644 --- a/README.md +++ b/README.md @@ -29,18 +29,22 @@ await uploadFile({ // Use hosted inference -await inference.translation({ - model: 't5-base', - inputs: 'My name is Wolfgang and I live in Berlin' -}) +await hf.chatCompletion({ + model: "meta-llama/Llama-3.1-8B-Instruct", + messages: [ + { + role: "user", + content: "Hello, nice to meet you!", + }, + ], + max_tokens: 512, + temperature: 0.5, +}); -await inference.textToImage({ - model: 'stabilityai/stable-diffusion-2', - inputs: 'award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]', - parameters: { - negative_prompt: 'blurry', - } -}) +await hf.textToImage({ + model: "black-forest-labs/FLUX.1-dev", + inputs: "a picture of a green bird", +}); // and much moreā€¦ ``` @@ -123,29 +127,32 @@ const inference = new HfInference(HF_TOKEN); // Chat completion API const out = await inference.chatCompletion({ - model: "mistralai/Mistral-7B-Instruct-v0.2", - messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }], - max_tokens: 100 + model: "meta-llama/Llama-3.1-8B-Instruct", + messages: [{ role: "user", content: "Hello, nice to meet you!" }], + max_tokens: 512 }); console.log(out.choices[0].message); // Streaming chat completion API for await (const chunk of inference.chatCompletionStream({ - model: "mistralai/Mistral-7B-Instruct-v0.2", - messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }], - max_tokens: 100 + model: "meta-llama/Llama-3.1-8B-Instruct", + messages: [{ role: "user", content: "Hello, nice to meet you!" }], + max_tokens: 512 })) { console.log(chunk.choices[0].delta.content); } // You can also omit "model" to use the recommended model for the task -await inference.translation({ - model: 't5-base', - inputs: 'My name is Wolfgang and I live in Amsterdam' -}) +await hf.translation({ + inputs: "My name is Wolfgang and I live in Amsterdam", + parameters: { + src_lang: "en", + tgt_lang: "fr", + }, +}); await inference.textToImage({ - model: 'stabilityai/stable-diffusion-2', + model: 'black-forest-labs/FLUX.1-dev', inputs: 'award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]', parameters: { negative_prompt: 'blurry', @@ -162,13 +169,13 @@ const gpt2 = inference.endpoint('https://xyz.eu-west-1.aws.endpoints.huggingface const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the universe is'}); //Chat Completion -const mistal = inference.endpoint( - "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2" +const llamaEndpoint = inference.endpoint( + "https://api-inference.huggingface.co/models/meta-llama/Llama-3.1-8B-Instruct" ); -const out = await mistal.chatCompletion({ - model: "mistralai/Mistral-7B-Instruct-v0.2", - messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }], - max_tokens: 100, +const out = await llamaEndpoint.chatCompletion({ + model: "meta-llama/Llama-3.1-8B-Instruct", + messages: [{ role: "user", content: "Hello, nice to meet you!" }], + max_tokens: 512, }); console.log(out.choices[0].message); ``` diff --git a/packages/inference/README.md b/packages/inference/README.md index f97a8312e..11939338b 100644 --- a/packages/inference/README.md +++ b/packages/inference/README.md @@ -91,23 +91,21 @@ Using the `chatCompletion` method, you can generate text with models compatible ```typescript // Non-streaming API const out = await hf.chatCompletion({ - model: "mistralai/Mistral-7B-Instruct-v0.2", - messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }], - max_tokens: 500, + model: "meta-llama/Llama-3.1-8B-Instruct", + messages: [{ role: "user", content: "Hello, nice to meet you!" }], + max_tokens: 512, temperature: 0.1, - seed: 0, }); // Streaming API let out = ""; for await (const chunk of hf.chatCompletionStream({ - model: "mistralai/Mistral-7B-Instruct-v0.2", + model: "meta-llama/Llama-3.1-8B-Instruct", messages: [ - { role: "user", content: "Complete the equation 1+1= ,just the answer" }, + { role: "user", content: "Can you help me solve an equation?" }, ], - max_tokens: 500, + max_tokens: 512, temperature: 0.1, - seed: 0, })) { if (chunk.choices && chunk.choices.length > 0) { out += chunk.choices[0].delta.content; @@ -396,11 +394,8 @@ Creates an image from a text prompt. ```typescript await hf.textToImage({ - inputs: 'award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]', - model: 'stabilityai/stable-diffusion-2', - parameters: { - negative_prompt: 'blurry', - } + model: 'black-forest-labs/FLUX.1-dev', + inputs: 'a picture of a green bird' }) ``` @@ -583,7 +578,7 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the // Chat Completion Example const ep = hf.endpoint( - "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2" + "https://api-inference.huggingface.co/models/meta-llama/Llama-3.1-8B-Instruct" ); const stream = ep.chatCompletionStream({ model: "tgi", From b2cf6ab98ae41e0310c5b21a895d4e582af44802 Mon Sep 17 00:00:00 2001 From: Victor Mustar Date: Mon, 7 Oct 2024 12:33:40 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 91103a9d6..bf3a59ae7 100644 --- a/README.md +++ b/README.md @@ -153,10 +153,7 @@ await hf.translation({ await inference.textToImage({ model: 'black-forest-labs/FLUX.1-dev', - inputs: 'award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]', - parameters: { - negative_prompt: 'blurry', - } + inputs: 'a picture of a green bird', }) await inference.imageToText({ From c41183dd1f55dc9fee3aedcb85b903501e3c5c27 Mon Sep 17 00:00:00 2001 From: Victor Mustar Date: Mon, 7 Oct 2024 12:42:26 +0200 Subject: [PATCH 3/4] hosted inference -> inference API --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf3a59ae7..8d56c41e9 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ await uploadFile({ } }); -// Use hosted inference +// Use Inference API await hf.chatCompletion({ model: "meta-llama/Llama-3.1-8B-Instruct", From 20cb024fd876230029072706a8e4a09ad7a2a90e Mon Sep 17 00:00:00 2001 From: Victor Mustar Date: Mon, 7 Oct 2024 12:46:07 +0200 Subject: [PATCH 4/4] naming --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d56c41e9..84c0750bd 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ await uploadFile({ // Use Inference API -await hf.chatCompletion({ +await inference.chatCompletion({ model: "meta-llama/Llama-3.1-8B-Instruct", messages: [ { @@ -41,7 +41,7 @@ await hf.chatCompletion({ temperature: 0.5, }); -await hf.textToImage({ +await inference.textToImage({ model: "black-forest-labs/FLUX.1-dev", inputs: "a picture of a green bird", });