Skip to content

Commit

Permalink
📝 Added translation desc & moved tree shaking to the Initialize section
Browse files Browse the repository at this point in the history
  • Loading branch information
ArsalaBangash authored Oct 31, 2023
1 parent af441b1 commit a714e42
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions packages/inference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ import { HfInference } from '@huggingface/inference'
const hf = new HfInference('your access token')
```

#### Tree-shaking

You can import the functions you need directly from the module instead of using the `HfInference` class.

```ts
import { textGeneration } from "@huggingface/inference";

await textGeneration({
accessToken: "hf_...",
model: "model_or_endpoint",
inputs: ...,
parameters: ...
})
```

This will enable tree-shaking by your bundler.

**Important note:** Using an access token is optional to get started, however you will be rate limited eventually. Join [Hugging Face](https://huggingface.co/join) and then visit [access tokens](https://huggingface.co/settings/tokens) to generate your access token for **free**.

Your access token should be kept private. If you need to protect it in front-end applications, we suggest setting up a proxy server that stores the access token.
Expand Down Expand Up @@ -146,6 +163,8 @@ await hf.tokenClassification({

### Translation

Converts text from one language to another.

```typescript
await hf.translation({
model: 't5-base',
Expand Down Expand Up @@ -447,7 +466,7 @@ await hf.tabularClassification({
})
```

## Custom Call
## Custom Calls

For models with custom parameters / outputs.

Expand Down Expand Up @@ -481,23 +500,6 @@ const gpt2 = hf.endpoint('https://xyz.eu-west-1.aws.endpoints.huggingface.cloud/
const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the universe is'});
```

## Tree-shaking

You can import the functions you need directly from the module, rather than using the `HfInference` class:

```ts
import {textGeneration} from "@huggingface/inference";

await textGeneration({
accessToken: "hf_...",
model: "model_or_endpoint",
inputs: ...,
parameters: ...
})
```

This will enable tree-shaking by your bundler.

## Running tests

```console
Expand Down

0 comments on commit a714e42

Please sign in to comment.