@ai-sdk/google
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -178,3 +178,2 @@ "use strict"; | ||
}) { | ||
var _a; | ||
const type = mode.type; | ||
@@ -211,10 +210,2 @@ const warnings = []; | ||
case "regular": { | ||
const functionDeclarations = (_a = mode.tools) == null ? void 0 : _a.map((tool) => { | ||
var _a2; | ||
return { | ||
name: tool.name, | ||
description: (_a2 = tool.description) != null ? _a2 : "", | ||
parameters: prepareJsonSchema(tool.parameters) | ||
}; | ||
}); | ||
return { | ||
@@ -224,3 +215,3 @@ args: { | ||
contents, | ||
tools: functionDeclarations == null ? void 0 : { functionDeclarations } | ||
...prepareToolsAndToolConfig(mode) | ||
}, | ||
@@ -380,18 +371,2 @@ warnings | ||
}; | ||
function prepareJsonSchema(jsonSchema) { | ||
if (typeof jsonSchema !== "object") { | ||
return jsonSchema; | ||
} | ||
if (Array.isArray(jsonSchema)) { | ||
return jsonSchema.map(prepareJsonSchema); | ||
} | ||
const result = {}; | ||
for (const [key, value] of Object.entries(jsonSchema)) { | ||
if (key === "additionalProperties" || key === "$schema") { | ||
continue; | ||
} | ||
result[key] = prepareJsonSchema(value); | ||
} | ||
return result; | ||
} | ||
function getToolCallsFromParts({ | ||
@@ -457,2 +432,71 @@ parts, | ||
}); | ||
function prepareToolsAndToolConfig(mode) { | ||
var _a; | ||
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0; | ||
if (tools == null) { | ||
return { tools: void 0, toolConfig: void 0 }; | ||
} | ||
const mappedTools = { | ||
functionDeclarations: tools.map((tool) => { | ||
var _a2; | ||
return { | ||
name: tool.name, | ||
description: (_a2 = tool.description) != null ? _a2 : "", | ||
parameters: prepareJsonSchema(tool.parameters) | ||
}; | ||
}) | ||
}; | ||
const toolChoice = mode.toolChoice; | ||
if (toolChoice == null) { | ||
return { tools: mappedTools, toolConfig: void 0 }; | ||
} | ||
const type = toolChoice.type; | ||
switch (type) { | ||
case "auto": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { functionCallingConfig: { mode: "AUTO" } } | ||
}; | ||
case "none": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { functionCallingConfig: { mode: "NONE" } } | ||
}; | ||
case "required": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { functionCallingConfig: { mode: "ANY" } } | ||
}; | ||
case "tool": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { | ||
functionCallingConfig: { | ||
mode: "ANY", | ||
allowedFunctionNames: [toolChoice.toolName] | ||
} | ||
} | ||
}; | ||
default: { | ||
const _exhaustiveCheck = type; | ||
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`); | ||
} | ||
} | ||
} | ||
function prepareJsonSchema(jsonSchema) { | ||
if (typeof jsonSchema !== "object") { | ||
return jsonSchema; | ||
} | ||
if (Array.isArray(jsonSchema)) { | ||
return jsonSchema.map(prepareJsonSchema); | ||
} | ||
const result = {}; | ||
for (const [key, value] of Object.entries(jsonSchema)) { | ||
if (key === "additionalProperties" || key === "$schema") { | ||
continue; | ||
} | ||
result[key] = prepareJsonSchema(value); | ||
} | ||
return result; | ||
} | ||
@@ -459,0 +503,0 @@ // src/google-facade.ts |
@@ -178,3 +178,2 @@ "use strict"; | ||
}) { | ||
var _a; | ||
const type = mode.type; | ||
@@ -211,10 +210,2 @@ const warnings = []; | ||
case "regular": { | ||
const functionDeclarations = (_a = mode.tools) == null ? void 0 : _a.map((tool) => { | ||
var _a2; | ||
return { | ||
name: tool.name, | ||
description: (_a2 = tool.description) != null ? _a2 : "", | ||
parameters: prepareJsonSchema(tool.parameters) | ||
}; | ||
}); | ||
return { | ||
@@ -224,3 +215,3 @@ args: { | ||
contents, | ||
tools: functionDeclarations == null ? void 0 : { functionDeclarations } | ||
...prepareToolsAndToolConfig(mode) | ||
}, | ||
@@ -380,18 +371,2 @@ warnings | ||
}; | ||
function prepareJsonSchema(jsonSchema) { | ||
if (typeof jsonSchema !== "object") { | ||
return jsonSchema; | ||
} | ||
if (Array.isArray(jsonSchema)) { | ||
return jsonSchema.map(prepareJsonSchema); | ||
} | ||
const result = {}; | ||
for (const [key, value] of Object.entries(jsonSchema)) { | ||
if (key === "additionalProperties" || key === "$schema") { | ||
continue; | ||
} | ||
result[key] = prepareJsonSchema(value); | ||
} | ||
return result; | ||
} | ||
function getToolCallsFromParts({ | ||
@@ -457,2 +432,71 @@ parts, | ||
}); | ||
function prepareToolsAndToolConfig(mode) { | ||
var _a; | ||
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0; | ||
if (tools == null) { | ||
return { tools: void 0, toolConfig: void 0 }; | ||
} | ||
const mappedTools = { | ||
functionDeclarations: tools.map((tool) => { | ||
var _a2; | ||
return { | ||
name: tool.name, | ||
description: (_a2 = tool.description) != null ? _a2 : "", | ||
parameters: prepareJsonSchema(tool.parameters) | ||
}; | ||
}) | ||
}; | ||
const toolChoice = mode.toolChoice; | ||
if (toolChoice == null) { | ||
return { tools: mappedTools, toolConfig: void 0 }; | ||
} | ||
const type = toolChoice.type; | ||
switch (type) { | ||
case "auto": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { functionCallingConfig: { mode: "AUTO" } } | ||
}; | ||
case "none": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { functionCallingConfig: { mode: "NONE" } } | ||
}; | ||
case "required": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { functionCallingConfig: { mode: "ANY" } } | ||
}; | ||
case "tool": | ||
return { | ||
tools: mappedTools, | ||
toolConfig: { | ||
functionCallingConfig: { | ||
mode: "ANY", | ||
allowedFunctionNames: [toolChoice.toolName] | ||
} | ||
} | ||
}; | ||
default: { | ||
const _exhaustiveCheck = type; | ||
throw new Error(`Unsupported tool choice type: ${_exhaustiveCheck}`); | ||
} | ||
} | ||
} | ||
function prepareJsonSchema(jsonSchema) { | ||
if (typeof jsonSchema !== "object") { | ||
return jsonSchema; | ||
} | ||
if (Array.isArray(jsonSchema)) { | ||
return jsonSchema.map(prepareJsonSchema); | ||
} | ||
const result = {}; | ||
for (const [key, value] of Object.entries(jsonSchema)) { | ||
if (key === "additionalProperties" || key === "$schema") { | ||
continue; | ||
} | ||
result[key] = prepareJsonSchema(value); | ||
} | ||
return result; | ||
} | ||
@@ -459,0 +503,0 @@ // src/google-facade.ts |
{ | ||
"name": "@ai-sdk/google", | ||
"version": "0.0.16", | ||
"version": "0.0.17", | ||
"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 - Google Generative AI Provider | ||
The Google provider for the [Vercel AI SDK](https://sdk.vercel.ai/docs) contains language model support for the [Google Generative AI](https://ai.google/discover/generativeai/) APIs. | ||
It creates language model objects that can be used with the `generateText`, `streamText`, `generateObject`, and `streamObject` AI functions. | ||
The **[Google Generative AI provider](https://sdk.vercel.ai/providers/ai-sdk-providers/google-generative-ai)** for the [Vercel AI SDK](https://sdk.vercel.ai/docs) contains language model support for the [Google Generative AI](https://ai.google/discover/generativeai/) APIs. | ||
## Setup | ||
The Google provider is available in the `@ai-sdk/google` module. You can install it with | ||
The Google Generative AI provider is available in the `@ai-sdk/google` module. You can install it with | ||
@@ -22,55 +21,16 @@ ```bash | ||
If you need a customized setup, you can import `createGoogleGenerativeAI` from `@ai-sdk/google` and create a provider instance with your settings: | ||
## Example | ||
```ts | ||
import { createGoogleGenerativeAI } from '@ai-sdk/google'; | ||
import { google } from '@ai-sdk/google'; | ||
import { generateText } from 'ai'; | ||
const google = createGoogleGenerativeAI({ | ||
// custom settings | ||
const { text } = await generateText({ | ||
model: google('models/gemini-pro'), | ||
prompt: 'Write a vegetarian lasagna recipe for 4 people.', | ||
}); | ||
``` | ||
You can use the following optional settings to customize the Google Generative AI provider instance: | ||
## Documentation | ||
- **baseURL** _string_ | ||
Use a different URL prefix for API calls, e.g. to use proxy servers. | ||
The default prefix is `https://generativelanguage.googleapis.com/v1beta`. | ||
- **apiKey** _string_ | ||
API key that is being send using the `x-goog-api-key` header. | ||
It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable. | ||
- **headers** _Record<string,string>_ | ||
Custom headers to include in the requests. | ||
## Models | ||
You can create models that call the [Google Generative AI API](https://ai.google.dev/api/rest) using the provider instance. | ||
The first argument is the model id, e.g. `models/gemini-pro`. | ||
The models support tool calls and some have multi-modal capabilities. | ||
```ts | ||
const model = google('models/gemini-pro'); | ||
``` | ||
Google Generative AI models support also some model specific 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 = google('models/gemini-pro', { | ||
topK: 0.2, | ||
}); | ||
``` | ||
The following optional settings are available for Google Generative AI models: | ||
- **topK** _number_ | ||
Optional. The maximum number of tokens to consider when sampling. | ||
Models use nucleus sampling or combined Top-k and nucleus sampling. | ||
Top-k sampling considers the set of topK most probable tokens. | ||
Models running with nucleus sampling don't allow topK setting. | ||
Please check out the **[Google Generative AI provider documentation](https://sdk.vercel.ai/providers/ai-sdk-providers/google-generative-ai)** 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123453
1724
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