inflection-ai-sdk-provider
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -26,1 +26,9 @@ # inflection-ai-sdk-provider | ||
- Updated keywords in package.json | ||
## 1.0.4 | ||
### Patch Changes | ||
- Added tool calling support for inflection_3_with_tools model | ||
- Added streaming tool call support | ||
- Updated documentation with tool calling examples and capabilities |
import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider'; | ||
import { FetchFunction } from '@ai-sdk/provider-utils'; | ||
type InflectionChatModelId = 'inflection_3_with_tools' | 'inflection_3_pi' | 'inflection_3_productivity' | (string & {}); | ||
type InflectionChatModelId = "inflection_3_with_tools" | "inflection_3_pi" | "inflection_3_productivity" | (string & {}); | ||
interface InflectionFunctionParameters { | ||
type: "object"; | ||
properties: Record<string, unknown>; | ||
required?: string[]; | ||
} | ||
interface InflectionFunction { | ||
name: string; | ||
description?: string; | ||
parameters: InflectionFunctionParameters; | ||
} | ||
interface InflectionTool { | ||
type: "function"; | ||
function: InflectionFunction; | ||
} | ||
interface InflectionChatSettings { | ||
@@ -43,2 +57,6 @@ /** | ||
top_p?: number; | ||
/** | ||
* List of tools the model can use. Only supported when using the inflection_3_with_tools model. | ||
*/ | ||
tools?: InflectionTool[]; | ||
} | ||
@@ -45,0 +63,0 @@ |
@@ -39,6 +39,8 @@ "use strict"; | ||
var import_provider = require("@ai-sdk/provider"); | ||
function convertToInflectionChatMessages(prompt) { | ||
function convertToInflectionChatMessages(prompt, modelId = "inflection_3_pi") { | ||
var _a; | ||
const context = []; | ||
for (const { role, content } of prompt) { | ||
let text = ""; | ||
const toolCalls = []; | ||
if (typeof content === "string") { | ||
@@ -53,2 +55,27 @@ text = content; | ||
} | ||
case "tool-call": { | ||
if (modelId !== "inflection_3_with_tools") { | ||
throw new import_provider.UnsupportedFunctionalityError({ | ||
functionality: "Tool calls are only supported with the inflection_3_with_tools model" | ||
}); | ||
} | ||
toolCalls.push({ | ||
id: part.toolCallId, | ||
type: "function", | ||
function: { | ||
name: part.toolName, | ||
arguments: JSON.stringify(part.args) | ||
} | ||
}); | ||
break; | ||
} | ||
case "tool-result": { | ||
if (modelId !== "inflection_3_with_tools") { | ||
throw new import_provider.UnsupportedFunctionalityError({ | ||
functionality: "Tool results are only supported with the inflection_3_with_tools model" | ||
}); | ||
} | ||
text = JSON.stringify(part.result); | ||
break; | ||
} | ||
case "image": { | ||
@@ -64,12 +91,2 @@ throw new import_provider.UnsupportedFunctionalityError({ | ||
} | ||
case "tool-call": { | ||
throw new import_provider.UnsupportedFunctionalityError({ | ||
functionality: "Tool calls are not supported by Inflection AI at this time" | ||
}); | ||
} | ||
case "tool-result": { | ||
throw new import_provider.UnsupportedFunctionalityError({ | ||
functionality: "Tool results are not supported by Inflection AI at this time" | ||
}); | ||
} | ||
default: { | ||
@@ -84,3 +101,3 @@ const _exhaustiveCheck = part; | ||
} | ||
if (!text) { | ||
if (!text && !toolCalls.length) { | ||
continue; | ||
@@ -94,3 +111,7 @@ } | ||
case "assistant": { | ||
context.push({ type: "AI", text }); | ||
context.push({ | ||
type: "AI", | ||
text, | ||
...toolCalls.length ? { tool_calls: toolCalls } : {} | ||
}); | ||
break; | ||
@@ -103,2 +124,10 @@ } | ||
case "tool": { | ||
if (text) { | ||
const toolCallId = typeof content === "string" ? void 0 : (_a = content.find((part) => part.type === "tool-result")) == null ? void 0 : _a.toolCallId; | ||
context.push({ | ||
type: "Tool", | ||
text, | ||
...toolCallId ? { tool_call_id: toolCallId } : {} | ||
}); | ||
} | ||
break; | ||
@@ -165,10 +194,26 @@ } | ||
}) { | ||
var _a; | ||
var _a, _b; | ||
const type = mode.type; | ||
const warnings = []; | ||
if (type === "object-tool" || type === "regular" && ((_a = mode.tools) == null ? void 0 : _a.length)) { | ||
if (type === "regular" && ((_a = mode.tools) == null ? void 0 : _a.length) && this.modelId !== "inflection_3_with_tools") { | ||
throw new import_provider2.UnsupportedFunctionalityError({ | ||
functionality: "Tool calls are not supported by Inflection AI" | ||
functionality: "Tool calls are only supported with the inflection_3_with_tools model" | ||
}); | ||
} | ||
const tools = type === "regular" && ((_b = mode.tools) == null ? void 0 : _b.length) ? mode.tools.filter( | ||
(tool) => tool.type === "function" | ||
).map( | ||
(tool) => ({ | ||
type: "function", | ||
function: { | ||
name: tool.name, | ||
description: tool.description, | ||
parameters: { | ||
type: "object", | ||
properties: tool.parameters.properties, | ||
required: tool.parameters.required | ||
} | ||
} | ||
}) | ||
) : void 0; | ||
const baseArgs = { | ||
@@ -186,3 +231,5 @@ // config instead of model: | ||
// context (messages): | ||
context: convertToInflectionChatMessages(prompt) | ||
context: convertToInflectionChatMessages(prompt, this.modelId), | ||
// tools if present: | ||
tools | ||
}; | ||
@@ -192,2 +239,3 @@ return { args: baseArgs, warnings }; | ||
async doGenerate(options) { | ||
var _a, _b; | ||
const { args, warnings } = this.getArgs(options); | ||
@@ -209,5 +257,13 @@ const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({ | ||
const completionTokens = Math.ceil(response.text.length / 4); | ||
const toolCalls = (_a = response.tool_calls) == null ? void 0 : _a.map( | ||
(call) => ({ | ||
toolCallType: "function", | ||
toolCallId: call.id, | ||
toolName: call.function.name, | ||
args: JSON.parse(call.function.arguments) | ||
}) | ||
); | ||
return { | ||
text: response.text, | ||
finishReason: "stop", | ||
finishReason: ((_b = response.tool_calls) == null ? void 0 : _b.length) ? "tool-calls" : "stop", | ||
usage: { | ||
@@ -217,2 +273,3 @@ promptTokens, | ||
}, | ||
toolCalls, | ||
rawCall: { rawPrompt, rawSettings }, | ||
@@ -248,2 +305,3 @@ rawResponse: { headers: responseHeaders }, | ||
transform(chunk, controller) { | ||
var _a; | ||
if (!chunk.success) { | ||
@@ -265,2 +323,17 @@ controller.enqueue({ type: "error", error: chunk.error }); | ||
}); | ||
if ((_a = value.tool_calls) == null ? void 0 : _a.length) { | ||
for (const call of value.tool_calls) { | ||
const toolCall = { | ||
toolCallType: "function", | ||
toolCallId: call.id, | ||
toolName: call.function.name, | ||
args: JSON.parse(call.function.arguments) | ||
}; | ||
controller.enqueue({ | ||
type: "tool-call", | ||
...toolCall | ||
}); | ||
} | ||
finishReason = "tool-calls"; | ||
} | ||
}, | ||
@@ -286,5 +359,14 @@ flush(controller) { | ||
}; | ||
var inflectionToolCallSchema = import_zod2.z.object({ | ||
id: import_zod2.z.string(), | ||
type: import_zod2.z.literal("function"), | ||
function: import_zod2.z.object({ | ||
name: import_zod2.z.string(), | ||
arguments: import_zod2.z.string() | ||
}) | ||
}); | ||
var inflectionChatResponseSchema = import_zod2.z.object({ | ||
created: import_zod2.z.number(), | ||
text: import_zod2.z.string() | ||
text: import_zod2.z.string(), | ||
tool_calls: import_zod2.z.array(inflectionToolCallSchema).optional() | ||
}); | ||
@@ -294,3 +376,4 @@ var inflectionChatChunkSchema = import_zod2.z.object({ | ||
idx: import_zod2.z.number(), | ||
text: import_zod2.z.string() | ||
text: import_zod2.z.string(), | ||
tool_calls: import_zod2.z.array(inflectionToolCallSchema).optional() | ||
}); | ||
@@ -297,0 +380,0 @@ |
{ | ||
"name": "inflection-ai-sdk-provider", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"license": "Apache-2.0", | ||
@@ -44,3 +44,3 @@ "sideEffects": false, | ||
}, | ||
"homepage": "https://github.com/Umbrage-Studios/inflection-ai-sdk-provider", | ||
"homepage": "https://sdk.vercel.ai/providers/community-providers/inflection-ai", | ||
"repository": { | ||
@@ -47,0 +47,0 @@ "type": "git", |
@@ -27,2 +27,3 @@ # Unofficial Community Provider for AI SDK - Inflection AI | ||
// Basic text generation | ||
const { text } = await generateText({ | ||
@@ -32,2 +33,25 @@ model: inflection("inflection_3_with_tools"), | ||
}); | ||
// Using tool calls | ||
const { text: weatherText, toolCalls } = await generateText({ | ||
model: inflection("inflection_3_with_tools"), | ||
prompt: "what's the weather in San Francisco?", | ||
tools: [ | ||
{ | ||
type: "function", | ||
name: "get_weather", | ||
description: "Get the current weather in a location", | ||
parameters: { | ||
type: "object", | ||
properties: { | ||
location: { | ||
type: "string", | ||
description: "The city and state, e.g. San Francisco, CA", | ||
}, | ||
}, | ||
required: ["location"], | ||
}, | ||
}, | ||
], | ||
}); | ||
``` | ||
@@ -41,3 +65,3 @@ | ||
- `inflection_3_productivity`- "the model optimized for following instructions. It is better for tasks requiring JSON output or precise adherence to provided guidelines." | ||
- `inflection_3_with_tools` - This model seems to be in preview and it lacks an official description as of the writing of this README in 1.0.0. | ||
- `inflection_3_with_tools` - Model that supports function calling capabilities, allowing it to interact with external tools and APIs through a structured interface. | ||
@@ -48,6 +72,8 @@ | Model | Text Generation | Streaming | Image Input | Object Generation | Tool Usage | Tool Streaming | | ||
| `inflection_3_productivity` | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | | ||
| `inflection_3_with_tools` | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | | ||
| `inflection_3_with_tools` | ✓ | ✓ | ✗ | ✗ | ✓ | ✓ | | ||
There is limited API support for features other than text generation and streaming text at this time. Should that change, the table above will be updated and support will be added to this unofficial provider. | ||
## Tool Calling Support | ||
The `inflection_3_with_tools` model supports function calling through the standard AI SDK tools interface. You can provide a list of tools when making requests, and the model can choose to call these tools as part of its response. Both streaming and non-streaming tool calls are supported. | ||
## Documentation | ||
@@ -54,0 +80,0 @@ |
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
101128
890
80