Skip to content

Commit

Permalink
feat (provider/deepinfra): Add DeepInfra provider. (#4158)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaper authored Dec 20, 2024
1 parent 7370e41 commit baae8f4
Show file tree
Hide file tree
Showing 25 changed files with 1,162 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/rotten-tomatoes-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ai-sdk/openai-compatible': patch
'@ai-sdk/deepinfra': patch
---

feat (provider/deepinfra): Add DeepInfra provider.
5 changes: 3 additions & 2 deletions content/docs/02-foundations/02-providers-and-models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ The AI SDK comes with several providers that you can use to interact with differ
- [xAI Grok Provider](/providers/ai-sdk-providers/xai) (`@ai-sdk/xai`)
- [Together.ai Provider](/providers/ai-sdk-providers/togetherai) (`@ai-sdk/togetherai`)
- [Cohere Provider](/providers/ai-sdk-providers/cohere) (`@ai-sdk/cohere`)
- [Fireworks](/providers/ai-sdk-providers/fireworks)
- [Groq](/providers/ai-sdk-providers/groq) (`@ai-sdk/groq`)
- [Fireworks Provider](/providers/ai-sdk-providers/fireworks) (`@ai-sdk/fireworks`)
- [DeepInfra Provider](/providers/ai-sdk-providers/deepinfra) (`@ai-sdk/deepinfra`)
- [Groq Provider](/providers/ai-sdk-providers/groq) (`@ai-sdk/groq`)

You can also use the OpenAI provider with OpenAI-compatible APIs:

Expand Down
111 changes: 111 additions & 0 deletions content/providers/01-ai-sdk-providers/27-deepinfra.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: DeepInfra
description: Learn how to use DeepInfra's models with the AI SDK.
---

# DeepInfra Provider

The [DeepInfra](https://deepinfra.com) provider contains support for state-of-the-art models through the DeepInfra API, including Llama 3, Mixtral, Qwen, and many other popular open-source models.

## Setup

The DeepInfra provider is available via the `@ai-sdk/deepinfra` module. You can install it with:

<Tabs items={['pnpm', 'npm', 'yarn']}>
<Tab>
<Snippet text="pnpm add @ai-sdk/deepinfra" dark />
</Tab>
<Tab>
<Snippet text="npm install @ai-sdk/deepinfra" dark />
</Tab>
<Tab>
<Snippet text="yarn add @ai-sdk/deepinfra" dark />
</Tab>
</Tabs>

## Provider Instance

You can import the default provider instance `deepinfra` from `@ai-sdk/deepinfra`:

```ts
import { deepinfra } from '@ai-sdk/deepinfra';
```

If you need a customized setup, you can import `createDeepInfra` from `@ai-sdk/deepinfra` and create a provider instance with your settings:

```ts
import { createDeepInfra } from '@ai-sdk/deepinfra';

const deepinfra = createDeepInfra({
apiKey: process.env.DEEPINFRA_API_KEY ?? '',
});
```

You can use the following optional settings to customize the DeepInfra provider instance:

- **baseURL** _string_

Use a different URL prefix for API calls, e.g. to use proxy servers.
The default prefix is `https://api.deepinfra.com/v1/openai`.

- **apiKey** _string_

API key that is being sent using the `Authorization` header. It defaults to
the `DEEPINFRA_API_KEY` environment variable.

- **headers** _Record&lt;string,string&gt;_

Custom headers to include in the requests.

- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise&lt;Response&gt;_

Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
Defaults to the global `fetch` function.
You can use it as a middleware to intercept requests,
or to provide a custom fetch implementation for e.g. testing.

## Language Models

You can create language models using a provider instance. The first argument is the model ID, for example:

```ts
import { deepinfra } from '@ai-sdk/deepinfra';
import { generateText } from 'ai';

const { text } = await generateText({
model: deepinfra('meta-llama/Meta-Llama-3.1-70B-Instruct'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
```

DeepInfra language models can also be used in the `streamText` and `streamUI` functions (see [AI SDK Core](/docs/ai-sdk-core) and [AI SDK RSC](/docs/ai-sdk-rsc)).

## Model Capabilities

| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
| ---------------------------------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
| `meta-llama/Llama-3.3-70B-Instruct-Turbo` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `meta-llama/Llama-3.3-70B-Instruct` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| 'meta-llama/Meta-Llama-3.1-405B-Instruct' | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `meta-llama/Meta-Llama-3.1-70B-Instruct` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
| `meta-llama/Meta-Llama-3.1-8B-Instruct` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `meta-llama/Llama-3.2-11B-Vision-Instruct` | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
| `meta-llama/Llama-3.2-90B-Vision-Instruct` | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
| `mistralai/Mixtral-8x7B-Instruct-v0.1` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
| `nvidia/Llama-3.1-Nemotron-70B-Instruct` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Cross size={18} /> |
| `Qwen/Qwen2-7B-Instruct` | <Cross size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
| `Qwen/Qwen2.5-72B-Instruct` | <Cross size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
| `Qwen/Qwen2.5-Coder-32B-Instruct` | <Cross size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
| `Qwen/QwQ-32B-Preview` | <Cross size={18} /> | <Check size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
| `google/codegemma-7b-it` | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
| `google/gemma-2-9b-it` | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> |
| `microsoft/WizardLM-2-8x22B` | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> | <Cross size={18} /> |

<Note>
The table above lists popular models. Please see the [DeepInfra
docs](https://deepinfra.com) for a full list of available models. The table
above lists popular models. You can also pass any available provider model ID
as a string if needed.
</Note>
1 change: 1 addition & 0 deletions examples/ai-core/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AWS_REGION=""
AZURE_API_KEY=""
AZURE_RESOURCE_NAME=""
COHERE_API_KEY=""
DEEPINFRA_API_KEY=""
FIREWORKS_API_KEY=""
GOOGLE_APPLICATION_CREDENTIALS=""
GOOGLE_CLIENT_EMAIL=""
Expand Down
1 change: 1 addition & 0 deletions examples/ai-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@ai-sdk/anthropic": "1.0.5",
"@ai-sdk/azure": "1.0.12",
"@ai-sdk/cohere": "1.0.5",
"@ai-sdk/deepinfra": "0.0.0",
"@ai-sdk/fireworks": "0.0.3",
"@ai-sdk/google": "1.0.11",
"@ai-sdk/google-vertex": "2.0.11",
Expand Down
Loading

0 comments on commit baae8f4

Please sign in to comment.