@ainetwork/adk-provider-model-gemini 0.2.3 → 0.3.0
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 +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/index.ts +5 -2
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -63,14 +63,14 @@ var GeminiModel = class extends import_modules.BaseModel {
|
|
|
63
63
|
parts: [{ text: message }]
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
async fetch(messages) {
|
|
66
|
+
async fetch(messages, options) {
|
|
67
67
|
const response = await this.client.models.generateContent({
|
|
68
68
|
model: this.modelName,
|
|
69
69
|
contents: messages
|
|
70
70
|
});
|
|
71
71
|
return { content: response.text };
|
|
72
72
|
}
|
|
73
|
-
async fetchWithContextMessage(messages, functions) {
|
|
73
|
+
async fetchWithContextMessage(messages, functions, options) {
|
|
74
74
|
if (functions.length > 0) {
|
|
75
75
|
const response = await this.client.models.generateContent({
|
|
76
76
|
model: this.modelName,
|
|
@@ -96,7 +96,7 @@ var GeminiModel = class extends import_modules.BaseModel {
|
|
|
96
96
|
}
|
|
97
97
|
return await this.fetch(messages);
|
|
98
98
|
}
|
|
99
|
-
async fetchStreamWithContextMessage(messages, functions) {
|
|
99
|
+
async fetchStreamWithContextMessage(messages, functions, options) {
|
|
100
100
|
const stream = await this.client.models.generateContentStream({
|
|
101
101
|
model: this.modelName,
|
|
102
102
|
contents: messages,
|
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\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,
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { BaseModel, ModelFetchOptions } 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\tModel,\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[], options?: ModelFetchOptions): 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\toptions?: ModelFetchOptions,\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\toptions?: ModelFetchOptions,\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,qBAA6C;AAC7C,oBAA8D;AAU9D,mBAOO;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,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,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/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseModel } from '@ainetwork/adk/modules';
|
|
1
|
+
import { BaseModel, ModelFetchOptions } from '@ainetwork/adk/modules';
|
|
2
2
|
import { ThreadObject } from '@ainetwork/adk/types/memory';
|
|
3
3
|
import { LLMStream } from '@ainetwork/adk/types/stream';
|
|
4
4
|
import { FetchResponse, ConnectorTool } from '@ainetwork/adk/types/connector';
|
|
@@ -15,9 +15,9 @@ declare class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
15
15
|
systemPrompt?: string;
|
|
16
16
|
}): Content[];
|
|
17
17
|
appendMessages(messages: Content[], message: string): void;
|
|
18
|
-
fetch(messages: Content[]): Promise<FetchResponse>;
|
|
19
|
-
fetchWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<FetchResponse>;
|
|
20
|
-
fetchStreamWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<LLMStream>;
|
|
18
|
+
fetch(messages: Content[], options?: ModelFetchOptions): Promise<FetchResponse>;
|
|
19
|
+
fetchWithContextMessage(messages: Content[], functions: FunctionDeclaration[], options?: ModelFetchOptions): Promise<FetchResponse>;
|
|
20
|
+
fetchStreamWithContextMessage(messages: Content[], functions: FunctionDeclaration[], options?: ModelFetchOptions): Promise<LLMStream>;
|
|
21
21
|
private createGeminiStreamAdapter;
|
|
22
22
|
convertToolsToFunctions(tools: ConnectorTool[]): FunctionDeclaration[];
|
|
23
23
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseModel } from '@ainetwork/adk/modules';
|
|
1
|
+
import { BaseModel, ModelFetchOptions } from '@ainetwork/adk/modules';
|
|
2
2
|
import { ThreadObject } from '@ainetwork/adk/types/memory';
|
|
3
3
|
import { LLMStream } from '@ainetwork/adk/types/stream';
|
|
4
4
|
import { FetchResponse, ConnectorTool } from '@ainetwork/adk/types/connector';
|
|
@@ -15,9 +15,9 @@ declare class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
15
15
|
systemPrompt?: string;
|
|
16
16
|
}): Content[];
|
|
17
17
|
appendMessages(messages: Content[], message: string): void;
|
|
18
|
-
fetch(messages: Content[]): Promise<FetchResponse>;
|
|
19
|
-
fetchWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<FetchResponse>;
|
|
20
|
-
fetchStreamWithContextMessage(messages: Content[], functions: FunctionDeclaration[]): Promise<LLMStream>;
|
|
18
|
+
fetch(messages: Content[], options?: ModelFetchOptions): Promise<FetchResponse>;
|
|
19
|
+
fetchWithContextMessage(messages: Content[], functions: FunctionDeclaration[], options?: ModelFetchOptions): Promise<FetchResponse>;
|
|
20
|
+
fetchStreamWithContextMessage(messages: Content[], functions: FunctionDeclaration[], options?: ModelFetchOptions): Promise<LLMStream>;
|
|
21
21
|
private createGeminiStreamAdapter;
|
|
22
22
|
convertToolsToFunctions(tools: ConnectorTool[]): FunctionDeclaration[];
|
|
23
23
|
}
|
package/dist/index.js
CHANGED
|
@@ -41,14 +41,14 @@ var GeminiModel = class extends BaseModel {
|
|
|
41
41
|
parts: [{ text: message }]
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
async fetch(messages) {
|
|
44
|
+
async fetch(messages, options) {
|
|
45
45
|
const response = await this.client.models.generateContent({
|
|
46
46
|
model: this.modelName,
|
|
47
47
|
contents: messages
|
|
48
48
|
});
|
|
49
49
|
return { content: response.text };
|
|
50
50
|
}
|
|
51
|
-
async fetchWithContextMessage(messages, functions) {
|
|
51
|
+
async fetchWithContextMessage(messages, functions, options) {
|
|
52
52
|
if (functions.length > 0) {
|
|
53
53
|
const response = await this.client.models.generateContent({
|
|
54
54
|
model: this.modelName,
|
|
@@ -74,7 +74,7 @@ var GeminiModel = class extends BaseModel {
|
|
|
74
74
|
}
|
|
75
75
|
return await this.fetch(messages);
|
|
76
76
|
}
|
|
77
|
-
async fetchStreamWithContextMessage(messages, functions) {
|
|
77
|
+
async fetchStreamWithContextMessage(messages, functions, options) {
|
|
78
78
|
const stream = await this.client.models.generateContentStream({
|
|
79
79
|
model: this.modelName,
|
|
80
80
|
contents: messages,
|
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\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,
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { BaseModel, ModelFetchOptions } 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\tModel,\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[], options?: ModelFetchOptions): 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\toptions?: ModelFetchOptions,\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\toptions?: ModelFetchOptions,\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,iBAAoC;AAC7C,SAAwB,mBAAsC;AAU9D;AAAA,EAKC;AAAA,OAEM;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,YAAY;AAAA,MACjB,KAAK,YAAY;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,OAAO,CAAC,EAAE,MAAM,aAAa,KAAK,EAAE,CAAC,EAAE,CAAC;AAC7D,UAAM,iBAA4B,CAAC,SAChC,CAAC,IACD,OAAO,SAAS,IAAI,CAAC,YAA2B;AAEhD,aAAO;AAAA,QACN,MAAM,KAAK,eAAe,QAAQ,IAAI;AAA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AAQ,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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseModel } from "@ainetwork/adk/modules";
|
|
1
|
+
import { BaseModel, ModelFetchOptions } from "@ainetwork/adk/modules";
|
|
2
2
|
import { MessageObject, MessageRole, type ThreadObject } from "@ainetwork/adk/types/memory";
|
|
3
3
|
import type {
|
|
4
4
|
LLMStream,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
type FunctionDeclaration,
|
|
16
16
|
type GenerateContentResponse,
|
|
17
17
|
GoogleGenAI,
|
|
18
|
+
Model,
|
|
18
19
|
} from "@google/genai";
|
|
19
20
|
|
|
20
21
|
export class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
@@ -68,7 +69,7 @@ export class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
68
69
|
});
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
async fetch(messages: Content[]): Promise<FetchResponse> {
|
|
72
|
+
async fetch(messages: Content[], options?: ModelFetchOptions): Promise<FetchResponse> {
|
|
72
73
|
const response = await this.client.models.generateContent({
|
|
73
74
|
model: this.modelName,
|
|
74
75
|
contents: messages,
|
|
@@ -80,6 +81,7 @@ export class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
80
81
|
async fetchWithContextMessage(
|
|
81
82
|
messages: Content[],
|
|
82
83
|
functions: FunctionDeclaration[],
|
|
84
|
+
options?: ModelFetchOptions,
|
|
83
85
|
): Promise<FetchResponse> {
|
|
84
86
|
if (functions.length > 0) {
|
|
85
87
|
const response = await this.client.models.generateContent({
|
|
@@ -116,6 +118,7 @@ export class GeminiModel extends BaseModel<Content, FunctionDeclaration> {
|
|
|
116
118
|
async fetchStreamWithContextMessage(
|
|
117
119
|
messages: Content[],
|
|
118
120
|
functions: FunctionDeclaration[],
|
|
121
|
+
options?: ModelFetchOptions,
|
|
119
122
|
): Promise<LLMStream> {
|
|
120
123
|
const stream = await this.client.models.generateContentStream({
|
|
121
124
|
model: this.modelName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainetwork/adk-provider-model-gemini",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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": "0.
|
|
24
|
+
"@ainetwork/adk": "^0.3.0",
|
|
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": "77a4f8c8bb228f45383eea93f153c21bac3f8b3b"
|
|
35
35
|
}
|