Spaces:
Runtime error
Runtime error
Support bash snippets (#21)
Browse files
src/lib/components/CodeSnippets.svelte
CHANGED
|
@@ -147,45 +147,36 @@ print(output.choices[0].message)`
|
|
| 147 |
}
|
| 148 |
|
| 149 |
function getBashSnippets() {
|
|
|
|
| 150 |
const snippets: Snippet[] = [];
|
| 151 |
-
snippets.push({
|
| 152 |
-
label: 'Install',
|
| 153 |
-
code: `import { HfInference } from '@huggingface/inference'
|
| 154 |
|
| 155 |
-
const hf = new HfInference("your access token")`
|
| 156 |
-
});
|
| 157 |
if (conversation.config.streaming) {
|
| 158 |
snippets.push({
|
| 159 |
label: 'Streaming API',
|
| 160 |
-
code: `
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
})) {
|
| 171 |
-
if (chunk.choices && chunk.choices.length > 0) {
|
| 172 |
-
out += chunk.choices[0].delta.content;
|
| 173 |
-
}
|
| 174 |
-
}`
|
| 175 |
});
|
| 176 |
} else {
|
| 177 |
// non-streaming
|
| 178 |
snippets.push({
|
| 179 |
label: 'Non-Streaming API',
|
| 180 |
-
code: `
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
}
|
| 189 |
});
|
| 190 |
}
|
| 191 |
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
function getBashSnippets() {
|
| 150 |
+
const messagesStr = getMessages();
|
| 151 |
const snippets: Snippet[] = [];
|
|
|
|
|
|
|
|
|
|
| 152 |
|
|
|
|
|
|
|
| 153 |
if (conversation.config.streaming) {
|
| 154 |
snippets.push({
|
| 155 |
label: 'Streaming API',
|
| 156 |
+
code: `curl 'https://api-inference.huggingface.co/models/${conversation.model}/v1/chat/completions' \
|
| 157 |
+
--header "Authorization: Bearer {YOUR_HF_TOKEN}" \
|
| 158 |
+
--header 'Content-Type: application/json' \
|
| 159 |
+
--data '{
|
| 160 |
+
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 161 |
+
"messages": ${messagesStr},
|
| 162 |
+
"temperature": ${conversation.config.temperature},
|
| 163 |
+
"max_tokens": ${conversation.config.maxTokens},
|
| 164 |
+
"stream": true
|
| 165 |
+
}'`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
});
|
| 167 |
} else {
|
| 168 |
// non-streaming
|
| 169 |
snippets.push({
|
| 170 |
label: 'Non-Streaming API',
|
| 171 |
+
code: `curl 'https://api-inference.huggingface.co/models/${conversation.model}/v1/chat/completions' \
|
| 172 |
+
--header "Authorization: Bearer {YOUR_HF_TOKEN}" \
|
| 173 |
+
--header 'Content-Type: application/json' \
|
| 174 |
+
--data '{
|
| 175 |
+
"model": "meta-llama/Meta-Llama-3-8B-Instruct",
|
| 176 |
+
"messages": ${messagesStr},
|
| 177 |
+
"temperature": ${conversation.config.temperature},
|
| 178 |
+
"max_tokens": ${conversation.config.maxTokens}
|
| 179 |
+
}'`
|
| 180 |
});
|
| 181 |
}
|
| 182 |
|