@aigne/doubao 1.0.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 ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2025-07-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * **models:** support doubao llm adapter ([#289](https://github.com/AIGNE-io/aigne-framework/issues/289)) ([0f68887](https://github.com/AIGNE-io/aigne-framework/commit/0f688871d232e7a42613f4921491de8974b31b81))
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,112 @@
1
+ # @aigne/doubao
2
+
3
+ [![GitHub star chart](https://img.shields.io/github/stars/AIGNE-io/aigne-framework?style=flat-square)](https://star-history.com/#AIGNE-io/aigne-framework)
4
+ [![Open Issues](https://img.shields.io/github/issues-raw/AIGNE-io/aigne-framework?style=flat-square)](https://github.com/AIGNE-io/aigne-framework/issues)
5
+ [![codecov](https://codecov.io/gh/AIGNE-io/aigne-framework/graph/badge.svg?token=DO07834RQL)](https://codecov.io/gh/AIGNE-io/aigne-framework)
6
+ [![NPM Version](https://img.shields.io/npm/v/@aigne/doubao)](https://www.npmjs.com/package/@aigne/doubao)
7
+ [![Elastic-2.0 licensed](https://img.shields.io/npm/l/@aigne/doubao)](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE.md)
8
+
9
+ AIGNE Doubao SDK for integrating with Doubao AI models within the [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework).
10
+
11
+ ## Introduction
12
+
13
+ `@aigne/doubao` provides a seamless integration between the AIGNE Framework and Doubao's powerful language models and API. This package enables developers to easily leverage Doubao's AI models in their AIGNE applications, providing a consistent interface across the framework while taking advantage of Doubao's advanced AI capabilities.
14
+
15
+ ## Features
16
+
17
+ * **Doubao API Integration**: Direct connection to Doubao's API services
18
+ * **Chat Completions**: Support for Doubao's chat completions API with all available models
19
+ * **Function Calling**: Built-in support for function calling capabilities
20
+ * **Streaming Responses**: Support for streaming responses for more responsive applications
21
+ * **Type-Safe**: Comprehensive TypeScript typings for all APIs and models
22
+ * **Consistent Interface**: Compatible with the AIGNE Framework's model interface
23
+ * **Error Handling**: Robust error handling and retry mechanisms
24
+ * **Full Configuration**: Extensive configuration options for fine-tuning behavior
25
+
26
+ ## Installation
27
+
28
+ ### Using npm
29
+
30
+ ```bash
31
+ npm install @aigne/doubao @aigne/core
32
+ ```
33
+
34
+ ### Using yarn
35
+
36
+ ```bash
37
+ yarn add @aigne/doubao @aigne/core
38
+ ```
39
+
40
+ ### Using pnpm
41
+
42
+ ```bash
43
+ pnpm add @aigne/doubao @aigne/core
44
+ ```
45
+
46
+ ## Basic Usage
47
+
48
+ // todo
49
+ ```typescript file="test/doubao-chat-model.test.ts" region="example-doubao-chat-model"
50
+ import { DoubaoChatModel } from "@aigne/doubao";
51
+
52
+ const model = new DoubaoChatModel({
53
+ // Provide API key directly or use environment variable DOUBAO_API_KEY
54
+ apiKey: "your-api-key", // Optional if set in env variables
55
+ // Specify model version (defaults to 'doubao-seed-1-6-250615')
56
+ model: "doubao-seed-1-6-250615",
57
+ modelOptions: {
58
+ temperature: 0.7,
59
+ },
60
+ });
61
+
62
+ const result = await model.invoke({
63
+ messages: [{ role: "user", content: "Introduce yourself" }],
64
+ });
65
+
66
+ console.log(result);
67
+ /* Output:
68
+ {
69
+ text: "Hello! I'm Doubao, an AI developed by ByteDance. My main goal is to assist you with a wide range of tasks—whether you have questions to ask, need help brainstorming ideas, want explanations on topics, or just feel like chatting. I’m here to provide helpful, clear, and friendly responses. Feel free to let me know what you need—I’m happy to help! 😊",
70
+ usage: { inputTokens: 87, outputTokens: 219 },
71
+ model: 'doubao-seed-1-6-250615'
72
+ }
73
+ */
74
+ ```
75
+
76
+ ## Streaming Responses
77
+
78
+ // todo
79
+ ```typescript file="test/doubao-seed-1-6-250615-model.test.ts" region="example-doubao-seed-1-6-250615-model-streaming"
80
+ import { isAgentResponseDelta } from "@aigne/core";
81
+ import { DoubaoChatModel } from "@aigne/doubao";
82
+
83
+ const model = new DoubaoChatModel({
84
+ apiKey: "your-api-key",
85
+ model: "doubao-seed-1-6-250615",
86
+ });
87
+
88
+ const stream = await model.invoke(
89
+ {
90
+ messages: [{ role: "user", content: "Introduce yourself" }],
91
+ },
92
+ { streaming: true },
93
+ );
94
+
95
+ let fullText = "";
96
+ const json = {};
97
+
98
+ for await (const chunk of stream) {
99
+ if (isAgentResponseDelta(chunk)) {
100
+ const text = chunk.delta.text?.text;
101
+ if (text) fullText += text;
102
+ if (chunk.delta.json) Object.assign(json, chunk.delta.json);
103
+ }
104
+ }
105
+
106
+ console.log(fullText); // Output: "Hello! I'm an AI assistant powered by Doubao's language model."
107
+ console.log(json); // { model: "doubao-seed-1-6-250615", usage: { inputTokens: 7, outputTokens: 12 } }
108
+ ```
109
+
110
+ ## License
111
+
112
+ Elastic-2.0
@@ -0,0 +1,21 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
2
+ /**
3
+ * Implementation of the ChatModel interface for Doubao's API
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with Doubao's models,
6
+ * but with specific configuration and capabilities for Doubao.
7
+ *
8
+ * Default model: 'doubao-seed-1-6-250615'
9
+ *
10
+ * @example
11
+ * Here's how to create and use a Doubao chat model:
12
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model-streaming}
17
+ */
18
+ export declare class DoubaoChatModel extends OpenAIChatModel {
19
+ constructor(options?: OpenAIChatModelOptions);
20
+ protected apiKeyEnvName: string;
21
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DoubaoChatModel = void 0;
4
+ const openai_1 = require("@aigne/openai");
5
+ const DOUBAO_DEFAULT_CHAT_MODEL = "doubao-seed-1-6-250615";
6
+ const DOUBAO_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
7
+ /**
8
+ * Implementation of the ChatModel interface for Doubao's API
9
+ *
10
+ * This model uses OpenAI-compatible API format to interact with Doubao's models,
11
+ * but with specific configuration and capabilities for Doubao.
12
+ *
13
+ * Default model: 'doubao-seed-1-6-250615'
14
+ *
15
+ * @example
16
+ * Here's how to create and use a Doubao chat model:
17
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model}
18
+ *
19
+ * @example
20
+ * Here's an example with streaming response:
21
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model-streaming}
22
+ */
23
+ class DoubaoChatModel extends openai_1.OpenAIChatModel {
24
+ constructor(options) {
25
+ super({
26
+ ...options,
27
+ model: options?.model || DOUBAO_DEFAULT_CHAT_MODEL,
28
+ baseURL: options?.baseURL || DOUBAO_BASE_URL,
29
+ });
30
+ }
31
+ apiKeyEnvName = "DOUBAO_API_KEY";
32
+ }
33
+ exports.DoubaoChatModel = DoubaoChatModel;
@@ -0,0 +1 @@
1
+ export * from "./doubao-chat-model.js";
@@ -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("./doubao-chat-model.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,21 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
2
+ /**
3
+ * Implementation of the ChatModel interface for Doubao's API
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with Doubao's models,
6
+ * but with specific configuration and capabilities for Doubao.
7
+ *
8
+ * Default model: 'doubao-seed-1-6-250615'
9
+ *
10
+ * @example
11
+ * Here's how to create and use a Doubao chat model:
12
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model-streaming}
17
+ */
18
+ export declare class DoubaoChatModel extends OpenAIChatModel {
19
+ constructor(options?: OpenAIChatModelOptions);
20
+ protected apiKeyEnvName: string;
21
+ }
@@ -0,0 +1 @@
1
+ export * from "./doubao-chat-model.js";
@@ -0,0 +1,21 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
2
+ /**
3
+ * Implementation of the ChatModel interface for Doubao's API
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with Doubao's models,
6
+ * but with specific configuration and capabilities for Doubao.
7
+ *
8
+ * Default model: 'doubao-seed-1-6-250615'
9
+ *
10
+ * @example
11
+ * Here's how to create and use a Doubao chat model:
12
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model-streaming}
17
+ */
18
+ export declare class DoubaoChatModel extends OpenAIChatModel {
19
+ constructor(options?: OpenAIChatModelOptions);
20
+ protected apiKeyEnvName: string;
21
+ }
@@ -0,0 +1,29 @@
1
+ import { OpenAIChatModel } from "@aigne/openai";
2
+ const DOUBAO_DEFAULT_CHAT_MODEL = "doubao-seed-1-6-250615";
3
+ const DOUBAO_BASE_URL = "https://ark.cn-beijing.volces.com/api/v3";
4
+ /**
5
+ * Implementation of the ChatModel interface for Doubao's API
6
+ *
7
+ * This model uses OpenAI-compatible API format to interact with Doubao's models,
8
+ * but with specific configuration and capabilities for Doubao.
9
+ *
10
+ * Default model: 'doubao-seed-1-6-250615'
11
+ *
12
+ * @example
13
+ * Here's how to create and use a Doubao chat model:
14
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model}
15
+ *
16
+ * @example
17
+ * Here's an example with streaming response:
18
+ * {@includeCode ../test/doubao-chat-model.test.ts#example-doubao-chat-model-streaming}
19
+ */
20
+ export class DoubaoChatModel extends OpenAIChatModel {
21
+ constructor(options) {
22
+ super({
23
+ ...options,
24
+ model: options?.model || DOUBAO_DEFAULT_CHAT_MODEL,
25
+ baseURL: options?.baseURL || DOUBAO_BASE_URL,
26
+ });
27
+ }
28
+ apiKeyEnvName = "DOUBAO_API_KEY";
29
+ }
@@ -0,0 +1 @@
1
+ export * from "./doubao-chat-model.js";
@@ -0,0 +1 @@
1
+ export * from "./doubao-chat-model.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@aigne/doubao",
3
+ "description": "AIGNE doubao SDK for integrating with doubao AI models",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
8
+ "homepage": "https://github.com/AIGNE-io/aigne-framework",
9
+ "license": "Elastic-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/AIGNE-io/aigne-framework"
13
+ },
14
+ "files": [
15
+ "lib/cjs",
16
+ "lib/dts",
17
+ "lib/esm",
18
+ "LICENSE",
19
+ "README.md",
20
+ "CHANGELOG.md"
21
+ ],
22
+ "type": "module",
23
+ "main": "./lib/cjs/index.js",
24
+ "module": "./lib/esm/index.js",
25
+ "types": "./lib/dts/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "import": "./lib/esm/index.js",
29
+ "require": "./lib/cjs/index.js",
30
+ "types": "./lib/dts/index.d.ts"
31
+ }
32
+ },
33
+ "dependencies": {
34
+ "@aigne/openai": "^0.10.6"
35
+ },
36
+ "devDependencies": {
37
+ "@types/bun": "^1.2.18",
38
+ "@types/node": "^24.0.12",
39
+ "npm-run-all": "^4.1.5",
40
+ "rimraf": "^6.0.1",
41
+ "typescript": "^5.8.3",
42
+ "@aigne/test-utils": "^0.5.14",
43
+ "@aigne/core": "^1.39.0"
44
+ },
45
+ "version": "1.0.0",
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": "node ../../scripts/post-build-lib.mjs"
53
+ }
54
+ }