@ai-sdk/google 0.0.0-85f9a635-20240518005312
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +75 -0
- package/dist/index.d.mts +95 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +516 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +499 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2023 Vercel, Inc.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Vercel AI SDK - Google Generative AI Provider
|
2
|
+
|
3
|
+
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.
|
4
|
+
It creates language model objects that can be used with the `generateText`, `streamText`, `generateObject`, and `streamObject` AI functions.
|
5
|
+
|
6
|
+
## Setup
|
7
|
+
|
8
|
+
The Google provider is available in the `@ai-sdk/google` module. You can install it with
|
9
|
+
|
10
|
+
```bash
|
11
|
+
npm i @ai-sdk/google
|
12
|
+
```
|
13
|
+
|
14
|
+
## Provider Instance
|
15
|
+
|
16
|
+
You can import the default provider instance `google` from `@ai-sdk/google`:
|
17
|
+
|
18
|
+
```ts
|
19
|
+
import { google } from '@ai-sdk/google';
|
20
|
+
```
|
21
|
+
|
22
|
+
If you need a customized setup, you can import `createGoogleGenerativeAI` from `@ai-sdk/google` and create a provider instance with your settings:
|
23
|
+
|
24
|
+
```ts
|
25
|
+
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
26
|
+
|
27
|
+
const google = createGoogleGenerativeAI({
|
28
|
+
// custom settings
|
29
|
+
});
|
30
|
+
```
|
31
|
+
|
32
|
+
You can use the following optional settings to customize the Google Generative AI provider instance:
|
33
|
+
|
34
|
+
- **baseURL** _string_
|
35
|
+
|
36
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
37
|
+
The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
38
|
+
|
39
|
+
- **apiKey** _string_
|
40
|
+
|
41
|
+
API key that is being send using the `x-goog-api-key` header.
|
42
|
+
It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
43
|
+
|
44
|
+
- **headers** _Record<string,string>_
|
45
|
+
|
46
|
+
Custom headers to include in the requests.
|
47
|
+
|
48
|
+
## Models
|
49
|
+
|
50
|
+
You can create models that call the [Google Generative AI API](https://ai.google.dev/api/rest) using the provider instance.
|
51
|
+
The first argument is the model id, e.g. `models/gemini-pro`.
|
52
|
+
The models support tool calls and some have multi-modal capabilities.
|
53
|
+
|
54
|
+
```ts
|
55
|
+
const model = google('models/gemini-pro');
|
56
|
+
```
|
57
|
+
|
58
|
+
Google Generative AI models support also some model specific settings that are not part of the [standard call settings](/docs/ai-core/settings).
|
59
|
+
You can pass them as an options argument:
|
60
|
+
|
61
|
+
```ts
|
62
|
+
const model = google('models/gemini-pro', {
|
63
|
+
topK: 0.2,
|
64
|
+
});
|
65
|
+
```
|
66
|
+
|
67
|
+
The following optional settings are available for Google Generative AI models:
|
68
|
+
|
69
|
+
- **topK** _number_
|
70
|
+
|
71
|
+
Optional. The maximum number of tokens to consider when sampling.
|
72
|
+
|
73
|
+
Models use nucleus sampling or combined Top-k and nucleus sampling.
|
74
|
+
Top-k sampling considers the set of topK most probable tokens.
|
75
|
+
Models running with nucleus sampling don't allow topK setting.
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
import { LanguageModelV1 } from '@ai-sdk/provider';
|
2
|
+
|
3
|
+
type GoogleGenerativeAIModelId = 'models/gemini-1.5-flash-latest' | 'models/gemini-1.5-pro-latest' | 'models/gemini-pro' | 'models/gemini-pro-vision' | (string & {});
|
4
|
+
interface GoogleGenerativeAISettings {
|
5
|
+
/**
|
6
|
+
Optional. The maximum number of tokens to consider when sampling.
|
7
|
+
|
8
|
+
Models use nucleus sampling or combined Top-k and nucleus sampling.
|
9
|
+
Top-k sampling considers the set of topK most probable tokens.
|
10
|
+
Models running with nucleus sampling don't allow topK setting.
|
11
|
+
*/
|
12
|
+
topK?: number;
|
13
|
+
}
|
14
|
+
|
15
|
+
type GoogleGenerativeAIConfig = {
|
16
|
+
provider: string;
|
17
|
+
baseURL: string;
|
18
|
+
headers: () => Record<string, string | undefined>;
|
19
|
+
generateId: () => string;
|
20
|
+
};
|
21
|
+
declare class GoogleGenerativeAILanguageModel implements LanguageModelV1 {
|
22
|
+
readonly specificationVersion = "v1";
|
23
|
+
readonly defaultObjectGenerationMode = "json";
|
24
|
+
readonly modelId: GoogleGenerativeAIModelId;
|
25
|
+
readonly settings: GoogleGenerativeAISettings;
|
26
|
+
private readonly config;
|
27
|
+
constructor(modelId: GoogleGenerativeAIModelId, settings: GoogleGenerativeAISettings, config: GoogleGenerativeAIConfig);
|
28
|
+
get provider(): string;
|
29
|
+
private getArgs;
|
30
|
+
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
31
|
+
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
32
|
+
}
|
33
|
+
|
34
|
+
interface GoogleGenerativeAIProvider {
|
35
|
+
(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
36
|
+
chat(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
37
|
+
/**
|
38
|
+
* @deprecated Use `chat()` instead.
|
39
|
+
*/
|
40
|
+
generativeAI(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
41
|
+
}
|
42
|
+
interface GoogleGenerativeAIProviderSettings {
|
43
|
+
/**
|
44
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
45
|
+
The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
46
|
+
*/
|
47
|
+
baseURL?: string;
|
48
|
+
/**
|
49
|
+
@deprecated Use `baseURL` instead.
|
50
|
+
*/
|
51
|
+
baseUrl?: string;
|
52
|
+
/**
|
53
|
+
API key that is being send using the `x-goog-api-key` header.
|
54
|
+
It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
55
|
+
*/
|
56
|
+
apiKey?: string;
|
57
|
+
/**
|
58
|
+
Custom headers to include in the requests.
|
59
|
+
*/
|
60
|
+
headers?: Record<string, string>;
|
61
|
+
generateId?: () => string;
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
Create a Google Generative AI provider instance.
|
65
|
+
*/
|
66
|
+
declare function createGoogleGenerativeAI(options?: GoogleGenerativeAIProviderSettings): GoogleGenerativeAIProvider;
|
67
|
+
/**
|
68
|
+
Default Google Generative AI provider instance.
|
69
|
+
*/
|
70
|
+
declare const google: GoogleGenerativeAIProvider;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* @deprecated Use `createGoogleGenerativeAI` instead.
|
74
|
+
*/
|
75
|
+
declare class Google {
|
76
|
+
/**
|
77
|
+
* Base URL for the Google API calls.
|
78
|
+
*/
|
79
|
+
readonly baseURL: string;
|
80
|
+
readonly apiKey?: string;
|
81
|
+
readonly headers?: Record<string, string>;
|
82
|
+
private readonly generateId;
|
83
|
+
/**
|
84
|
+
* Creates a new Google provider instance.
|
85
|
+
*/
|
86
|
+
constructor(options?: GoogleGenerativeAIProviderSettings);
|
87
|
+
private get baseConfig();
|
88
|
+
/**
|
89
|
+
* @deprecated Use `chat()` instead.
|
90
|
+
*/
|
91
|
+
generativeAI(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
92
|
+
chat(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
93
|
+
}
|
94
|
+
|
95
|
+
export { Google, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
import { LanguageModelV1 } from '@ai-sdk/provider';
|
2
|
+
|
3
|
+
type GoogleGenerativeAIModelId = 'models/gemini-1.5-flash-latest' | 'models/gemini-1.5-pro-latest' | 'models/gemini-pro' | 'models/gemini-pro-vision' | (string & {});
|
4
|
+
interface GoogleGenerativeAISettings {
|
5
|
+
/**
|
6
|
+
Optional. The maximum number of tokens to consider when sampling.
|
7
|
+
|
8
|
+
Models use nucleus sampling or combined Top-k and nucleus sampling.
|
9
|
+
Top-k sampling considers the set of topK most probable tokens.
|
10
|
+
Models running with nucleus sampling don't allow topK setting.
|
11
|
+
*/
|
12
|
+
topK?: number;
|
13
|
+
}
|
14
|
+
|
15
|
+
type GoogleGenerativeAIConfig = {
|
16
|
+
provider: string;
|
17
|
+
baseURL: string;
|
18
|
+
headers: () => Record<string, string | undefined>;
|
19
|
+
generateId: () => string;
|
20
|
+
};
|
21
|
+
declare class GoogleGenerativeAILanguageModel implements LanguageModelV1 {
|
22
|
+
readonly specificationVersion = "v1";
|
23
|
+
readonly defaultObjectGenerationMode = "json";
|
24
|
+
readonly modelId: GoogleGenerativeAIModelId;
|
25
|
+
readonly settings: GoogleGenerativeAISettings;
|
26
|
+
private readonly config;
|
27
|
+
constructor(modelId: GoogleGenerativeAIModelId, settings: GoogleGenerativeAISettings, config: GoogleGenerativeAIConfig);
|
28
|
+
get provider(): string;
|
29
|
+
private getArgs;
|
30
|
+
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
31
|
+
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
32
|
+
}
|
33
|
+
|
34
|
+
interface GoogleGenerativeAIProvider {
|
35
|
+
(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
36
|
+
chat(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
37
|
+
/**
|
38
|
+
* @deprecated Use `chat()` instead.
|
39
|
+
*/
|
40
|
+
generativeAI(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
41
|
+
}
|
42
|
+
interface GoogleGenerativeAIProviderSettings {
|
43
|
+
/**
|
44
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
45
|
+
The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
46
|
+
*/
|
47
|
+
baseURL?: string;
|
48
|
+
/**
|
49
|
+
@deprecated Use `baseURL` instead.
|
50
|
+
*/
|
51
|
+
baseUrl?: string;
|
52
|
+
/**
|
53
|
+
API key that is being send using the `x-goog-api-key` header.
|
54
|
+
It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
55
|
+
*/
|
56
|
+
apiKey?: string;
|
57
|
+
/**
|
58
|
+
Custom headers to include in the requests.
|
59
|
+
*/
|
60
|
+
headers?: Record<string, string>;
|
61
|
+
generateId?: () => string;
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
Create a Google Generative AI provider instance.
|
65
|
+
*/
|
66
|
+
declare function createGoogleGenerativeAI(options?: GoogleGenerativeAIProviderSettings): GoogleGenerativeAIProvider;
|
67
|
+
/**
|
68
|
+
Default Google Generative AI provider instance.
|
69
|
+
*/
|
70
|
+
declare const google: GoogleGenerativeAIProvider;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* @deprecated Use `createGoogleGenerativeAI` instead.
|
74
|
+
*/
|
75
|
+
declare class Google {
|
76
|
+
/**
|
77
|
+
* Base URL for the Google API calls.
|
78
|
+
*/
|
79
|
+
readonly baseURL: string;
|
80
|
+
readonly apiKey?: string;
|
81
|
+
readonly headers?: Record<string, string>;
|
82
|
+
private readonly generateId;
|
83
|
+
/**
|
84
|
+
* Creates a new Google provider instance.
|
85
|
+
*/
|
86
|
+
constructor(options?: GoogleGenerativeAIProviderSettings);
|
87
|
+
private get baseConfig();
|
88
|
+
/**
|
89
|
+
* @deprecated Use `chat()` instead.
|
90
|
+
*/
|
91
|
+
generativeAI(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
92
|
+
chat(modelId: GoogleGenerativeAIModelId, settings?: GoogleGenerativeAISettings): GoogleGenerativeAILanguageModel;
|
93
|
+
}
|
94
|
+
|
95
|
+
export { Google, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|