docs: add providers
This commit is contained in:
3 files changed
+96
No files matched your search
@@ -0,0 +1,88 @@
|
||||
---
|
||||
title: Providers
|
||||
description: Collection of predefined providers.
|
||||
---
|
||||
|
||||
<Callout type="info">
|
||||
This package is not recommended for xsAI-based libraries,
|
||||
which can increase the size of the installation.
|
||||
</Callout>
|
||||
|
||||
import { PkgSizeBadge } from '@/components/pkg-size-badge'
|
||||
|
||||
## Cloud
|
||||
|
||||
<PkgSizeBadge pkg="@xsai-ext/providers-cloud" />
|
||||
|
||||
```package-install
|
||||
npm i @xsai-ext/providers-cloud
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
#### Keys
|
||||
|
||||
```ts twoslash
|
||||
import * as providers from '@xsai-ext/providers-cloud'
|
||||
|
||||
type Keys = keyof typeof providers
|
||||
```
|
||||
|
||||
#### OpenAI
|
||||
|
||||
```ts twoslash
|
||||
import { createOpenAI } from '@xsai-ext/providers-cloud' // [!code ++]
|
||||
import { generateText } from '@xsai/generate-text'
|
||||
import { env } from 'node:process'
|
||||
|
||||
const openai = createOpenAI(env.OPENAI_API_KEY!) // [!code ++]
|
||||
|
||||
const { text } = await generateText({
|
||||
...openai.chat('gpt-4o'), // [!code ++]
|
||||
apiKey: env.OPENAI_API_KEY!, // [!code --]
|
||||
baseURL: 'https://api.openai.com/v1/', // [!code --]
|
||||
messages: [{
|
||||
content: 'Why is the sky blue?',
|
||||
role: 'user'
|
||||
}],
|
||||
model: 'gpt-4o', // [!code --]
|
||||
})
|
||||
```
|
||||
|
||||
## Local
|
||||
|
||||
<PkgSizeBadge pkg="@xsai-ext/providers-local" />
|
||||
|
||||
```package-install
|
||||
npm i @xsai-ext/providers-local
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
#### Keys
|
||||
|
||||
```ts twoslash
|
||||
import * as providers from '@xsai-ext/providers-local'
|
||||
|
||||
type Keys = keyof typeof providers
|
||||
```
|
||||
|
||||
#### Ollama
|
||||
|
||||
```ts twoslash
|
||||
import { createOllama } from '@xsai-ext/providers-local' // [!code ++]
|
||||
import { generateText } from '@xsai/generate-text'
|
||||
import { env } from 'node:process'
|
||||
|
||||
const ollama = createOllama() // [!code ++]
|
||||
|
||||
const { text } = await generateText({
|
||||
...ollama.chat('llama3.2'), // [!code ++]
|
||||
baseURL: 'http://localhost:11434/v1/', // [!code --]
|
||||
messages: [{
|
||||
content: 'Why is the sky blue?',
|
||||
role: 'user'
|
||||
}],
|
||||
model: 'llama3.2', // [!code --]
|
||||
})
|
||||
```
|
||||
@@ -32,6 +32,8 @@
|
||||
"@types/mdx": "^2.0.13",
|
||||
"@types/react": "^19.0.10",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@xsai-ext/providers-cloud": "workspace:^",
|
||||
"@xsai-ext/providers-local": "workspace:^",
|
||||
"@xsai/embed": "workspace:^",
|
||||
"@xsai/generate-object": "workspace:^",
|
||||
"@xsai/generate-speech": "workspace:^",
|
||||
|
||||
Generated
+6
@@ -132,6 +132,12 @@ importers:
|
||||
'@types/react-dom':
|
||||
specifier: ^19.0.4
|
||||
version: 19.0.4(@types/react@19.0.10)
|
||||
'@xsai-ext/providers-cloud':
|
||||
specifier: workspace:^
|
||||
version: link:../packages-ext/providers-cloud
|
||||
'@xsai-ext/providers-local':
|
||||
specifier: workspace:^
|
||||
version: link:../packages-ext/providers-local
|
||||
'@xsai/embed':
|
||||
specifier: workspace:^
|
||||
version: link:../packages/embed
|
||||
|
||||
Reference in new issue
Block a user