@aigne/poe 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-08-14)
4
+
5
+
6
+ ### Features
7
+
8
+ * **model:** add poe chat model support ([#365](https://github.com/AIGNE-io/aigne-framework/issues/365)) ([b2cce67](https://github.com/AIGNE-io/aigne-framework/commit/b2cce67bdab1c6dec273929bcdd79e1d15410119))
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,127 @@
1
+ # @aigne/poe
2
+
3
+ <p align="center">
4
+ <picture>
5
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo-dark.svg" media="(prefers-color-scheme: dark)">
6
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" media="(prefers-color-scheme: light)">
7
+ <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/logo.svg" alt="AIGNE Logo" width="400" />
8
+ </picture>
9
+ </p>
10
+
11
+ [![GitHub star chart](https://img.shields.io/github/stars/AIGNE-io/aigne-framework?style=flat-square)](https://star-history.com/#AIGNE-io/aigne-framework)
12
+ [![Open Issues](https://img.shields.io/github/issues-raw/AIGNE-io/aigne-framework?style=flat-square)](https://github.com/AIGNE-io/aigne-framework/issues)
13
+ [![codecov](https://codecov.io/gh/AIGNE-io/aigne-framework/graph/badge.svg?token=DO07834RQL)](https://codecov.io/gh/AIGNE-io/aigne-framework)
14
+ [![NPM Version](https://img.shields.io/npm/v/@aigne/poe)](https://www.npmjs.com/package/@aigne/poe)
15
+ [![Elastic-2.0 licensed](https://img.shields.io/npm/l/@aigne/poe)](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE.md)
16
+
17
+ AIGNE Poe SDK for integrating with Poe language models and API services within the [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework).
18
+
19
+ ## Introduction
20
+
21
+ `@aigne/poe` provides a seamless integration between the AIGNE Framework and Poe's language models and API services. This package enables developers to easily leverage Poe's models in their AIGNE applications, providing a consistent interface across the framework while taking advantage of Poe's advanced AI capabilities.
22
+
23
+ <picture>
24
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-poe-dark.png" media="(prefers-color-scheme: dark)">
25
+ <source srcset="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/assets/aigne-poe.png" media="(prefers-color-scheme: light)">
26
+ <img src="https://raw.githubusercontent.com/AIGNE-io/aigne-framework/main/aigne-poe.png" alt="AIGNE Arch" />
27
+ </picture>
28
+
29
+ ## Features
30
+
31
+ * **Poe API Integration**: Direct connection to Poe's API services
32
+ * **Chat Completions**: Support for Poe's chat completions API with all available models
33
+ * **Function Calling**: Built-in support for function calling capabilities
34
+ * **Streaming Responses**: Support for streaming responses for more responsive applications
35
+ * **Type-Safe**: Comprehensive TypeScript typings for all APIs and models
36
+ * **Consistent Interface**: Compatible with the AIGNE Framework's model interface
37
+ * **Error Handling**: Robust error handling and retry mechanisms
38
+ * **Full Configuration**: Extensive configuration options for fine-tuning behavior
39
+
40
+ ## Installation
41
+
42
+ ### Using npm
43
+
44
+ ```bash
45
+ npm install @aigne/poe @aigne/core
46
+ ```
47
+
48
+ ### Using yarn
49
+
50
+ ```bash
51
+ yarn add @aigne/poe @aigne/core
52
+ ```
53
+
54
+ ### Using pnpm
55
+
56
+ ```bash
57
+ pnpm add @aigne/poe @aigne/core
58
+ ```
59
+
60
+ ## Basic Usage
61
+
62
+ ```typescript file="test/poe-chat-model.test.ts" region="example-poe-chat-model"
63
+ import { PoeChatModel } from "@aigne/poe";
64
+
65
+ const model = new PoeChatModel({
66
+ // Provide API key directly or use environment variable POE_API_KEY
67
+ apiKey: "your-api-key", // Optional if set in env variables
68
+ // Specify model (defaults to 'openai/gpt-4o')
69
+ model: "claude-3-opus",
70
+ modelOptions: {
71
+ temperature: 0.7,
72
+ },
73
+ });
74
+
75
+ const result = await model.invoke({
76
+ messages: [{ role: "user", content: "Which model are you using?" }],
77
+ });
78
+
79
+ console.log(result);
80
+ /* Output:
81
+ {
82
+ text: "I'm powered by Poe, using the Claude 3 Opus model from Anthropic.",
83
+ model: "claude-3-opus",
84
+ usage: {
85
+ inputTokens: 5,
86
+ outputTokens: 14
87
+ }
88
+ }
89
+ */
90
+ ```
91
+
92
+ ## Streaming Responses
93
+
94
+ ```typescript file="test/poe-chat-model.test.ts" region="example-poe-chat-model-streaming"
95
+ import { isAgentResponseDelta } from "@aigne/core";
96
+ import { PoeChatModel } from "@aigne/poe";
97
+
98
+ const model = new PoeChatModel({
99
+ apiKey: "your-api-key",
100
+ model: "claude-3-opus",
101
+ });
102
+
103
+ const stream = await model.invoke(
104
+ {
105
+ messages: [{ role: "user", content: "Which model are you using?" }],
106
+ },
107
+ { streaming: true },
108
+ );
109
+
110
+ let fullText = "";
111
+ const json = {};
112
+
113
+ for await (const chunk of stream) {
114
+ if (isAgentResponseDelta(chunk)) {
115
+ const text = chunk.delta.text?.text;
116
+ if (text) fullText += text;
117
+ if (chunk.delta.json) Object.assign(json, chunk.delta.json);
118
+ }
119
+ }
120
+
121
+ console.log(fullText); // Output: "I'm powered by Poe, using the Claude 3 Opus model from Anthropic."
122
+ console.log(json); // { model: "anthropic/claude-3-opus", usage: { inputTokens: 5, outputTokens: 14 } }
123
+ ```
124
+
125
+ ## License
126
+
127
+ Elastic-2.0
@@ -0,0 +1 @@
1
+ export * from "./poe.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("./poe.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,22 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
2
+ /**
3
+ * Implementation of the ChatModel interface for Poe's API (Grok)
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with X.AI models,
6
+ * providing access to models like Grok.
7
+ *
8
+ * Default model: 'grok-2-latest'
9
+ *
10
+ * @example
11
+ * Here's how to create and use an Poe chat model:
12
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model-streaming}
17
+ */
18
+ export declare class PoeChatModel extends OpenAIChatModel {
19
+ constructor(options?: OpenAIChatModelOptions);
20
+ protected apiKeyEnvName: string;
21
+ protected supportsParallelToolCalls: boolean;
22
+ }
package/lib/cjs/poe.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PoeChatModel = void 0;
4
+ const openai_1 = require("@aigne/openai");
5
+ const POE_DEFAULT_CHAT_MODEL = "gpt-5-mini";
6
+ const POE_BASE_URL = "https://api.poe.com/v1";
7
+ /**
8
+ * Implementation of the ChatModel interface for Poe's API (Grok)
9
+ *
10
+ * This model uses OpenAI-compatible API format to interact with X.AI models,
11
+ * providing access to models like Grok.
12
+ *
13
+ * Default model: 'grok-2-latest'
14
+ *
15
+ * @example
16
+ * Here's how to create and use an Poe chat model:
17
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model}
18
+ *
19
+ * @example
20
+ * Here's an example with streaming response:
21
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model-streaming}
22
+ */
23
+ class PoeChatModel extends openai_1.OpenAIChatModel {
24
+ constructor(options) {
25
+ super({
26
+ ...options,
27
+ model: options?.model || POE_DEFAULT_CHAT_MODEL,
28
+ baseURL: options?.baseURL || POE_BASE_URL,
29
+ });
30
+ }
31
+ apiKeyEnvName = "POE_API_KEY";
32
+ supportsParallelToolCalls = false;
33
+ }
34
+ exports.PoeChatModel = PoeChatModel;
@@ -0,0 +1 @@
1
+ export * from "./poe.js";
@@ -0,0 +1,22 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
2
+ /**
3
+ * Implementation of the ChatModel interface for Poe's API (Grok)
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with X.AI models,
6
+ * providing access to models like Grok.
7
+ *
8
+ * Default model: 'grok-2-latest'
9
+ *
10
+ * @example
11
+ * Here's how to create and use an Poe chat model:
12
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model-streaming}
17
+ */
18
+ export declare class PoeChatModel extends OpenAIChatModel {
19
+ constructor(options?: OpenAIChatModelOptions);
20
+ protected apiKeyEnvName: string;
21
+ protected supportsParallelToolCalls: boolean;
22
+ }
@@ -0,0 +1 @@
1
+ export * from "./poe.js";
@@ -0,0 +1 @@
1
+ export * from "./poe.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,22 @@
1
+ import { OpenAIChatModel, type OpenAIChatModelOptions } from "@aigne/openai";
2
+ /**
3
+ * Implementation of the ChatModel interface for Poe's API (Grok)
4
+ *
5
+ * This model uses OpenAI-compatible API format to interact with X.AI models,
6
+ * providing access to models like Grok.
7
+ *
8
+ * Default model: 'grok-2-latest'
9
+ *
10
+ * @example
11
+ * Here's how to create and use an Poe chat model:
12
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model}
13
+ *
14
+ * @example
15
+ * Here's an example with streaming response:
16
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model-streaming}
17
+ */
18
+ export declare class PoeChatModel extends OpenAIChatModel {
19
+ constructor(options?: OpenAIChatModelOptions);
20
+ protected apiKeyEnvName: string;
21
+ protected supportsParallelToolCalls: boolean;
22
+ }
package/lib/esm/poe.js ADDED
@@ -0,0 +1,30 @@
1
+ import { OpenAIChatModel } from "@aigne/openai";
2
+ const POE_DEFAULT_CHAT_MODEL = "gpt-5-mini";
3
+ const POE_BASE_URL = "https://api.poe.com/v1";
4
+ /**
5
+ * Implementation of the ChatModel interface for Poe's API (Grok)
6
+ *
7
+ * This model uses OpenAI-compatible API format to interact with X.AI models,
8
+ * providing access to models like Grok.
9
+ *
10
+ * Default model: 'grok-2-latest'
11
+ *
12
+ * @example
13
+ * Here's how to create and use an Poe chat model:
14
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model}
15
+ *
16
+ * @example
17
+ * Here's an example with streaming response:
18
+ * {@includeCode ../test/poe-chat-model.test.ts#example-poe-chat-model-streaming}
19
+ */
20
+ export class PoeChatModel extends OpenAIChatModel {
21
+ constructor(options) {
22
+ super({
23
+ ...options,
24
+ model: options?.model || POE_DEFAULT_CHAT_MODEL,
25
+ baseURL: options?.baseURL || POE_BASE_URL,
26
+ });
27
+ }
28
+ apiKeyEnvName = "POE_API_KEY";
29
+ supportsParallelToolCalls = false;
30
+ }
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@aigne/poe",
3
+ "description": "AIGNE Poe SDK for integrating with Poe's language models and API services",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
8
+ "homepage": "https://www.aigne.io/framework",
9
+ "license": "Elastic-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/AIGNE-io/aigne-framework"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/AIGNE-io/aigne-framework/issues"
16
+ },
17
+ "files": [
18
+ "lib/cjs",
19
+ "lib/dts",
20
+ "lib/esm",
21
+ "LICENSE",
22
+ "README.md",
23
+ "CHANGELOG.md"
24
+ ],
25
+ "type": "module",
26
+ "main": "./lib/cjs/index.js",
27
+ "module": "./lib/esm/index.js",
28
+ "types": "./lib/dts/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "import": "./lib/esm/index.js",
32
+ "require": "./lib/cjs/index.js",
33
+ "types": "./lib/dts/index.d.ts"
34
+ }
35
+ },
36
+ "dependencies": {
37
+ "@aigne/openai": "^0.11.2"
38
+ },
39
+ "devDependencies": {
40
+ "@types/bun": "^1.2.18",
41
+ "@types/node": "^24.0.12",
42
+ "npm-run-all": "^4.1.5",
43
+ "rimraf": "^6.0.1",
44
+ "typescript": "^5.8.3",
45
+ "@aigne/test-utils": "^0.5.28",
46
+ "@aigne/core": "^1.50.0"
47
+ },
48
+ "version": "1.0.0",
49
+ "scripts": {
50
+ "lint": "tsc --noEmit",
51
+ "build": "tsc --build scripts/tsconfig.build.json",
52
+ "clean": "rimraf lib test/coverage",
53
+ "test": "bun test",
54
+ "test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text",
55
+ "postbuild": "node ../../scripts/post-build-lib.mjs"
56
+ }
57
+ }