@ai-sdk/mistral
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -303,3 +303,3 @@ "use strict"; | ||
}; | ||
const generateId2 = this.config.generateId; | ||
const generateId3 = this.config.generateId; | ||
return { | ||
@@ -336,3 +336,3 @@ stream: response.pipeThrough( | ||
for (const toolCall of delta.tool_calls) { | ||
const toolCallId = generateId2(); | ||
const toolCallId = generateId3(); | ||
controller.enqueue({ | ||
@@ -449,4 +449,20 @@ type: "tool-call-delta", | ||
// src/mistral-provider.ts | ||
var import_provider_utils4 = require("@ai-sdk/provider-utils"); | ||
function createMistral(options = {}) { | ||
const mistral2 = new Mistral(options); | ||
const createModel = (modelId, settings = {}) => { | ||
var _a, _b, _c; | ||
return new MistralChatLanguageModel(modelId, settings, { | ||
provider: "mistral.chat", | ||
baseURL: (_b = (0, import_provider_utils4.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : options.baseUrl)) != null ? _b : "https://api.mistral.ai/v1", | ||
headers: () => ({ | ||
Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({ | ||
apiKey: options.apiKey, | ||
environmentVariableName: "MISTRAL_API_KEY", | ||
description: "Mistral" | ||
})}`, | ||
...options.headers | ||
}), | ||
generateId: (_c = options.generateId) != null ? _c : import_provider_utils4.generateId | ||
}); | ||
}; | ||
const provider = function(modelId, settings) { | ||
@@ -458,5 +474,5 @@ if (new.target) { | ||
} | ||
return mistral2.chat(modelId, settings); | ||
return createModel(modelId, settings); | ||
}; | ||
provider.chat = mistral2.chat.bind(mistral2); | ||
provider.chat = createModel; | ||
return provider; | ||
@@ -463,0 +479,0 @@ } |
@@ -6,5 +6,5 @@ import { LanguageModelV1 } from '@ai-sdk/provider'; | ||
/** | ||
* Whether to inject a safety prompt before all conversations. | ||
* | ||
* Default: false | ||
Whether to inject a safety prompt before all conversations. | ||
Defaults to `false`. | ||
*/ | ||
@@ -39,3 +39,4 @@ safePrompt?: boolean; | ||
/** | ||
Base URL for the Mistral API calls. | ||
Use a different URL prefix for API calls, e.g. to use proxy servers. | ||
The default prefix is `https://api.mistral.ai/v1`. | ||
*/ | ||
@@ -48,3 +49,4 @@ baseURL?: string; | ||
/** | ||
API key for authenticating requests. | ||
API key that is being send using the `Authorization` header. | ||
It defaults to the `MISTRAL_API_KEY` environment variable. | ||
*/ | ||
@@ -51,0 +53,0 @@ apiKey?: string; |
@@ -303,3 +303,3 @@ "use strict"; | ||
}; | ||
const generateId2 = this.config.generateId; | ||
const generateId3 = this.config.generateId; | ||
return { | ||
@@ -336,3 +336,3 @@ stream: response.pipeThrough( | ||
for (const toolCall of delta.tool_calls) { | ||
const toolCallId = generateId2(); | ||
const toolCallId = generateId3(); | ||
controller.enqueue({ | ||
@@ -449,4 +449,20 @@ type: "tool-call-delta", | ||
// src/mistral-provider.ts | ||
var import_provider_utils4 = require("@ai-sdk/provider-utils"); | ||
function createMistral(options = {}) { | ||
const mistral2 = new Mistral(options); | ||
const createModel = (modelId, settings = {}) => { | ||
var _a, _b, _c; | ||
return new MistralChatLanguageModel(modelId, settings, { | ||
provider: "mistral.chat", | ||
baseURL: (_b = (0, import_provider_utils4.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : options.baseUrl)) != null ? _b : "https://api.mistral.ai/v1", | ||
headers: () => ({ | ||
Authorization: `Bearer ${(0, import_provider_utils4.loadApiKey)({ | ||
apiKey: options.apiKey, | ||
environmentVariableName: "MISTRAL_API_KEY", | ||
description: "Mistral" | ||
})}`, | ||
...options.headers | ||
}), | ||
generateId: (_c = options.generateId) != null ? _c : import_provider_utils4.generateId | ||
}); | ||
}; | ||
const provider = function(modelId, settings) { | ||
@@ -458,5 +474,5 @@ if (new.target) { | ||
} | ||
return mistral2.chat(modelId, settings); | ||
return createModel(modelId, settings); | ||
}; | ||
provider.chat = mistral2.chat.bind(mistral2); | ||
provider.chat = createModel; | ||
return provider; | ||
@@ -463,0 +479,0 @@ } |
{ | ||
"name": "@ai-sdk/mistral", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"license": "Apache-2.0", | ||
@@ -22,3 +22,3 @@ "sideEffects": false, | ||
"@ai-sdk/provider": "0.0.2", | ||
"@ai-sdk/provider-utils": "0.0.3" | ||
"@ai-sdk/provider-utils": "0.0.4" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": { |
# Vercel AI SDK - Mistral Provider | ||
The Mistral provider contains language model support for the Mistral chat API. | ||
The [Mistral](https://mistral.ai/) provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs) contains language model support for the Mistral chat API. | ||
It creates language model objects that can be used with the `generateText`, `streamText`, `generateObject`, and `streamObject` AI functions. | ||
@@ -16,27 +16,34 @@ | ||
You can import `createMistral` from `@ai-sdk/mistral` and create a provider instance with various settings: | ||
You can import the default provider instance `mistral` from `@ai-sdk/mistral`: | ||
```ts | ||
import { mistral } from '@ai-sdk/mistral'; | ||
``` | ||
If you need a customized setup, you can import `createMistral` from `@ai-sdk/mistral` and create a provider instance with your settings: | ||
```ts | ||
import { createMistral } from '@ai-sdk/mistral'; | ||
const mistral = createMistral({ | ||
// optional base URL for proxies etc.: | ||
baseURL: '', | ||
// optional API key, default to env property MISTRAL_API_KEY: | ||
apiKey: '', | ||
// optional custom headers: | ||
headers: { | ||
'custom-header': 'value', | ||
}, | ||
// custom settings | ||
}); | ||
``` | ||
The AI SDK also provides a shorthand `mistral` import with a Mistral provider instance that uses defaults: | ||
You can use the following optional settings to customize the Mistral provider instance: | ||
```ts | ||
import { mistral } from '@ai-sdk/mistral'; | ||
``` | ||
- **baseURL** _string_ | ||
Use a different URL prefix for API calls, e.g. to use proxy servers. | ||
The default prefix is `https://api.mistral.ai/v1`. | ||
- **apiKey** _string_ | ||
API key that is being send using the `Authorization` header. | ||
It defaults to the `MISTRAL_API_KEY` environment variable. | ||
- **headers** _Record<string,string>_ | ||
Custom headers to include in the requests. | ||
## Models | ||
@@ -60,1 +67,9 @@ | ||
``` | ||
The following optional settings are available for Mistral models: | ||
- **safePrompt** _boolean_ | ||
Whether to inject a safety prompt before all conversations. | ||
Defaults to `false`. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
107344
1487
74
+ Added@ai-sdk/provider-utils@0.0.4(transitive)
- Removed@ai-sdk/provider-utils@0.0.3(transitive)
Updated@ai-sdk/provider-utils@0.0.4