-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (provider/deepinfra): Add DeepInfra provider. (#4158)
- Loading branch information
Showing
25 changed files
with
1,162 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<string,string>_ | ||
|
||
Custom headers to include in the requests. | ||
|
||
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_ | ||
|
||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.