Skip to content

Commit fd6ce52

Browse files
authored
♻️ Export individual functions, precise typing (#148)
1 parent ce9bfd0 commit fd6ce52

35 files changed

+1368
-1190
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
"@typescript-eslint/no-unused-vars": "error",
1717
"@typescript-eslint/no-non-null-assertion": "error",
1818
"@typescript-eslint/no-explicit-any": "error",
19+
"@typescript-eslint/no-empty-interfaces": "off",
1920
// For doc purposes, prefer interfaces
2021
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
2122
},

packages/hub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"license": "MIT",
5050
"devDependencies": {
5151
"@types/node": "^18.13.0",
52-
"typescript": "^4.9.5"
52+
"typescript": "^5.0.4"
5353
},
5454
"dependencies": {
5555
"hash-wasm": "^4.9.0",

packages/hub/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/inference/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the
212212
- [x] Zero-shot classification
213213
- [x] Conversational
214214
- [x] Feature extraction
215+
- [x] Sentence Similarity
215216

216217
### Audio
217218

@@ -226,6 +227,23 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the
226227
- [x] Text to image
227228
- [x] Image to text
228229

230+
## Tree-shaking
231+
232+
You can import the functions you need directly from the module, rather than using the `HfInference` class:
233+
234+
```ts
235+
import {textGeneration} from "@huggingface/inference";
236+
237+
await textGeneration({
238+
accessToken: "hf_...",
239+
model: "model_or_endpoint",
240+
inputs: ...,
241+
parameters: ...
242+
})
243+
```
244+
245+
This will enable tree-shaking by your bundler.
246+
229247
## Running tests
230248

231249
```console

packages/inference/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@
2828
"src"
2929
],
3030
"source": "src/index.ts",
31-
"types": "dist/index.d.ts",
31+
"types": "src/index.ts",
3232
"main": "./dist/index.js",
3333
"module": "./dist/index.mjs",
3434
"exports": {
35-
".": {
36-
"require": "./dist/index.js",
37-
"import": "./dist/index.mjs",
38-
"types": "./dist/index.d.ts"
39-
}
35+
"types": "./src/index.ts",
36+
"require": "./dist/index.js",
37+
"import": "./dist/index.mjs"
4038
},
4139
"scripts": {
42-
"build": "tsup src/index.ts --format cjs,esm --clean --dts",
40+
"build": "tsup src/index.ts --format cjs,esm --clean",
4341
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
4442
"lint:check": "eslint --ext .cjs,.ts .",
4543
"format": "prettier --write .",
@@ -51,7 +49,7 @@
5149
},
5250
"devDependencies": {
5351
"@types/node": "18.13.0",
54-
"typescript": "4.9.5",
52+
"typescript": "^5.0.4",
5553
"vite": "^4.1.4",
5654
"vitest": "^0.29.8"
5755
},

packages/inference/pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)