Commit 2a5443f
[Inference snippets] Templated snippets for inference snippet generation (#1255)
### What does this PR do?
- add `@huggingface/jinja` as a dependency for `@huggingface/inference`
- heavily refactor
[`./packages/inference/src/snippets/python.ts`](https://github.com/huggingface/huggingface.js/blob/ddd62b60d0a858dc808b6dd7b3589977681f5a8b/packages/inference/src/snippets/python.ts)
to use templates instead of inline strings
- add some snippet templates under
`packages/inference/src/snippets/templates/{language}/{client}/{templateName}.jinja`
- `language` is Python
- `client` is e.g. huggingface_hub, requests, etc.
- `templateName` is related to task name e.g. textToImage,
conversationalStream, etc.
=> overall goal is to make it rather easy to update the snippets for a
given task + client without entering the JS code
=> if conclusive, we can extend to cURL / JS snippets in a follow-up PR
This PR also includes a lot of small fixes (usually whitespace<>tabs
inconsistencies) + added some tests. I did not change anything major in
the generated snippets.
### What to review?
IMO, no need to review all templates. Better to check the generated
snippets + the main JS file directly
(https://github.com/huggingface/huggingface.js/blob/ddd62b60d0a858dc808b6dd7b3589977681f5a8b/packages/inference/src/snippets/python.ts).
Sorry for the huge PR but I do believe it is a necessary move moving
forward 🤗
---------
Co-authored-by: Simon Brandeis <[email protected]>
Co-authored-by: coyotte508 <[email protected]>1 parent 5cab02a commit 2a5443f
File tree
69 files changed
+731
-621
lines changed- .github/workflows
- .vscode
- packages
- inference
- src
- lib
- snippets
- templates/python
- fal_client
- huggingface_hub
- openai
- requests
- tasks-gen
- scripts
- snippets-fixtures
- automatic-speech-recognition
- basic-snippet--token-classification
- conversational-llm-non-stream
- conversational-llm-stream
- conversational-vlm-non-stream
- conversational-vlm-stream
- document-question-answering
- image-to-image
- tabular
- text-classification
- text-to-audio-transformers
- text-to-image
- text-to-video
- zero-shot-classification
- zero-shot-image-classification
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
69 files changed
+731
-621
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
55 | | - | |
| 62 | + | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
| 6 | + | |
7 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
| |||
0 commit comments