-
Notifications
You must be signed in to change notification settings - Fork 533
Adapt generate-snippets-fixtures script for providers #1137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
julien-c
merged 3 commits into
inference/providers-snippets
from
inference/providers-snippets-adapt-test-script
Jan 24, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
packages/tasks-gen/snippets-fixtures/conversational-llm-non-stream/0.curl.replicate.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
curl 'https://huggingface.co/api/inference-proxy/replicate/v1/chat/completions' \ | ||
-H 'Authorization: Bearer api_token' \ | ||
-H 'Content-Type: application/json' \ | ||
--data '{ | ||
"model": "meta-llama/Llama-3.1-8B-Instruct", | ||
"messages": [ | ||
{ | ||
"role": "user", | ||
"content": "What is the capital of France?" | ||
} | ||
], | ||
"max_tokens": 500, | ||
"stream": false | ||
}' |
17 changes: 17 additions & 0 deletions
17
...asks-gen/snippets-fixtures/conversational-llm-non-stream/0.huggingface.js.hf-inference.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { HfInference } from "@huggingface/inference"; | ||
|
||
const client = new HfInference("api_token"); | ||
|
||
const chatCompletion = await client.chatCompletion({ | ||
model: "meta-llama/Llama-3.1-8B-Instruct", | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: "What is the capital of France?" | ||
} | ||
], | ||
provider: "hf-inference", | ||
max_tokens: 500 | ||
}); | ||
|
||
console.log(chatCompletion.choices[0].message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...sks-gen/snippets-fixtures/conversational-llm-non-stream/0.huggingface_hub.hf-inference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from huggingface_hub import InferenceClient | ||
|
||
client = InferenceClient( | ||
provider="hf-inference", | ||
api_key="api_token" | ||
) | ||
|
||
messages = [ | ||
{ | ||
"role": "user", | ||
"content": "What is the capital of France?" | ||
} | ||
] | ||
|
||
completion = client.chat.completions.create( | ||
model="meta-llama/Llama-3.1-8B-Instruct", | ||
messages=messages, | ||
max_tokens=500 | ||
) | ||
|
||
print(completion.choices[0].message) |
5 changes: 4 additions & 1 deletion
5
...ional-llm-non-stream/0.huggingface_hub.py → ...non-stream/0.huggingface_hub.replicate.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...conversational-llm-non-stream/1.openai.js → ...l-llm-non-stream/1.openai.hf-inference.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
packages/tasks-gen/snippets-fixtures/conversational-llm-non-stream/1.openai.replicate.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { OpenAI } from "openai"; | ||
|
||
const client = new OpenAI({ | ||
baseURL: "https://huggingface.co/api/inference-proxy/replicate", | ||
apiKey: "api_token" | ||
}); | ||
|
||
const chatCompletion = await client.chat.completions.create({ | ||
model: "meta-llama/Llama-3.1-8B-Instruct", | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: "What is the capital of France?" | ||
} | ||
], | ||
max_tokens: 500 | ||
}); | ||
|
||
console.log(chatCompletion.choices[0].message); |
21 changes: 21 additions & 0 deletions
21
packages/tasks-gen/snippets-fixtures/conversational-llm-non-stream/1.openai.replicate.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from openai import OpenAI | ||
|
||
client = OpenAI( | ||
base_url="https://huggingface.co/api/inference-proxy/replicate", | ||
api_key="api_token" | ||
) | ||
|
||
messages = [ | ||
{ | ||
"role": "user", | ||
"content": "What is the capital of France?" | ||
} | ||
] | ||
|
||
completion = client.chat.completions.create( | ||
model="meta-llama/Llama-3.1-8B-Instruct", | ||
messages=messages, | ||
max_tokens=500 | ||
) | ||
|
||
print(completion.choices[0].message) |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...rsational-llm-stream/0.huggingface_hub.py → ...-stream/0.huggingface_hub.hf-inference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...ional-vlm-non-stream/0.huggingface_hub.py → ...-stream/0.huggingface_hub.hf-inference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...conversational-vlm-non-stream/1.openai.js → ...l-vlm-non-stream/1.openai.hf-inference.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ const stream = client.chatCompletionStream({ | |
] | ||
} | ||
], | ||
provider: "hf-inference", | ||
max_tokens: 500 | ||
}); | ||
|
||
|
5 changes: 4 additions & 1 deletion
5
...rsational-vlm-stream/0.huggingface_hub.py → ...-stream/0.huggingface_hub.hf-inference.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
packages/tasks-gen/snippets-fixtures/text-to-image/0.huggingface.js.hf-inference.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { HfInference } from "@huggingface/inference"; | ||
|
||
const client = new HfInference("api_token"); | ||
|
||
const image = await client.textToImage({ | ||
model: "black-forest-labs/FLUX.1-schnell", | ||
inputs: "Astronaut riding a horse", | ||
parameters: { num_inference_steps: 5 }, | ||
provider: "hf-inference", | ||
}); | ||
/// Use the generated image (it's a Blob) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.