@tanstack/ai-gemini 0.4.0 → 0.4.1
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/dist/esm/adapters/summarize.d.ts +9 -4
- package/dist/esm/adapters/summarize.js +6 -6
- package/dist/esm/adapters/summarize.js.map +1 -1
- package/dist/esm/utils/client.d.ts +2 -2
- package/dist/esm/utils/client.js +1 -0
- package/dist/esm/utils/client.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/summarize.ts +11 -14
- package/src/utils/client.ts +3 -1
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GeminiClientConfig } from '../utils.js';
|
|
2
2
|
import { SummarizeAdapter } from '@tanstack/ai/adapters';
|
|
3
3
|
import { StreamChunk, SummarizationOptions, SummarizationResult } from '@tanstack/ai';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for Gemini summarize adapter
|
|
6
|
+
*/
|
|
7
|
+
export interface GeminiSummarizeConfig extends GeminiClientConfig {
|
|
8
|
+
}
|
|
4
9
|
/**
|
|
5
10
|
* Available Gemini models for summarization
|
|
6
11
|
*/
|
|
@@ -38,7 +43,7 @@ export declare class GeminiSummarizeAdapter<TModel extends GeminiSummarizeModel>
|
|
|
38
43
|
providerOptions: GeminiSummarizeProviderOptions;
|
|
39
44
|
};
|
|
40
45
|
private client;
|
|
41
|
-
constructor(
|
|
46
|
+
constructor(config: GeminiSummarizeConfig, model: TModel);
|
|
42
47
|
summarize(options: SummarizationOptions): Promise<SummarizationResult>;
|
|
43
48
|
summarizeStream(options: SummarizationOptions): AsyncIterable<StreamChunk>;
|
|
44
49
|
private getFormatInstructions;
|
|
@@ -46,8 +51,8 @@ export declare class GeminiSummarizeAdapter<TModel extends GeminiSummarizeModel>
|
|
|
46
51
|
/**
|
|
47
52
|
* Creates a Gemini summarize adapter with explicit API key and model
|
|
48
53
|
*/
|
|
49
|
-
export declare function createGeminiSummarize<TModel extends GeminiSummarizeModel>(apiKey: string, model: TModel,
|
|
54
|
+
export declare function createGeminiSummarize<TModel extends GeminiSummarizeModel>(apiKey: string, model: TModel, config?: Omit<GeminiSummarizeConfig, 'apiKey'>): GeminiSummarizeAdapter<TModel>;
|
|
50
55
|
/**
|
|
51
56
|
* Creates a Gemini summarize adapter with API key from environment and required model
|
|
52
57
|
*/
|
|
53
|
-
export declare function geminiSummarize<TModel extends GeminiSummarizeModel>(model: TModel,
|
|
58
|
+
export declare function geminiSummarize<TModel extends GeminiSummarizeModel>(model: TModel, config?: Omit<GeminiSummarizeConfig, 'apiKey'>): GeminiSummarizeAdapter<TModel>;
|
|
@@ -7,10 +7,10 @@ const GeminiSummarizeModels = [
|
|
|
7
7
|
"gemini-2.0-flash-lite"
|
|
8
8
|
];
|
|
9
9
|
class GeminiSummarizeAdapter {
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(config, model) {
|
|
11
11
|
this.kind = "summarize";
|
|
12
12
|
this.name = "gemini";
|
|
13
|
-
this.client =
|
|
13
|
+
this.client = createGeminiClient(config);
|
|
14
14
|
this.model = model;
|
|
15
15
|
}
|
|
16
16
|
async summarize(options) {
|
|
@@ -122,12 +122,12 @@ ${options.text}` }
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function createGeminiSummarize(apiKey, model,
|
|
126
|
-
return new GeminiSummarizeAdapter(apiKey, model
|
|
125
|
+
function createGeminiSummarize(apiKey, model, config) {
|
|
126
|
+
return new GeminiSummarizeAdapter({ ...config, apiKey }, model);
|
|
127
127
|
}
|
|
128
|
-
function geminiSummarize(model,
|
|
128
|
+
function geminiSummarize(model, config) {
|
|
129
129
|
const apiKey = getGeminiApiKeyFromEnv();
|
|
130
|
-
return new GeminiSummarizeAdapter(apiKey, model
|
|
130
|
+
return new GeminiSummarizeAdapter({ ...config, apiKey }, model);
|
|
131
131
|
}
|
|
132
132
|
export {
|
|
133
133
|
GeminiSummarizeAdapter,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.js","sources":["../../../src/adapters/summarize.ts"],"sourcesContent":["import { FinishReason } from '@google/genai'\nimport {\n createGeminiClient,\n generateId,\n getGeminiApiKeyFromEnv,\n} from '../utils'\
|
|
1
|
+
{"version":3,"file":"summarize.js","sources":["../../../src/adapters/summarize.ts"],"sourcesContent":["import { FinishReason } from '@google/genai'\nimport {\n createGeminiClient,\n generateId,\n getGeminiApiKeyFromEnv,\n} from '../utils'\nimport type { GoogleGenAI } from '@google/genai'\nimport type { GeminiClientConfig } from '../utils'\nimport type { SummarizeAdapter } from '@tanstack/ai/adapters'\nimport type {\n StreamChunk,\n SummarizationOptions,\n SummarizationResult,\n} from '@tanstack/ai'\n\n/**\n * Configuration for Gemini summarize adapter\n */\nexport interface GeminiSummarizeConfig extends GeminiClientConfig {}\n/**\n * Available Gemini models for summarization\n */\nexport const GeminiSummarizeModels = [\n 'gemini-2.0-flash',\n 'gemini-1.5-flash',\n 'gemini-1.5-pro',\n 'gemini-2.0-flash-lite',\n] as const\n\nexport type GeminiSummarizeModel = (typeof GeminiSummarizeModels)[number]\n\n/**\n * Provider-specific options for Gemini summarization\n */\nexport interface GeminiSummarizeProviderOptions {\n /** Generation configuration */\n generationConfig?: {\n temperature?: number\n topP?: number\n topK?: number\n maxOutputTokens?: number\n stopSequences?: Array<string>\n }\n /** Safety settings */\n safetySettings?: Array<{\n category: string\n threshold: string\n }>\n}\n\nexport interface GeminiSummarizeAdapterOptions {\n // Additional adapter options can be added here\n}\n\n/**\n * Gemini Summarize Adapter\n * A tree-shakeable summarization adapter for Google Gemini\n */\nexport class GeminiSummarizeAdapter<\n TModel extends GeminiSummarizeModel,\n> implements SummarizeAdapter<TModel, GeminiSummarizeProviderOptions> {\n readonly kind = 'summarize' as const\n readonly name = 'gemini' as const\n readonly model: TModel\n\n // Type-only property - never assigned at runtime\n declare '~types': {\n providerOptions: GeminiSummarizeProviderOptions\n }\n\n private client: GoogleGenAI\n\n constructor(config: GeminiSummarizeConfig, model: TModel) {\n this.client = createGeminiClient(config)\n this.model = model\n }\n\n async summarize(options: SummarizationOptions): Promise<SummarizationResult> {\n const model = options.model\n\n // Build the system prompt based on format\n const formatInstructions = this.getFormatInstructions(options.style)\n const lengthInstructions = options.maxLength\n ? ` Keep the summary under ${options.maxLength} tokens.`\n : ''\n\n const systemPrompt = `You are a helpful assistant that summarizes text. ${formatInstructions}${lengthInstructions}`\n\n const response = await this.client.models.generateContent({\n model,\n contents: [\n {\n role: 'user',\n parts: [\n { text: `Please summarize the following:\\n\\n${options.text}` },\n ],\n },\n ],\n config: {\n systemInstruction: systemPrompt,\n },\n })\n\n const summary = response.text ?? ''\n const inputTokens = response.usageMetadata?.promptTokenCount ?? 0\n const outputTokens = response.usageMetadata?.candidatesTokenCount ?? 0\n\n return {\n id: generateId('sum'),\n model,\n summary,\n usage: {\n promptTokens: inputTokens,\n completionTokens: outputTokens,\n totalTokens: inputTokens + outputTokens,\n },\n }\n }\n\n async *summarizeStream(\n options: SummarizationOptions,\n ): AsyncIterable<StreamChunk> {\n const model = options.model\n const id = generateId('sum')\n let accumulatedContent = ''\n let inputTokens = 0\n let outputTokens = 0\n\n // Build the system prompt based on format\n const formatInstructions = this.getFormatInstructions(options.style)\n const lengthInstructions = options.maxLength\n ? ` Keep the summary under ${options.maxLength} words.`\n : ''\n\n const systemPrompt = `You are a helpful assistant that summarizes text. ${formatInstructions}${lengthInstructions}`\n\n const result = await this.client.models.generateContentStream({\n model,\n contents: [\n {\n role: 'user',\n parts: [\n { text: `Please summarize the following:\\n\\n${options.text}` },\n ],\n },\n ],\n config: {\n systemInstruction: systemPrompt,\n },\n })\n\n for await (const chunk of result) {\n // Track usage metadata\n if (chunk.usageMetadata) {\n inputTokens = chunk.usageMetadata.promptTokenCount ?? inputTokens\n outputTokens = chunk.usageMetadata.candidatesTokenCount ?? outputTokens\n }\n\n if (chunk.candidates?.[0]?.content?.parts) {\n for (const part of chunk.candidates[0].content.parts) {\n if (part.text) {\n accumulatedContent += part.text\n yield {\n type: 'TEXT_MESSAGE_CONTENT',\n messageId: id,\n model,\n timestamp: Date.now(),\n delta: part.text,\n content: accumulatedContent,\n }\n }\n }\n }\n\n // Check for finish reason\n const finishReason = chunk.candidates?.[0]?.finishReason\n if (\n finishReason === FinishReason.STOP ||\n finishReason === FinishReason.MAX_TOKENS ||\n finishReason === FinishReason.SAFETY\n ) {\n yield {\n type: 'RUN_FINISHED',\n runId: id,\n model,\n timestamp: Date.now(),\n finishReason:\n finishReason === FinishReason.STOP\n ? 'stop'\n : finishReason === FinishReason.MAX_TOKENS\n ? 'length'\n : 'content_filter',\n usage: {\n promptTokens: inputTokens,\n completionTokens: outputTokens,\n totalTokens: inputTokens + outputTokens,\n },\n }\n }\n }\n }\n\n private getFormatInstructions(\n style?: 'paragraph' | 'bullet-points' | 'concise',\n ): string {\n switch (style) {\n case 'bullet-points':\n return 'Provide the summary as bullet points.'\n case 'concise':\n return 'Provide a very brief one or two sentence summary.'\n case 'paragraph':\n default:\n return 'Provide the summary in paragraph form.'\n }\n }\n}\n\n/**\n * Creates a Gemini summarize adapter with explicit API key and model\n */\nexport function createGeminiSummarize<TModel extends GeminiSummarizeModel>(\n apiKey: string,\n model: TModel,\n config?: Omit<GeminiSummarizeConfig, 'apiKey'>,\n): GeminiSummarizeAdapter<TModel> {\n return new GeminiSummarizeAdapter({ ...config, apiKey }, model)\n}\n\n/**\n * Creates a Gemini summarize adapter with API key from environment and required model\n */\nexport function geminiSummarize<TModel extends GeminiSummarizeModel>(\n model: TModel,\n config?: Omit<GeminiSummarizeConfig, 'apiKey'>,\n): GeminiSummarizeAdapter<TModel> {\n const apiKey = getGeminiApiKeyFromEnv()\n return new GeminiSummarizeAdapter({ ...config, apiKey }, model)\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AA+BO,MAAM,uBAEyD;AAAA,EAYpE,YAAY,QAA+B,OAAe;A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AO;AAAA,MACT,KAAK;AAAA,MACL;AACE,eAAO;AAAA,IAAA;AAAA,EAEb;AACF;AAKO,SAAS,sBACd,QACA,OACA,QACgC;AAChC,SAAO,IAAI,uBAAuB,EAAE,GAAG,QAAQ,OAAA,GAAU,KAAK;AAChE;AAKO,SAAS,gBACd,OACA,QACgC;AAChC,QAAM,SAAS,uBAAA;AACf,SAAO,IAAI,uBAAuB,EAAE,GAAG,QAAQ,OAAA,GAAU,KAAK;AAChE;"}
|
package/dist/esm/utils/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../../src/utils/client.ts"],"sourcesContent":["import { GoogleGenAI } from '@google/genai'\n\nexport interface GeminiClientConfig {\n apiKey: string\n}\n\n/**\n * Creates a Google Generative AI client instance\n */\nexport function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {\n return new GoogleGenAI({\n apiKey: config.apiKey,\n })\n}\n\n/**\n * Gets Google API key from environment variables\n * @throws Error if GOOGLE_API_KEY or GEMINI_API_KEY is not found\n */\nexport function getGeminiApiKeyFromEnv(): string {\n const env =\n typeof globalThis !== 'undefined' && (globalThis as any).window?.env\n ? (globalThis as any).window.env\n : typeof process !== 'undefined'\n ? process.env\n : undefined\n const key = env?.GOOGLE_API_KEY || env?.GEMINI_API_KEY\n\n if (!key) {\n throw new Error(\n 'GOOGLE_API_KEY or GEMINI_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key.',\n )\n }\n\n return key\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n}\n"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../../src/utils/client.ts"],"sourcesContent":["import { GoogleGenAI } from '@google/genai'\nimport type { GoogleGenAIOptions } from '@google/genai'\n\nexport interface GeminiClientConfig extends GoogleGenAIOptions {\n apiKey: string\n}\n\n/**\n * Creates a Google Generative AI client instance\n */\nexport function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {\n return new GoogleGenAI({\n ...config,\n apiKey: config.apiKey,\n })\n}\n\n/**\n * Gets Google API key from environment variables\n * @throws Error if GOOGLE_API_KEY or GEMINI_API_KEY is not found\n */\nexport function getGeminiApiKeyFromEnv(): string {\n const env =\n typeof globalThis !== 'undefined' && (globalThis as any).window?.env\n ? (globalThis as any).window.env\n : typeof process !== 'undefined'\n ? process.env\n : undefined\n const key = env?.GOOGLE_API_KEY || env?.GEMINI_API_KEY\n\n if (!key) {\n throw new Error(\n 'GOOGLE_API_KEY or GEMINI_API_KEY is required. Please set it in your environment variables or use the factory function with an explicit API key.',\n )\n }\n\n return key\n}\n\n/**\n * Generates a unique ID with a prefix\n */\nexport function generateId(prefix: string): string {\n return `${prefix}-${Date.now()}-${Math.random().toString(36).substring(7)}`\n}\n"],"names":[],"mappings":";AAUO,SAAS,mBAAmB,QAAyC;AAC1E,SAAO,IAAI,YAAY;AAAA,IACrB,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,EAAA,CAChB;AACH;AAMO,SAAS,yBAAiC;AAC/C,QAAM,MACJ,OAAO,eAAe,eAAgB,WAAmB,QAAQ,MAC5D,WAAmB,OAAO,MAC3B,OAAO,YAAY,cACjB,QAAQ,MACR;AACR,QAAM,MAAM,KAAK,kBAAkB,KAAK;AAExC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,SAAO;AACT;AAKO,SAAS,WAAW,QAAwB;AACjD,SAAO,GAAG,MAAM,IAAI,KAAK,KAAK,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC;AAC3E;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-gemini",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Google Gemini adapter for TanStack AI",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"@google/genai": "^1.30.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@tanstack/ai": "^0.4.
|
|
36
|
+
"@tanstack/ai": "^0.4.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@vitest/coverage-v8": "4.0.14",
|
|
40
40
|
"vite": "^7.2.7",
|
|
41
|
-
"@tanstack/ai": "0.4.
|
|
41
|
+
"@tanstack/ai": "0.4.2"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "vite build",
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
generateId,
|
|
5
5
|
getGeminiApiKeyFromEnv,
|
|
6
6
|
} from '../utils'
|
|
7
|
-
|
|
8
7
|
import type { GoogleGenAI } from '@google/genai'
|
|
8
|
+
import type { GeminiClientConfig } from '../utils'
|
|
9
9
|
import type { SummarizeAdapter } from '@tanstack/ai/adapters'
|
|
10
10
|
import type {
|
|
11
11
|
StreamChunk,
|
|
@@ -13,6 +13,10 @@ import type {
|
|
|
13
13
|
SummarizationResult,
|
|
14
14
|
} from '@tanstack/ai'
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for Gemini summarize adapter
|
|
18
|
+
*/
|
|
19
|
+
export interface GeminiSummarizeConfig extends GeminiClientConfig {}
|
|
16
20
|
/**
|
|
17
21
|
* Available Gemini models for summarization
|
|
18
22
|
*/
|
|
@@ -66,15 +70,8 @@ export class GeminiSummarizeAdapter<
|
|
|
66
70
|
|
|
67
71
|
private client: GoogleGenAI
|
|
68
72
|
|
|
69
|
-
constructor(
|
|
70
|
-
|
|
71
|
-
model: TModel,
|
|
72
|
-
_options: GeminiSummarizeAdapterOptions = {},
|
|
73
|
-
) {
|
|
74
|
-
this.client =
|
|
75
|
-
typeof apiKeyOrClient === 'string'
|
|
76
|
-
? createGeminiClient({ apiKey: apiKeyOrClient })
|
|
77
|
-
: apiKeyOrClient
|
|
73
|
+
constructor(config: GeminiSummarizeConfig, model: TModel) {
|
|
74
|
+
this.client = createGeminiClient(config)
|
|
78
75
|
this.model = model
|
|
79
76
|
}
|
|
80
77
|
|
|
@@ -224,9 +221,9 @@ export class GeminiSummarizeAdapter<
|
|
|
224
221
|
export function createGeminiSummarize<TModel extends GeminiSummarizeModel>(
|
|
225
222
|
apiKey: string,
|
|
226
223
|
model: TModel,
|
|
227
|
-
|
|
224
|
+
config?: Omit<GeminiSummarizeConfig, 'apiKey'>,
|
|
228
225
|
): GeminiSummarizeAdapter<TModel> {
|
|
229
|
-
return new GeminiSummarizeAdapter(apiKey, model
|
|
226
|
+
return new GeminiSummarizeAdapter({ ...config, apiKey }, model)
|
|
230
227
|
}
|
|
231
228
|
|
|
232
229
|
/**
|
|
@@ -234,8 +231,8 @@ export function createGeminiSummarize<TModel extends GeminiSummarizeModel>(
|
|
|
234
231
|
*/
|
|
235
232
|
export function geminiSummarize<TModel extends GeminiSummarizeModel>(
|
|
236
233
|
model: TModel,
|
|
237
|
-
|
|
234
|
+
config?: Omit<GeminiSummarizeConfig, 'apiKey'>,
|
|
238
235
|
): GeminiSummarizeAdapter<TModel> {
|
|
239
236
|
const apiKey = getGeminiApiKeyFromEnv()
|
|
240
|
-
return new GeminiSummarizeAdapter(apiKey, model
|
|
237
|
+
return new GeminiSummarizeAdapter({ ...config, apiKey }, model)
|
|
241
238
|
}
|
package/src/utils/client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GoogleGenAI } from '@google/genai'
|
|
2
|
+
import type { GoogleGenAIOptions } from '@google/genai'
|
|
2
3
|
|
|
3
|
-
export interface GeminiClientConfig {
|
|
4
|
+
export interface GeminiClientConfig extends GoogleGenAIOptions {
|
|
4
5
|
apiKey: string
|
|
5
6
|
}
|
|
6
7
|
|
|
@@ -9,6 +10,7 @@ export interface GeminiClientConfig {
|
|
|
9
10
|
*/
|
|
10
11
|
export function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {
|
|
11
12
|
return new GoogleGenAI({
|
|
13
|
+
...config,
|
|
12
14
|
apiKey: config.apiKey,
|
|
13
15
|
})
|
|
14
16
|
}
|