@aigne/gemini 0.1.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/CHANGELOG.md +18 -0
- package/LICENSE.md +93 -0
- package/README.md +110 -0
- package/README.zh.md +110 -0
- package/lib/cjs/gemini-chat-model.d.ts +23 -0
- package/lib/cjs/gemini-chat-model.js +35 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +17 -0
- package/lib/cjs/package.json +1 -0
- package/lib/dts/gemini-chat-model.d.ts +23 -0
- package/lib/dts/index.d.ts +1 -0
- package/lib/esm/gemini-chat-model.d.ts +23 -0
- package/lib/esm/gemini-chat-model.js +31 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/package.json +1 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0](https://github.com/AIGNE-io/aigne-framework/compare/gemini-v0.0.1...gemini-v0.1.0) (2025-05-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **models:** publish model adapters as standalone packages ([#126](https://github.com/AIGNE-io/aigne-framework/issues/126)) ([588b8ae](https://github.com/AIGNE-io/aigne-framework/commit/588b8aea6abcee5fa87def1358bf51f84021c6ef))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @aigne/openai bumped to 0.1.0
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @aigne/core bumped to 1.16.0
|
|
18
|
+
* @aigne/test-utils bumped to 0.3.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
21
|
+
|
|
22
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
+
software that is protected by the license key.
|
|
25
|
+
|
|
26
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
+
to applicable law.
|
|
29
|
+
|
|
30
|
+
## Patents
|
|
31
|
+
|
|
32
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
+
sale, import and have imported the software, in each case subject to the
|
|
35
|
+
limitations and conditions in this license. This license does not cover any
|
|
36
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
+
the software. If you or your company make any written claim that the software
|
|
38
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
+
the software granted under these terms ends immediately. If your company makes
|
|
40
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
+
company.
|
|
42
|
+
|
|
43
|
+
## Notices
|
|
44
|
+
|
|
45
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
+
also gets a copy of these terms.
|
|
47
|
+
|
|
48
|
+
If you modify the software, you must include in any modified copies of the
|
|
49
|
+
software prominent notices stating that you have modified the software.
|
|
50
|
+
|
|
51
|
+
## No Other Rights
|
|
52
|
+
|
|
53
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
+
these terms.
|
|
55
|
+
|
|
56
|
+
## Termination
|
|
57
|
+
|
|
58
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
+
to terminate automatically and permanently.
|
|
65
|
+
|
|
66
|
+
## No Liability
|
|
67
|
+
|
|
68
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
+
legal claim.*
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
+
software the licensor makes available under these terms, including any portion
|
|
77
|
+
of it.
|
|
78
|
+
|
|
79
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
+
organization that you work for, plus all organizations that have control over,
|
|
83
|
+
are under the control of, or are under common control with that
|
|
84
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
+
otherwise. Control can be direct or indirect.
|
|
87
|
+
|
|
88
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
+
these terms.
|
|
90
|
+
|
|
91
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
+
|
|
93
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @aigne/gemini
|
|
2
|
+
|
|
3
|
+
[](https://star-history.com/#AIGNE-io/aigne-framework)
|
|
4
|
+
[](https://github.com/AIGNE-io/aigne-framework/issues)
|
|
5
|
+
[](https://codecov.io/gh/AIGNE-io/aigne-framework)
|
|
6
|
+
[](https://www.npmjs.com/package/@aigne/gemini)
|
|
7
|
+
[](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE.md)
|
|
8
|
+
|
|
9
|
+
**English** | [中文](README.zh.md)
|
|
10
|
+
|
|
11
|
+
AIGNE Gemini SDK for integrating with Google's Gemini AI models within the [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework).
|
|
12
|
+
|
|
13
|
+
## Introduction
|
|
14
|
+
|
|
15
|
+
`@aigne/gemini` provides a seamless integration between the AIGNE Framework and Google's Gemini language models and API. This package enables developers to easily leverage Gemini's advanced AI capabilities in their AIGNE applications, providing a consistent interface across the framework while taking advantage of Google's state-of-the-art multimodal models.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
* **Google Gemini API Integration**: Direct connection to Google's Gemini API services
|
|
20
|
+
* **Chat Completions**: Support for Gemini's chat completions API with all available models
|
|
21
|
+
* **Multimodal Support**: Built-in support for handling both text and image inputs
|
|
22
|
+
* **Function Calling**: Support for function calling capabilities
|
|
23
|
+
* **Streaming Responses**: Support for streaming responses for more responsive applications
|
|
24
|
+
* **Type-Safe**: Comprehensive TypeScript typings for all APIs and models
|
|
25
|
+
* **Consistent Interface**: Compatible with the AIGNE Framework's model interface
|
|
26
|
+
* **Error Handling**: Robust error handling and retry mechanisms
|
|
27
|
+
* **Full Configuration**: Extensive configuration options for fine-tuning behavior
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
### Using npm
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @aigne/gemini @aigne/core
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Using yarn
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
yarn add @aigne/gemini @aigne/core
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Using pnpm
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm add @aigne/gemini @aigne/core
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Basic Usage
|
|
50
|
+
|
|
51
|
+
```typescript file="test/gemini-chat-model.test.ts" region="example-gemini-chat-model"
|
|
52
|
+
import { GeminiChatModel } from "@aigne/gemini";
|
|
53
|
+
|
|
54
|
+
const model = new GeminiChatModel({
|
|
55
|
+
// Provide API key directly or use environment variable GOOGLE_API_KEY
|
|
56
|
+
apiKey: "your-api-key", // Optional if set in env variables
|
|
57
|
+
// Specify Gemini model version (defaults to 'gemini-1.5-pro' if not specified)
|
|
58
|
+
model: "gemini-1.5-flash",
|
|
59
|
+
modelOptions: {
|
|
60
|
+
temperature: 0.7,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const result = await model.invoke({
|
|
65
|
+
messages: [{ role: "user", content: "Hi there, introduce yourself" }],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log(result);
|
|
69
|
+
/* Output:
|
|
70
|
+
{
|
|
71
|
+
text: "Hello from Gemini! I'm Google's helpful AI assistant. How can I assist you today?",
|
|
72
|
+
model: "gemini-1.5-flash"
|
|
73
|
+
}
|
|
74
|
+
*/
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Streaming Responses
|
|
78
|
+
|
|
79
|
+
```typescript file="test/gemini-chat-model.test.ts" region="example-gemini-chat-model-streaming"
|
|
80
|
+
import { GeminiChatModel } from "@aigne/gemini";
|
|
81
|
+
|
|
82
|
+
const model = new GeminiChatModel({
|
|
83
|
+
apiKey: "your-api-key",
|
|
84
|
+
model: "gemini-1.5-flash",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const stream = await model.invoke(
|
|
88
|
+
{
|
|
89
|
+
messages: [{ role: "user", content: "Hi there, introduce yourself" }],
|
|
90
|
+
},
|
|
91
|
+
undefined,
|
|
92
|
+
{ streaming: true },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
let fullText = "";
|
|
96
|
+
const json = {};
|
|
97
|
+
|
|
98
|
+
for await (const chunk of stream) {
|
|
99
|
+
const text = chunk.delta.text?.text;
|
|
100
|
+
if (text) fullText += text;
|
|
101
|
+
if (chunk.delta.json) Object.assign(json, chunk.delta.json);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(fullText); // Output: "Hello from Gemini! I'm Google's helpful AI assistant. How can I assist you today?"
|
|
105
|
+
console.log(json); // { model: "gemini-1.5-flash" }
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
Elastic-2.0
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @aigne/gemini
|
|
2
|
+
|
|
3
|
+
[](https://star-history.com/#AIGNE-io/aigne-framework)
|
|
4
|
+
[](https://github.com/AIGNE-io/aigne-framework/issues)
|
|
5
|
+
[](https://codecov.io/gh/AIGNE-io/aigne-framework)
|
|
6
|
+
[](https://www.npmjs.com/package/@aigne/gemini)
|
|
7
|
+
[](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE.md)
|
|
8
|
+
|
|
9
|
+
[English](README.md) | **中文**
|
|
10
|
+
|
|
11
|
+
AIGNE Gemini SDK,用于在 [AIGNE 框架](https://github.com/AIGNE-io/aigne-framework) 中集成 Google 的 Gemini AI 模型。
|
|
12
|
+
|
|
13
|
+
## 简介
|
|
14
|
+
|
|
15
|
+
`@aigne/gemini` 提供了 AIGNE 框架与 Google 的 Gemini 语言模型和 API 之间的无缝集成。该包使开发者能够在 AIGNE 应用程序中轻松利用 Gemini 的先进 AI 能力,同时提供框架内一致的接口,充分发挥 Google 最先进的多模态模型优势。
|
|
16
|
+
|
|
17
|
+
## 特性
|
|
18
|
+
|
|
19
|
+
* **Google Gemini API 集成**:直接连接到 Google 的 Gemini API 服务
|
|
20
|
+
* **聊天完成**:支持 Gemini 的聊天完成 API 和所有可用模型
|
|
21
|
+
* **多模态支持**:内置支持处理文本和图像输入
|
|
22
|
+
* **函数调用**:支持函数调用功能
|
|
23
|
+
* **流式响应**:支持流式响应,提供更高响应性的应用程序体验
|
|
24
|
+
* **类型安全**:为所有 API 和模型提供全面的 TypeScript 类型定义
|
|
25
|
+
* **一致接口**:兼容 AIGNE 框架的模型接口
|
|
26
|
+
* **错误处理**:健壮的错误处理和重试机制
|
|
27
|
+
* **完整配置**:丰富的配置选项用于微调行为
|
|
28
|
+
|
|
29
|
+
## 安装
|
|
30
|
+
|
|
31
|
+
### 使用 npm
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @aigne/gemini @aigne/core
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 使用 yarn
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
yarn add @aigne/gemini @aigne/core
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 使用 pnpm
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm add @aigne/gemini @aigne/core
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 基本用法
|
|
50
|
+
|
|
51
|
+
```typescript file="test/gemini-chat-model.test.ts" region="example-gemini-chat-model"
|
|
52
|
+
import { GeminiChatModel } from "@aigne/gemini";
|
|
53
|
+
|
|
54
|
+
const model = new GeminiChatModel({
|
|
55
|
+
// Provide API key directly or use environment variable GOOGLE_API_KEY
|
|
56
|
+
apiKey: "your-api-key", // Optional if set in env variables
|
|
57
|
+
// Specify Gemini model version (defaults to 'gemini-1.5-pro' if not specified)
|
|
58
|
+
model: "gemini-1.5-flash",
|
|
59
|
+
modelOptions: {
|
|
60
|
+
temperature: 0.7,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const result = await model.invoke({
|
|
65
|
+
messages: [{ role: "user", content: "Hi there, introduce yourself" }],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log(result);
|
|
69
|
+
/* Output:
|
|
70
|
+
{
|
|
71
|
+
text: "Hello from Gemini! I'm Google's helpful AI assistant. How can I assist you today?",
|
|
72
|
+
model: "gemini-1.5-flash"
|
|
73
|
+
}
|
|
74
|
+
*/
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 流式响应
|
|
78
|
+
|
|
79
|
+
```typescript file="test/gemini-chat-model.test.ts" region="example-gemini-chat-model-streaming"
|
|
80
|
+
import { GeminiChatModel } from "@aigne/gemini";
|
|
81
|
+
|
|
82
|
+
const model = new GeminiChatModel({
|
|
83
|
+
apiKey: "your-api-key",
|
|
84
|
+
model: "gemini-1.5-flash",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const stream = await model.invoke(
|
|
88
|
+
{
|
|
89
|
+
messages: [{ role: "user", content: "Hi there, introduce yourself" }],
|
|
90
|
+
},
|
|
91
|
+
undefined,
|
|
92
|
+
{ streaming: true },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
let fullText = "";
|
|
96
|
+
const json = {};
|
|
97
|
+
|
|
98
|
+
for await (const chunk of stream) {
|
|
99
|
+
const text = chunk.delta.text?.text;
|
|
100
|
+
if (text) fullText += text;
|
|
101
|
+
if (chunk.delta.json) Object.assign(json, chunk.delta.json);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(fullText); // Output: "Hello from Gemini! I'm Google's helpful AI assistant. How can I assist you today?"
|
|
105
|
+
console.log(json); // { model: "gemini-1.5-flash" }
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## 许可证
|
|
109
|
+
|
|
110
|
+
Elastic-2.0
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of the ChatModel interface for Google's Gemini API
|
|
4
|
+
*
|
|
5
|
+
* This model uses OpenAI-compatible API format to interact with Google's Gemini models,
|
|
6
|
+
* providing access to models like Gemini 1.5 and Gemini 2.0.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* Here's how to create and use a Gemini chat model:
|
|
10
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model}
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* Here's an example with streaming response:
|
|
14
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model-streaming}
|
|
15
|
+
*/
|
|
16
|
+
export declare class GeminiChatModel extends OpenAIChatModel {
|
|
17
|
+
constructor(options?: OpenAIChatModelOptions);
|
|
18
|
+
protected apiKeyEnvName: string;
|
|
19
|
+
protected supportsEndWithSystemMessage: boolean;
|
|
20
|
+
protected supportsToolsUseWithJsonSchema: boolean;
|
|
21
|
+
protected supportsParallelToolCalls: boolean;
|
|
22
|
+
protected supportsToolStreaming: boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeminiChatModel = void 0;
|
|
4
|
+
const openai_1 = require("@aigne/openai");
|
|
5
|
+
const GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/openai";
|
|
6
|
+
const GEMINI_DEFAULT_CHAT_MODEL = "gemini-2.0-flash";
|
|
7
|
+
/**
|
|
8
|
+
* Implementation of the ChatModel interface for Google's Gemini API
|
|
9
|
+
*
|
|
10
|
+
* This model uses OpenAI-compatible API format to interact with Google's Gemini models,
|
|
11
|
+
* providing access to models like Gemini 1.5 and Gemini 2.0.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* Here's how to create and use a Gemini chat model:
|
|
15
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model}
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* Here's an example with streaming response:
|
|
19
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model-streaming}
|
|
20
|
+
*/
|
|
21
|
+
class GeminiChatModel extends openai_1.OpenAIChatModel {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super({
|
|
24
|
+
...options,
|
|
25
|
+
model: options?.model || GEMINI_DEFAULT_CHAT_MODEL,
|
|
26
|
+
baseURL: options?.baseURL || GEMINI_BASE_URL,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
apiKeyEnvName = "GEMINI_API_KEY";
|
|
30
|
+
supportsEndWithSystemMessage = false;
|
|
31
|
+
supportsToolsUseWithJsonSchema = false;
|
|
32
|
+
supportsParallelToolCalls = false;
|
|
33
|
+
supportsToolStreaming = false;
|
|
34
|
+
}
|
|
35
|
+
exports.GeminiChatModel = GeminiChatModel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./gemini-chat-model.js";
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./gemini-chat-model.js"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of the ChatModel interface for Google's Gemini API
|
|
4
|
+
*
|
|
5
|
+
* This model uses OpenAI-compatible API format to interact with Google's Gemini models,
|
|
6
|
+
* providing access to models like Gemini 1.5 and Gemini 2.0.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* Here's how to create and use a Gemini chat model:
|
|
10
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model}
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* Here's an example with streaming response:
|
|
14
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model-streaming}
|
|
15
|
+
*/
|
|
16
|
+
export declare class GeminiChatModel extends OpenAIChatModel {
|
|
17
|
+
constructor(options?: OpenAIChatModelOptions);
|
|
18
|
+
protected apiKeyEnvName: string;
|
|
19
|
+
protected supportsEndWithSystemMessage: boolean;
|
|
20
|
+
protected supportsToolsUseWithJsonSchema: boolean;
|
|
21
|
+
protected supportsParallelToolCalls: boolean;
|
|
22
|
+
protected supportsToolStreaming: boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./gemini-chat-model.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
|
|
2
|
+
/**
|
|
3
|
+
* Implementation of the ChatModel interface for Google's Gemini API
|
|
4
|
+
*
|
|
5
|
+
* This model uses OpenAI-compatible API format to interact with Google's Gemini models,
|
|
6
|
+
* providing access to models like Gemini 1.5 and Gemini 2.0.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* Here's how to create and use a Gemini chat model:
|
|
10
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model}
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* Here's an example with streaming response:
|
|
14
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model-streaming}
|
|
15
|
+
*/
|
|
16
|
+
export declare class GeminiChatModel extends OpenAIChatModel {
|
|
17
|
+
constructor(options?: OpenAIChatModelOptions);
|
|
18
|
+
protected apiKeyEnvName: string;
|
|
19
|
+
protected supportsEndWithSystemMessage: boolean;
|
|
20
|
+
protected supportsToolsUseWithJsonSchema: boolean;
|
|
21
|
+
protected supportsParallelToolCalls: boolean;
|
|
22
|
+
protected supportsToolStreaming: boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OpenAIChatModel } from "@aigne/openai";
|
|
2
|
+
const GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/openai";
|
|
3
|
+
const GEMINI_DEFAULT_CHAT_MODEL = "gemini-2.0-flash";
|
|
4
|
+
/**
|
|
5
|
+
* Implementation of the ChatModel interface for Google's Gemini API
|
|
6
|
+
*
|
|
7
|
+
* This model uses OpenAI-compatible API format to interact with Google's Gemini models,
|
|
8
|
+
* providing access to models like Gemini 1.5 and Gemini 2.0.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* Here's how to create and use a Gemini chat model:
|
|
12
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model}
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* Here's an example with streaming response:
|
|
16
|
+
* {@includeCode ../test/gemini-chat-model.test.ts#example-gemini-chat-model-streaming}
|
|
17
|
+
*/
|
|
18
|
+
export class GeminiChatModel extends OpenAIChatModel {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super({
|
|
21
|
+
...options,
|
|
22
|
+
model: options?.model || GEMINI_DEFAULT_CHAT_MODEL,
|
|
23
|
+
baseURL: options?.baseURL || GEMINI_BASE_URL,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
apiKeyEnvName = "GEMINI_API_KEY";
|
|
27
|
+
supportsEndWithSystemMessage = false;
|
|
28
|
+
supportsToolsUseWithJsonSchema = false;
|
|
29
|
+
supportsParallelToolCalls = false;
|
|
30
|
+
supportsToolStreaming = false;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./gemini-chat-model.js";
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./gemini-chat-model.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aigne/gemini",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AIGNE Gemini SDK for integrating with Google's Gemini AI models",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
9
|
+
"homepage": "https://github.com/AIGNE-io/aigne-framework",
|
|
10
|
+
"license": "Elastic-2.0",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/AIGNE-io/aigne-framework"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib/cjs",
|
|
17
|
+
"lib/dts",
|
|
18
|
+
"lib/esm",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"README.md",
|
|
21
|
+
"CHANGELOG.md"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./lib/cjs/index.js",
|
|
25
|
+
"module": "./lib/esm/index.js",
|
|
26
|
+
"types": "./lib/dts/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./lib/esm/index.js",
|
|
30
|
+
"require": "./lib/cjs/index.js",
|
|
31
|
+
"types": "./lib/dts/index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@aigne/openai": "^0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/bun": "^1.2.12",
|
|
39
|
+
"@types/node": "^22.15.15",
|
|
40
|
+
"npm-run-all": "^4.1.5",
|
|
41
|
+
"rimraf": "^6.0.1",
|
|
42
|
+
"typescript": "^5.8.3",
|
|
43
|
+
"@aigne/core": "^1.16.0",
|
|
44
|
+
"@aigne/test-utils": "^0.3.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"lint": "tsc --noEmit",
|
|
48
|
+
"build": "tsc --build scripts/tsconfig.build.json",
|
|
49
|
+
"clean": "rimraf lib test/coverage",
|
|
50
|
+
"test": "bun test",
|
|
51
|
+
"test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text",
|
|
52
|
+
"postbuild": "echo '{\"type\": \"module\"}' > lib/esm/package.json && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json"
|
|
53
|
+
}
|
|
54
|
+
}
|