@ainetwork/adk-provider-model-gemini 0.2.1 → 0.2.3
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/index.cjs +5 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -18
- package/dist/index.js.map +1 -1
- package/index.ts +8 -24
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,6 @@ __export(index_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
var import_modules = require("@ainetwork/adk/modules");
|
|
27
27
|
var import_memory = require("@ainetwork/adk/types/memory");
|
|
28
|
-
var import_tool = require("@ainetwork/adk/types/tool");
|
|
29
28
|
var import_genai = require("@google/genai");
|
|
30
29
|
var GeminiModel = class extends import_modules.BaseModel {
|
|
31
30
|
client;
|
|
@@ -142,23 +141,11 @@ var GeminiModel = class extends import_modules.BaseModel {
|
|
|
142
141
|
convertToolsToFunctions(tools) {
|
|
143
142
|
const functions = [];
|
|
144
143
|
for (const tool of tools) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
functions.push({
|
|
151
|
-
name: id,
|
|
152
|
-
description: mcpTool.description,
|
|
153
|
-
parametersJsonSchema: mcpTool.inputSchema
|
|
154
|
-
});
|
|
155
|
-
} else {
|
|
156
|
-
const { id, card } = tool;
|
|
157
|
-
functions.push({
|
|
158
|
-
name: id,
|
|
159
|
-
description: card.description
|
|
160
|
-
});
|
|
161
|
-
}
|
|
144
|
+
functions.push({
|
|
145
|
+
name: tool.toolName,
|
|
146
|
+
description: tool.description,
|
|
147
|
+
parametersJsonSchema: tool.inputSchema
|
|
148
|
+
});
|
|
162
149
|
}
|
|
163
150
|
return functions;
|
|
164
151
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { BaseModel } from \"@ainetwork/adk/modules\";\nimport { MessageObject, MessageRole, type ThreadObject } from \"@ainetwork/adk/types/memory\";\nimport type {\n\tLLMStream,\n\tStreamChunk,\n} from \"@ainetwork/adk/types/stream\";\nimport type {\n\tFetchResponse,\n\
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { BaseModel } from \"@ainetwork/adk/modules\";\nimport { MessageObject, MessageRole, type ThreadObject } from \"@ainetwork/adk/types/memory\";\nimport type {\n\tLLMStream,\n\tStreamChunk,\n} from \"@ainetwork/adk/types/stream\";\nimport type {\n\tFetchResponse,\n\tToolCall,\n\tConnectorTool,\n} from \"@ainetwork/adk/types/connector\";\nimport {\n\ttype Content,\n\ttype FunctionCall,\n\ttype FunctionDeclaration,\n\ttype GenerateContentResponse,\n\tGoogleGenAI,\n} from \"@google/genai\";\n\nexport class GeminiModel extends BaseModel<Content, FunctionDeclaration> {\n\tprivate client: GoogleGenAI;\n\tprivate modelName: string;\n\n\tconstructor(apiKey: string, modelName: string) {\n\t\tsuper();\n\t\tthis.client = new GoogleGenAI({ apiKey });\n\t\tthis.modelName = modelName;\n\t}\n\n\tprivate getMessageRole(role: MessageRole) {\n\t\tswitch (role) {\n\t\t\tcase MessageRole.USER:\n\t\t\t\treturn \"user\";\n\t\t\tcase MessageRole.MODEL:\n\t\t\tcase MessageRole.SYSTEM:\n\t\t\t\treturn \"model\";\n\t\t\tdefault:\n\t\t\t\treturn \"model\"; /*FIXME*/\n\t\t}\n\t}\n\n\tgenerateMessages(params: {\n\t\tquery: string;\n\t\tthread?: ThreadObject;\n\t\tsystemPrompt?: string;\n\t}): Content[] {\n\t\tconst { query, thread, systemPrompt } = params;\n\t\tconst messages: Content[] = !systemPrompt\n\t\t\t? []\n\t\t\t: [{ role: \"model\", parts: [{ text: systemPrompt.trim() }] }];\n\t\tconst sessionContent: Content[] = !thread\n\t\t\t? []\n\t\t\t: thread.messages.map((message: MessageObject) => {\n\t\t\t\t\t// TODO: check message.content.type\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: this.getMessageRole(message.role),\n\t\t\t\t\t\tparts: [{ text: message.content.parts[0] }],\n\t\t\t\t\t};\n\t\t\t\t});\n\t\tconst userContent: Content = { role: \"user\", parts: [{ text: query }] };\n\t\treturn messages.concat(sessionContent).concat(userContent);\n\t}\n\n\tappendMessages(messages: Content[], message: string): void {\n\t\tmessages.push({\n\t\t\trole: \"user\",\n\t\t\tparts: [{ text: message }],\n\t\t});\n\t}\n\n\tasync fetch(messages: Content[]): Promise<FetchResponse> {\n\t\tconst response = await this.client.models.generateContent({\n\t\t\tmodel: this.modelName,\n\t\t\tcontents: messages,\n\t\t});\n\n\t\treturn { content: response.text };\n\t}\n\n\tasync fetchWithContextMessage(\n\t\tmessages: Content[],\n\t\tfunctions: FunctionDeclaration[],\n\t): Promise<FetchResponse> {\n\t\tif (functions.length > 0) {\n\t\t\tconst response = await this.client.models.generateContent({\n\t\t\t\tmodel: this.modelName,\n\t\t\t\tcontents: messages,\n\t\t\t\tconfig: {\n\t\t\t\t\ttools: [{ functionDeclarations: functions }],\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst { text, functionCalls } = response;\n\t\t\tconst hasName = (\n\t\t\t\tvalue: FunctionCall,\n\t\t\t): value is FunctionCall & { name: string } => {\n\t\t\t\treturn value.name !== undefined;\n\t\t\t};\n\t\t\tconst toolCalls: ToolCall[] | undefined = functionCalls\n\t\t\t\t?.filter(hasName)\n\t\t\t\t.map((value) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tname: value.name,\n\t\t\t\t\t\targuments: value.args,\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\treturn {\n\t\t\t\tcontent: text,\n\t\t\t\ttoolCalls,\n\t\t\t};\n\t\t}\n\t\treturn await this.fetch(messages);\n\t}\n\n\tasync fetchStreamWithContextMessage(\n\t\tmessages: Content[],\n\t\tfunctions: FunctionDeclaration[],\n\t): Promise<LLMStream> {\n\t\tconst stream = await this.client.models.generateContentStream({\n\t\t\tmodel: this.modelName,\n\t\t\tcontents: messages,\n\t\t\tconfig: { tools: [{ functionDeclarations: functions }] },\n\t\t});\n\n\t\treturn await this.createGeminiStreamAdapter(stream);\n\t}\n\n\t// NOTE(yoojin): Need to switch API Stream type to LLMStream.\n\tprivate createGeminiStreamAdapter(\n\t\tgeminiStream: AsyncIterable<GenerateContentResponse>,\n\t): LLMStream {\n\t\tconst hasName = (\n\t\t\tvalue: FunctionCall,\n\t\t): value is FunctionCall & { name: string } => {\n\t\t\treturn value.name !== undefined;\n\t\t};\n\n\t\treturn {\n\t\t\tasync *[Symbol.asyncIterator](): AsyncIterator<StreamChunk> {\n\t\t\t\tfor await (const geminiChunk of geminiStream) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\tdelta: {\n\t\t\t\t\t\t\trole: geminiChunk.candidates?.[0]?.content?.role,\n\t\t\t\t\t\t\tcontent:\n\t\t\t\t\t\t\t\tgeminiChunk.candidates?.[0]?.content?.parts?.[0]?.text ||\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\ttool_calls: hasName(\n\t\t\t\t\t\t\t\tgeminiChunk.candidates?.[0]?.content?.parts?.[0]\n\t\t\t\t\t\t\t\t\t?.functionCall || {},\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t? ([\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\t\t\t\t\tid:\n\t\t\t\t\t\t\t\t\t\t\t\tgeminiChunk.candidates?.[0]?.content?.parts?.[0]\n\t\t\t\t\t\t\t\t\t\t\t\t\t?.functionCall?.id || \"id\",\n\t\t\t\t\t\t\t\t\t\t\tfunction: {\n\t\t\t\t\t\t\t\t\t\t\t\tname: geminiChunk.candidates?.[0]?.content?.parts?.[0]\n\t\t\t\t\t\t\t\t\t\t\t\t\t?.functionCall?.name,\n\t\t\t\t\t\t\t\t\t\t\t\targuments:\n JSON.stringify(geminiChunk.candidates?.[0]?.content?.parts?.[0]\n ?.functionCall?.args),\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tfinish_reason: geminiChunk.candidates?.[0]?.finishReason as any,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tprovider: \"gemini\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tconvertToolsToFunctions(tools: ConnectorTool[]): FunctionDeclaration[] {\n\t\tconst functions: FunctionDeclaration[] = [];\n\t\tfor (const tool of tools) {\n\t\t\tfunctions.push({\n\t\t\t\tname: tool.toolName,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tparametersJsonSchema: tool.inputSchema,\n\t\t\t});\n\t\t}\n\t\treturn functions;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0B;AAC1B,oBAA8D;AAU9D,mBAMO;AAEA,IAAM,cAAN,cAA0B,yBAAwC;AAAA,EAChE;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,WAAmB;AAC9C,UAAM;AACN,SAAK,SAAS,IAAI,yBAAY,EAAE,OAAO,CAAC;AACxC,SAAK,YAAY;AAAA,EAClB;AAAA,EAEQ,eAAe,MAAmB;AACzC,YAAQ,MAAM;AAAA,MACb,KAAK,0BAAY;AAChB,eAAO;AAAA,MACR,KAAK,0BAAY;AAAA,MACjB,KAAK,0BAAY;AAChB,eAAO;AAAA,MACR;AACC,eAAO;AAAA,IACT;AAAA,EACD;AAAA,EAEA,iBAAiB,QAIH;AACb,UAAM,EAAE,OAAO,QAAQ,aAAa,IAAI;AACxC,UAAM,WAAsB,CAAC,eAC1B,CAAC,IACD,CAAC,EAAE,MAAM,SAAS,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AC,GAAG;AAAA,YAC5C,UAAU;AAAA,cACT,UAAU;AAAA,YACX;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,wBAAwB,OAA+C;AACtE,UAAM,YAAmC,CAAC;AAC1C,eAAW,QAAQ,OAAO;AACzB,gBAAU,KAAK;AAAA,QACd,MAAM,KAAK;AAAA,QACX,aAAa,KAAK;AAAA,QAClB,sBAAsB,KAAK;AAAA,MAC5B,CAAC;AAAA,IACF;AACA,WAAO;AAAA,EACR;AACD;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseModel } from '@ainetwork/adk/modules';
|
|
2
2
|
import { ThreadObject } from '@ainetwork/adk/types/memory';
|
|
3
3
|
import { LLMStream } from '@ainetwork/adk/types/stream';
|
|
4
|
-
import { FetchResponse,
|
|
4
|
+
import { FetchResponse, ConnectorTool } from '@ainetwork/adk/types/connector';
|
|
5
5
|
import { Content, FunctionDeclaration } from '@google/genai';
|
|
6
6
|
|
|
7
7
|
declare class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
@@ -19,7 +19,7 @@ declare class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
19
19
|
fetchWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<FetchResponse>;
|
|
20
20
|
fetchStreamWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<LLMStream>;
|
|
21
21
|
private createGeminiStreamAdapter;
|
|
22
|
-
convertToolsToFunctions(tools:
|
|
22
|
+
convertToolsToFunctions(tools: ConnectorTool[]): FunctionDeclaration[];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export { GeminiModel };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseModel } from '@ainetwork/adk/modules';
|
|
2
2
|
import { ThreadObject } from '@ainetwork/adk/types/memory';
|
|
3
3
|
import { LLMStream } from '@ainetwork/adk/types/stream';
|
|
4
|
-
import { FetchResponse,
|
|
4
|
+
import { FetchResponse, ConnectorTool } from '@ainetwork/adk/types/connector';
|
|
5
5
|
import { Content, FunctionDeclaration } from '@google/genai';
|
|
6
6
|
|
|
7
7
|
declare class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
@@ -19,7 +19,7 @@ declare class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
19
19
|
fetchWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<FetchResponse>;
|
|
20
20
|
fetchStreamWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<LLMStream>;
|
|
21
21
|
private createGeminiStreamAdapter;
|
|
22
|
-
convertToolsToFunctions(tools:
|
|
22
|
+
convertToolsToFunctions(tools: ConnectorTool[]): FunctionDeclaration[];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export { GeminiModel };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// index.ts
|
|
2
2
|
import { BaseModel } from "@ainetwork/adk/modules";
|
|
3
3
|
import { MessageRole } from "@ainetwork/adk/types/memory";
|
|
4
|
-
import { TOOL_PROTOCOL_TYPE } from "@ainetwork/adk/types/tool";
|
|
5
4
|
import {
|
|
6
5
|
GoogleGenAI
|
|
7
6
|
} from "@google/genai";
|
|
@@ -120,23 +119,11 @@ var GeminiModel = class extends BaseModel {
|
|
|
120
119
|
convertToolsToFunctions(tools) {
|
|
121
120
|
const functions = [];
|
|
122
121
|
for (const tool of tools) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
functions.push({
|
|
129
|
-
name: id,
|
|
130
|
-
description: mcpTool.description,
|
|
131
|
-
parametersJsonSchema: mcpTool.inputSchema
|
|
132
|
-
});
|
|
133
|
-
} else {
|
|
134
|
-
const { id, card } = tool;
|
|
135
|
-
functions.push({
|
|
136
|
-
name: id,
|
|
137
|
-
description: card.description
|
|
138
|
-
});
|
|
139
|
-
}
|
|
122
|
+
functions.push({
|
|
123
|
+
name: tool.toolName,
|
|
124
|
+
description: tool.description,
|
|
125
|
+
parametersJsonSchema: tool.inputSchema
|
|
126
|
+
});
|
|
140
127
|
}
|
|
141
128
|
return functions;
|
|
142
129
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { BaseModel } from \"@ainetwork/adk/modules\";\nimport { MessageObject, MessageRole, type ThreadObject } from \"@ainetwork/adk/types/memory\";\nimport type {\n\tLLMStream,\n\tStreamChunk,\n} from \"@ainetwork/adk/types/stream\";\nimport type {\n\tFetchResponse,\n\
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { BaseModel } from \"@ainetwork/adk/modules\";\nimport { MessageObject, MessageRole, type ThreadObject } from \"@ainetwork/adk/types/memory\";\nimport type {\n\tLLMStream,\n\tStreamChunk,\n} from \"@ainetwork/adk/types/stream\";\nimport type {\n\tFetchResponse,\n\tToolCall,\n\tConnectorTool,\n} from \"@ainetwork/adk/types/connector\";\nimport {\n\ttype Content,\n\ttype FunctionCall,\n\ttype FunctionDeclaration,\n\ttype GenerateContentResponse,\n\tGoogleGenAI,\n} from \"@google/genai\";\n\nexport class GeminiModel extends BaseModel<Content, FunctionDeclaration> {\n\tprivate client: GoogleGenAI;\n\tprivate modelName: string;\n\n\tconstructor(apiKey: string, modelName: string) {\n\t\tsuper();\n\t\tthis.client = new GoogleGenAI({ apiKey });\n\t\tthis.modelName = modelName;\n\t}\n\n\tprivate getMessageRole(role: MessageRole) {\n\t\tswitch (role) {\n\t\t\tcase MessageRole.USER:\n\t\t\t\treturn \"user\";\n\t\t\tcase MessageRole.MODEL:\n\t\t\tcase MessageRole.SYSTEM:\n\t\t\t\treturn \"model\";\n\t\t\tdefault:\n\t\t\t\treturn \"model\"; /*FIXME*/\n\t\t}\n\t}\n\n\tgenerateMessages(params: {\n\t\tquery: string;\n\t\tthread?: ThreadObject;\n\t\tsystemPrompt?: string;\n\t}): Content[] {\n\t\tconst { query, thread, systemPrompt } = params;\n\t\tconst messages: Content[] = !systemPrompt\n\t\t\t? []\n\t\t\t: [{ role: \"model\", parts: [{ text: systemPrompt.trim() }] }];\n\t\tconst sessionContent: Content[] = !thread\n\t\t\t? []\n\t\t\t: thread.messages.map((message: MessageObject) => {\n\t\t\t\t\t// TODO: check message.content.type\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: this.getMessageRole(message.role),\n\t\t\t\t\t\tparts: [{ text: message.content.parts[0] }],\n\t\t\t\t\t};\n\t\t\t\t});\n\t\tconst userContent: Content = { role: \"user\", parts: [{ text: query }] };\n\t\treturn messages.concat(sessionContent).concat(userContent);\n\t}\n\n\tappendMessages(messages: Content[], message: string): void {\n\t\tmessages.push({\n\t\t\trole: \"user\",\n\t\t\tparts: [{ text: message }],\n\t\t});\n\t}\n\n\tasync fetch(messages: Content[]): Promise<FetchResponse> {\n\t\tconst response = await this.client.models.generateContent({\n\t\t\tmodel: this.modelName,\n\t\t\tcontents: messages,\n\t\t});\n\n\t\treturn { content: response.text };\n\t}\n\n\tasync fetchWithContextMessage(\n\t\tmessages: Content[],\n\t\tfunctions: FunctionDeclaration[],\n\t): Promise<FetchResponse> {\n\t\tif (functions.length > 0) {\n\t\t\tconst response = await this.client.models.generateContent({\n\t\t\t\tmodel: this.modelName,\n\t\t\t\tcontents: messages,\n\t\t\t\tconfig: {\n\t\t\t\t\ttools: [{ functionDeclarations: functions }],\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst { text, functionCalls } = response;\n\t\t\tconst hasName = (\n\t\t\t\tvalue: FunctionCall,\n\t\t\t): value is FunctionCall & { name: string } => {\n\t\t\t\treturn value.name !== undefined;\n\t\t\t};\n\t\t\tconst toolCalls: ToolCall[] | undefined = functionCalls\n\t\t\t\t?.filter(hasName)\n\t\t\t\t.map((value) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tname: value.name,\n\t\t\t\t\t\targuments: value.args,\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\treturn {\n\t\t\t\tcontent: text,\n\t\t\t\ttoolCalls,\n\t\t\t};\n\t\t}\n\t\treturn await this.fetch(messages);\n\t}\n\n\tasync fetchStreamWithContextMessage(\n\t\tmessages: Content[],\n\t\tfunctions: FunctionDeclaration[],\n\t): Promise<LLMStream> {\n\t\tconst stream = await this.client.models.generateContentStream({\n\t\t\tmodel: this.modelName,\n\t\t\tcontents: messages,\n\t\t\tconfig: { tools: [{ functionDeclarations: functions }] },\n\t\t});\n\n\t\treturn await this.createGeminiStreamAdapter(stream);\n\t}\n\n\t// NOTE(yoojin): Need to switch API Stream type to LLMStream.\n\tprivate createGeminiStreamAdapter(\n\t\tgeminiStream: AsyncIterable<GenerateContentResponse>,\n\t): LLMStream {\n\t\tconst hasName = (\n\t\t\tvalue: FunctionCall,\n\t\t): value is FunctionCall & { name: string } => {\n\t\t\treturn value.name !== undefined;\n\t\t};\n\n\t\treturn {\n\t\t\tasync *[Symbol.asyncIterator](): AsyncIterator<StreamChunk> {\n\t\t\t\tfor await (const geminiChunk of geminiStream) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\tdelta: {\n\t\t\t\t\t\t\trole: geminiChunk.candidates?.[0]?.content?.role,\n\t\t\t\t\t\t\tcontent:\n\t\t\t\t\t\t\t\tgeminiChunk.candidates?.[0]?.content?.parts?.[0]?.text ||\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\ttool_calls: hasName(\n\t\t\t\t\t\t\t\tgeminiChunk.candidates?.[0]?.content?.parts?.[0]\n\t\t\t\t\t\t\t\t\t?.functionCall || {},\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t? ([\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tindex: 0,\n\t\t\t\t\t\t\t\t\t\t\tid:\n\t\t\t\t\t\t\t\t\t\t\t\tgeminiChunk.candidates?.[0]?.content?.parts?.[0]\n\t\t\t\t\t\t\t\t\t\t\t\t\t?.functionCall?.id || \"id\",\n\t\t\t\t\t\t\t\t\t\t\tfunction: {\n\t\t\t\t\t\t\t\t\t\t\t\tname: geminiChunk.candidates?.[0]?.content?.parts?.[0]\n\t\t\t\t\t\t\t\t\t\t\t\t\t?.functionCall?.name,\n\t\t\t\t\t\t\t\t\t\t\t\targuments:\n JSON.stringify(geminiChunk.candidates?.[0]?.content?.parts?.[0]\n ?.functionCall?.args),\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tfinish_reason: geminiChunk.candidates?.[0]?.finishReason as any,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tprovider: \"gemini\",\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tconvertToolsToFunctions(tools: ConnectorTool[]): FunctionDeclaration[] {\n\t\tconst functions: FunctionDeclaration[] = [];\n\t\tfor (const tool of tools) {\n\t\t\tfunctions.push({\n\t\t\t\tname: tool.toolName,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tparametersJsonSchema: tool.inputSchema,\n\t\t\t});\n\t\t}\n\t\treturn functions;\n\t}\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAwB,mBAAsC;AAU9D;AAAA,EAKC;AAAA,OACM;AAEA,IAAM,cAAN,cAA0B,UAAwC;AAAA,EAChE;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,WAAmB;AAC9C,UAAM;AACN,SAAK,SAAS,IAAI,YAAY,EAAE,OAAO,CAAC;AACxC,SAAK,YAAY;AAAA,EAClB;AAAA,EAEQ,eAAe,MAAmB;AACzC,YAAQ,MAAM;AAAA,MACb,KAAK,YAAY;AAChB,eAAO;AAAA,MACR,KAAK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a,CAAC,GAAG,SAAS,QAAQ,CAAC,GAClD,cAAc;AAAA,oBACjB,WACc,KAAK,UAAU,YAAY,aAAa,CAAC,GAAG,SAAS,QAAQ,CAAC,GAC1D,cAAc,IAAI;AAAA,kBACrC;AAAA,gBACD;AAAA,cACD,IACC;AAAA,YACJ;AAAA,YACA,eAAe,YAAY,aAAa,CAAC,GAAG;AAAA,YAC5C,UAAU;AAAA,cACT,UAAU;AAAA,YACX;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEA,wBAAwB,OAA+C;AACtE,UAAM,YAAmC,CAAC;AAC1C,eAAW,QAAQ,OAAO;AACzB,gBAAU,KAAK;AAAA,QACd,MAAM,KAAK;AAAA,QACX,aAAa,KAAK;AAAA,QAClB,sBAAsB,KAAK;AAAA,MAC5B,CAAC;AAAA,IACF;AACA,WAAO;AAAA,EACR;AACD;","names":[]}
|
package/index.ts
CHANGED
|
@@ -6,12 +6,9 @@ import type {
|
|
|
6
6
|
} from "@ainetwork/adk/types/stream";
|
|
7
7
|
import type {
|
|
8
8
|
FetchResponse,
|
|
9
|
-
IA2ATool,
|
|
10
|
-
IAgentTool,
|
|
11
|
-
IMCPTool,
|
|
12
9
|
ToolCall,
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
ConnectorTool,
|
|
11
|
+
} from "@ainetwork/adk/types/connector";
|
|
15
12
|
import {
|
|
16
13
|
type Content,
|
|
17
14
|
type FunctionCall,
|
|
@@ -179,27 +176,14 @@ export class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
179
176
|
};
|
|
180
177
|
}
|
|
181
178
|
|
|
182
|
-
convertToolsToFunctions(tools:
|
|
179
|
+
convertToolsToFunctions(tools: ConnectorTool[]): FunctionDeclaration[] {
|
|
183
180
|
const functions: FunctionDeclaration[] = [];
|
|
184
181
|
for (const tool of tools) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
functions.push({
|
|
191
|
-
name: id,
|
|
192
|
-
description: mcpTool.description,
|
|
193
|
-
parametersJsonSchema: mcpTool.inputSchema,
|
|
194
|
-
});
|
|
195
|
-
} else {
|
|
196
|
-
// PROTOCOL_TYPE.A2A
|
|
197
|
-
const { id, card } = tool as IA2ATool;
|
|
198
|
-
functions.push({
|
|
199
|
-
name: id,
|
|
200
|
-
description: card.description,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
182
|
+
functions.push({
|
|
183
|
+
name: tool.toolName,
|
|
184
|
+
description: tool.description,
|
|
185
|
+
parametersJsonSchema: tool.inputSchema,
|
|
186
|
+
});
|
|
203
187
|
}
|
|
204
188
|
return functions;
|
|
205
189
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainetwork/adk-provider-model-gemini",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"author": "AI Network (https://ainetwork.ai)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"clean": "rm -rf dist"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@ainetwork/adk": "
|
|
24
|
+
"@ainetwork/adk": "0.2.9",
|
|
25
25
|
"@google/genai": "^1.11.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "da5af7747935eeb8cedeb932cb2e918da6dc36c3"
|
|
35
35
|
}
|