@ai-sdk/mistral
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -173,3 +173,2 @@ "use strict"; | ||
}) { | ||
var _a; | ||
const type = mode.type; | ||
@@ -204,15 +203,4 @@ const warnings = []; | ||
case "regular": { | ||
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0; | ||
return { | ||
args: { | ||
...baseArgs, | ||
tools: tools == null ? void 0 : tools.map((tool) => ({ | ||
type: "function", | ||
function: { | ||
name: tool.name, | ||
description: tool.description, | ||
parameters: tool.parameters | ||
} | ||
})) | ||
}, | ||
args: { ...baseArgs, ...prepareToolsAndToolChoice(mode) }, | ||
warnings | ||
@@ -413,2 +401,40 @@ }; | ||
}); | ||
function prepareToolsAndToolChoice(mode) { | ||
var _a; | ||
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0; | ||
if (tools == null) { | ||
return { tools: void 0, tool_choice: void 0 }; | ||
} | ||
const mappedTools = tools.map((tool) => ({ | ||
type: "function", | ||
function: { | ||
name: tool.name, | ||
description: tool.description, | ||
parameters: tool.parameters | ||
} | ||
})); | ||
const toolChoice = mode.toolChoice; | ||
if (toolChoice == null) { | ||
return { tools: mappedTools, tool_choice: void 0 }; | ||
} | ||
const type = toolChoice.type; | ||
switch (type) { | ||
case "auto": | ||
case "none": | ||
return { tools: mappedTools, tool_choice: type }; | ||
case "required": | ||
return { tools: mappedTools, tool_choice: "any" }; | ||
case "tool": | ||
return { | ||
tools: mappedTools.filter( | ||
(tool) => tool.function.name === toolChoice.toolName | ||
), | ||
tool_choice: "any" | ||
}; | ||
default: { | ||
const _exhaustiveCheck = type; | ||
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`); | ||
} | ||
} | ||
} | ||
@@ -415,0 +441,0 @@ // src/mistral-facade.ts |
@@ -173,3 +173,2 @@ "use strict"; | ||
}) { | ||
var _a; | ||
const type = mode.type; | ||
@@ -204,15 +203,4 @@ const warnings = []; | ||
case "regular": { | ||
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0; | ||
return { | ||
args: { | ||
...baseArgs, | ||
tools: tools == null ? void 0 : tools.map((tool) => ({ | ||
type: "function", | ||
function: { | ||
name: tool.name, | ||
description: tool.description, | ||
parameters: tool.parameters | ||
} | ||
})) | ||
}, | ||
args: { ...baseArgs, ...prepareToolsAndToolChoice(mode) }, | ||
warnings | ||
@@ -413,2 +401,40 @@ }; | ||
}); | ||
function prepareToolsAndToolChoice(mode) { | ||
var _a; | ||
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0; | ||
if (tools == null) { | ||
return { tools: void 0, tool_choice: void 0 }; | ||
} | ||
const mappedTools = tools.map((tool) => ({ | ||
type: "function", | ||
function: { | ||
name: tool.name, | ||
description: tool.description, | ||
parameters: tool.parameters | ||
} | ||
})); | ||
const toolChoice = mode.toolChoice; | ||
if (toolChoice == null) { | ||
return { tools: mappedTools, tool_choice: void 0 }; | ||
} | ||
const type = toolChoice.type; | ||
switch (type) { | ||
case "auto": | ||
case "none": | ||
return { tools: mappedTools, tool_choice: type }; | ||
case "required": | ||
return { tools: mappedTools, tool_choice: "any" }; | ||
case "tool": | ||
return { | ||
tools: mappedTools.filter( | ||
(tool) => tool.function.name === toolChoice.toolName | ||
), | ||
tool_choice: "any" | ||
}; | ||
default: { | ||
const _exhaustiveCheck = type; | ||
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`); | ||
} | ||
} | ||
} | ||
@@ -415,0 +441,0 @@ // src/mistral-facade.ts |
{ | ||
"name": "@ai-sdk/mistral", | ||
"version": "0.0.13", | ||
"version": "0.0.14", | ||
"license": "Apache-2.0", | ||
@@ -21,4 +21,4 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@ai-sdk/provider": "0.0.7", | ||
"@ai-sdk/provider-utils": "0.0.10" | ||
"@ai-sdk/provider": "0.0.8", | ||
"@ai-sdk/provider-utils": "0.0.11" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": { |
# Vercel AI SDK - Mistral Provider | ||
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. | ||
The **[Mistral provider](https://sdk.vercel.ai/providers/ai-sdk-providers/mistral)** for the [Vercel AI SDK](https://sdk.vercel.ai/docs) contains language model support for the Mistral chat API. | ||
@@ -22,53 +21,16 @@ ## Setup | ||
If you need a customized setup, you can import `createMistral` from `@ai-sdk/mistral` and create a provider instance with your settings: | ||
## Example | ||
```ts | ||
import { createMistral } from '@ai-sdk/mistral'; | ||
import { mistral } from '@ai-sdk/mistral'; | ||
import { generateText } from 'ai'; | ||
const mistral = createMistral({ | ||
// custom settings | ||
const { text } = await generateText({ | ||
model: mistral('mistral-large-latest'), | ||
prompt: 'Write a vegetarian lasagna recipe for 4 people.', | ||
}); | ||
``` | ||
You can use the following optional settings to customize the Mistral provider instance: | ||
## Documentation | ||
- **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 | ||
You can create models that call the [Mistral chat API](https://docs.mistral.ai/api/#operation/createChatCompletion) using provider instance. | ||
The first argument is the model id, e.g. `mistral-large-latest`. | ||
Some Mistral chat models support tool calls. | ||
```ts | ||
const model = mistral('mistral-large-latest'); | ||
``` | ||
Mistral chat models also support additional model settings that are not part of the [standard call settings](/docs/ai-core/settings). | ||
You can pass them as an options argument: | ||
```ts | ||
const model = mistral('mistral-large-latest', { | ||
safePrompt: true, // optional safety prompt injection | ||
}); | ||
``` | ||
The following optional settings are available for Mistral models: | ||
- **safePrompt** _boolean_ | ||
Whether to inject a safety prompt before all conversations. | ||
Defaults to `false`. | ||
Please check out the **[Mistral provider](https://sdk.vercel.ai/providers/ai-sdk-providers/mistral)** for more information. |
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
130349
1817
36
+ Added@ai-sdk/provider@0.0.8(transitive)
+ Added@ai-sdk/provider-utils@0.0.11(transitive)
- Removed@ai-sdk/provider@0.0.7(transitive)
- Removed@ai-sdk/provider-utils@0.0.10(transitive)
Updated@ai-sdk/provider@0.0.8