├── .gitignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src └── index.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # vitepress build output 108 | **/.vitepress/dist 109 | 110 | # vitepress cache directory 111 | **/.vitepress/cache 112 | 113 | # Docusaurus cache and generated files 114 | .docusaurus 115 | 116 | # Serverless directories 117 | .serverless/ 118 | 119 | # FuseBox cache 120 | .fusebox/ 121 | 122 | # DynamoDB Local files 123 | .dynamodb/ 124 | 125 | # TernJS port file 126 | .tern-port 127 | 128 | # Stores VSCode versions used for testing VSCode extensions 129 | .vscode-test 130 | 131 | # yarn v2 132 | .yarn/cache 133 | .yarn/unplugged 134 | .yarn/build-state.yml 135 | .yarn/install-state.gz 136 | .pnp.* 137 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # langchain-llm7 2 | 3 | [![npm version](https://badge.fury.io/js/langchain-llm7.svg)](https://badge.fury.io/js/langchain-llm7) 4 | [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 5 | [![LinkedIn](https://img.shields.io/badge/LinkedIn-blue)](https://www.linkedin.com/in/eugene-evstafev-716669181/) 6 | [![Downloads](https://img.shields.io/npm/dy/langchain-llm7)](https://img.shields.io/npm/dy/langchain-llm7) 7 | 8 | [LangChain](https://js.langchain.com/) integration for the [LLM7 Chat API](https://api.llm7.io/v1). 9 | 10 | This package provides a `ChatLLM7` class that implements the LangChain `SimpleChatModel` interface, allowing seamless integration with the LangChain JS/TS ecosystem for both standard invocation and streaming responses. 11 | 12 | ## Installation 13 | 14 | ```bash 15 | npm install langchain-llm7 @langchain/core 16 | ```` 17 | 18 | or 19 | 20 | ```bash 21 | yarn add langchain-llm7 @langchain/core 22 | ``` 23 | 24 | Note: `@langchain/core` is a peer dependency. 25 | 26 | ## Usage 27 | 28 | Here's how to use the `ChatLLM7` model: 29 | 30 | ```typescript 31 | import { ChatLLM7 } from "langchain-llm7"; 32 | import { HumanMessage, SystemMessage } from "@langchain/core/messages"; 33 | 34 | // Initialize the model (defaults or provide specific options) 35 | const chat = new ChatLLM7({ 36 | // modelName: "gpt-4.1-nano", // Default 37 | // temperature: 0.8, 38 | // maxTokens: 150, 39 | }); 40 | 41 | const messages = [ 42 | new SystemMessage("You are a helpful assistant."), 43 | new HumanMessage("What is the capital of France?"), 44 | ]; 45 | 46 | // --- Basic Invocation (Non-streaming) --- 47 | console.log("--- Testing invoke() ---"); 48 | try { 49 | const response = await chat.invoke(messages); 50 | console.log("Response:", response.content); 51 | // Example Output: Response: Paris 52 | } catch (error) { 53 | console.error("Invoke Error:", error); 54 | } 55 | 56 | // --- Streaming --- 57 | console.log("\n--- Testing stream() ---"); 58 | try { 59 | const stream = await chat.stream(messages); 60 | let fullResponse = ""; 61 | process.stdout.write("Streamed Response: "); 62 | for await (const chunk of stream) { 63 | process.stdout.write(chunk.text); // Use .text for string content of the chunk 64 | fullResponse += chunk.text; // Accumulate the text part 65 | } 66 | process.stdout.write("\n"); 67 | console.log("(Full streamed content length:", fullResponse.length, ")"); 68 | // Example Output: Streamed Response: Paris 69 | // (Full streamed content length: 5) 70 | } catch (error) { 71 | console.error("Stream Error:", error); 72 | } 73 | ``` 74 | 75 | ## Configuration 76 | 77 | You can configure the `ChatLLM7` model by passing parameters to its constructor: 78 | 79 | | Parameter | Type | Default | Description | 80 | |--------------|--------------|------------------------------|-----------------------------------------------------------------------------| 81 | | `baseUrl` | `string` | `"https://api.llm7.io/v1"` | Base URL for the LLM7 API. | 82 | | `modelName` | `string` | `"gpt-4.1-nano"` | The specific LLM7 model to use. | 83 | | `temperature`| `number` | `1.0` | Sampling temperature (usually between 0 and 2). Higher values mean more randomness. | 84 | | `maxTokens` | `number` | `undefined` | Maximum number of tokens to generate in the completion. | 85 | | `timeout` | `number` | `120` | Request timeout in seconds. | 86 | | `maxRetries` | `number` | `3` | Maximum number of retries for failed API requests (network errors, 5xx, 429). | 87 | | `stop` | `string[]` | `undefined` | Optional list of sequences where the API should stop generating tokens. | 88 | 89 | All standard `BaseChatModelParams` like `callbacks`, `verbose`, etc., are also accepted. 90 | 91 | ## Development 92 | 93 | 94 | 1. Clone the repository: `git clone https://github.com/chigwell/npm-langchain-llm7.git` 95 | 2. Install dependencies: `cd npm-langchain-llm7 && npm install` 96 | 3. Build the package: `npm run build` 97 | 4. Run tests (using the example): `npx ts-node test.ts` 98 | 99 | ## Contributing 100 | 101 | Contributions are welcome\! Please feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/chigwell/npm-langchain-llm7). 102 | 103 | ## License 104 | 105 | This package is licensed under the [Apache License 2.0](https://www.google.com/search?q=LICENSE). 106 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "langchain-llm7", 3 | "version": "2025.04.101554", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "langchain-llm7", 9 | "version": "2025.04.101554", 10 | "license": "Apache-2.0", 11 | "dependencies": { 12 | "@langchain/core": "^0.1.0", 13 | "axios": "^1.6.0", 14 | "axios-retry": "^4.0.0", 15 | "gpt-3-encoder": "^1.1.4" 16 | }, 17 | "devDependencies": { 18 | "@types/node": "^20.0.0", 19 | "ts-node": "^10.9.2", 20 | "typescript": "^5.0.0" 21 | } 22 | }, 23 | "node_modules/@cspotcode/source-map-support": { 24 | "version": "0.8.1", 25 | "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", 26 | "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", 27 | "dev": true, 28 | "dependencies": { 29 | "@jridgewell/trace-mapping": "0.3.9" 30 | }, 31 | "engines": { 32 | "node": ">=12" 33 | } 34 | }, 35 | "node_modules/@jridgewell/resolve-uri": { 36 | "version": "3.1.2", 37 | "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", 38 | "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", 39 | "dev": true, 40 | "engines": { 41 | "node": ">=6.0.0" 42 | } 43 | }, 44 | "node_modules/@jridgewell/sourcemap-codec": { 45 | "version": "1.5.0", 46 | "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", 47 | "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", 48 | "dev": true 49 | }, 50 | "node_modules/@jridgewell/trace-mapping": { 51 | "version": "0.3.9", 52 | "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", 53 | "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", 54 | "dev": true, 55 | "dependencies": { 56 | "@jridgewell/resolve-uri": "^3.0.3", 57 | "@jridgewell/sourcemap-codec": "^1.4.10" 58 | } 59 | }, 60 | "node_modules/@langchain/core": { 61 | "version": "0.1.63", 62 | "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.1.63.tgz", 63 | "integrity": "sha512-+fjyYi8wy6x1P+Ee1RWfIIEyxd9Ee9jksEwvrggPwwI/p45kIDTdYTblXsM13y4mNWTiACyLSdbwnPaxxdoz+w==", 64 | "dependencies": { 65 | "ansi-styles": "^5.0.0", 66 | "camelcase": "6", 67 | "decamelize": "1.2.0", 68 | "js-tiktoken": "^1.0.12", 69 | "langsmith": "~0.1.7", 70 | "ml-distance": "^4.0.0", 71 | "mustache": "^4.2.0", 72 | "p-queue": "^6.6.2", 73 | "p-retry": "4", 74 | "uuid": "^9.0.0", 75 | "zod": "^3.22.4", 76 | "zod-to-json-schema": "^3.22.3" 77 | }, 78 | "engines": { 79 | "node": ">=18" 80 | } 81 | }, 82 | "node_modules/@tsconfig/node10": { 83 | "version": "1.0.11", 84 | "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", 85 | "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", 86 | "dev": true 87 | }, 88 | "node_modules/@tsconfig/node12": { 89 | "version": "1.0.11", 90 | "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", 91 | "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", 92 | "dev": true 93 | }, 94 | "node_modules/@tsconfig/node14": { 95 | "version": "1.0.3", 96 | "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", 97 | "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", 98 | "dev": true 99 | }, 100 | "node_modules/@tsconfig/node16": { 101 | "version": "1.0.4", 102 | "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", 103 | "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", 104 | "dev": true 105 | }, 106 | "node_modules/@types/node": { 107 | "version": "20.17.30", 108 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.30.tgz", 109 | "integrity": "sha512-7zf4YyHA+jvBNfVrk2Gtvs6x7E8V+YDW05bNfG2XkWDJfYRXrTiP/DsB2zSYTaHX0bGIujTBQdMVAhb+j7mwpg==", 110 | "dev": true, 111 | "dependencies": { 112 | "undici-types": "~6.19.2" 113 | } 114 | }, 115 | "node_modules/@types/retry": { 116 | "version": "0.12.0", 117 | "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", 118 | "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==" 119 | }, 120 | "node_modules/@types/uuid": { 121 | "version": "10.0.0", 122 | "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", 123 | "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==" 124 | }, 125 | "node_modules/acorn": { 126 | "version": "8.14.1", 127 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz", 128 | "integrity": "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==", 129 | "dev": true, 130 | "bin": { 131 | "acorn": "bin/acorn" 132 | }, 133 | "engines": { 134 | "node": ">=0.4.0" 135 | } 136 | }, 137 | "node_modules/acorn-walk": { 138 | "version": "8.3.4", 139 | "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", 140 | "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", 141 | "dev": true, 142 | "dependencies": { 143 | "acorn": "^8.11.0" 144 | }, 145 | "engines": { 146 | "node": ">=0.4.0" 147 | } 148 | }, 149 | "node_modules/ansi-styles": { 150 | "version": "5.2.0", 151 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", 152 | "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", 153 | "engines": { 154 | "node": ">=10" 155 | }, 156 | "funding": { 157 | "url": "https://github.com/chalk/ansi-styles?sponsor=1" 158 | } 159 | }, 160 | "node_modules/arg": { 161 | "version": "4.1.3", 162 | "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", 163 | "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", 164 | "dev": true 165 | }, 166 | "node_modules/asynckit": { 167 | "version": "0.4.0", 168 | "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", 169 | "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" 170 | }, 171 | "node_modules/axios": { 172 | "version": "1.8.4", 173 | "resolved": "https://registry.npmjs.org/axios/-/axios-1.8.4.tgz", 174 | "integrity": "sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==", 175 | "dependencies": { 176 | "follow-redirects": "^1.15.6", 177 | "form-data": "^4.0.0", 178 | "proxy-from-env": "^1.1.0" 179 | } 180 | }, 181 | "node_modules/axios-retry": { 182 | "version": "4.5.0", 183 | "resolved": "https://registry.npmjs.org/axios-retry/-/axios-retry-4.5.0.tgz", 184 | "integrity": "sha512-aR99oXhpEDGo0UuAlYcn2iGRds30k366Zfa05XWScR9QaQD4JYiP3/1Qt1u7YlefUOK+cn0CcwoL1oefavQUlQ==", 185 | "dependencies": { 186 | "is-retry-allowed": "^2.2.0" 187 | }, 188 | "peerDependencies": { 189 | "axios": "0.x || 1.x" 190 | } 191 | }, 192 | "node_modules/base64-js": { 193 | "version": "1.5.1", 194 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", 195 | "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", 196 | "funding": [ 197 | { 198 | "type": "github", 199 | "url": "https://github.com/sponsors/feross" 200 | }, 201 | { 202 | "type": "patreon", 203 | "url": "https://www.patreon.com/feross" 204 | }, 205 | { 206 | "type": "consulting", 207 | "url": "https://feross.org/support" 208 | } 209 | ] 210 | }, 211 | "node_modules/binary-search": { 212 | "version": "1.3.6", 213 | "resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.6.tgz", 214 | "integrity": "sha512-nbE1WxOTTrUWIfsfZ4aHGYu5DOuNkbxGokjV6Z2kxfJK3uaAb8zNK1muzOeipoLHZjInT4Br88BHpzevc681xA==" 215 | }, 216 | "node_modules/call-bind-apply-helpers": { 217 | "version": "1.0.2", 218 | "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", 219 | "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", 220 | "dependencies": { 221 | "es-errors": "^1.3.0", 222 | "function-bind": "^1.1.2" 223 | }, 224 | "engines": { 225 | "node": ">= 0.4" 226 | } 227 | }, 228 | "node_modules/camelcase": { 229 | "version": "6.3.0", 230 | "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", 231 | "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", 232 | "engines": { 233 | "node": ">=10" 234 | }, 235 | "funding": { 236 | "url": "https://github.com/sponsors/sindresorhus" 237 | } 238 | }, 239 | "node_modules/combined-stream": { 240 | "version": "1.0.8", 241 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", 242 | "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", 243 | "dependencies": { 244 | "delayed-stream": "~1.0.0" 245 | }, 246 | "engines": { 247 | "node": ">= 0.8" 248 | } 249 | }, 250 | "node_modules/commander": { 251 | "version": "10.0.1", 252 | "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", 253 | "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", 254 | "engines": { 255 | "node": ">=14" 256 | } 257 | }, 258 | "node_modules/create-require": { 259 | "version": "1.1.1", 260 | "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", 261 | "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", 262 | "dev": true 263 | }, 264 | "node_modules/decamelize": { 265 | "version": "1.2.0", 266 | "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", 267 | "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", 268 | "engines": { 269 | "node": ">=0.10.0" 270 | } 271 | }, 272 | "node_modules/delayed-stream": { 273 | "version": "1.0.0", 274 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 275 | "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", 276 | "engines": { 277 | "node": ">=0.4.0" 278 | } 279 | }, 280 | "node_modules/diff": { 281 | "version": "4.0.2", 282 | "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", 283 | "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", 284 | "dev": true, 285 | "engines": { 286 | "node": ">=0.3.1" 287 | } 288 | }, 289 | "node_modules/dunder-proto": { 290 | "version": "1.0.1", 291 | "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", 292 | "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", 293 | "dependencies": { 294 | "call-bind-apply-helpers": "^1.0.1", 295 | "es-errors": "^1.3.0", 296 | "gopd": "^1.2.0" 297 | }, 298 | "engines": { 299 | "node": ">= 0.4" 300 | } 301 | }, 302 | "node_modules/es-define-property": { 303 | "version": "1.0.1", 304 | "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", 305 | "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", 306 | "engines": { 307 | "node": ">= 0.4" 308 | } 309 | }, 310 | "node_modules/es-errors": { 311 | "version": "1.3.0", 312 | "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", 313 | "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", 314 | "engines": { 315 | "node": ">= 0.4" 316 | } 317 | }, 318 | "node_modules/es-object-atoms": { 319 | "version": "1.1.1", 320 | "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", 321 | "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", 322 | "dependencies": { 323 | "es-errors": "^1.3.0" 324 | }, 325 | "engines": { 326 | "node": ">= 0.4" 327 | } 328 | }, 329 | "node_modules/es-set-tostringtag": { 330 | "version": "2.1.0", 331 | "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", 332 | "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", 333 | "dependencies": { 334 | "es-errors": "^1.3.0", 335 | "get-intrinsic": "^1.2.6", 336 | "has-tostringtag": "^1.0.2", 337 | "hasown": "^2.0.2" 338 | }, 339 | "engines": { 340 | "node": ">= 0.4" 341 | } 342 | }, 343 | "node_modules/eventemitter3": { 344 | "version": "4.0.7", 345 | "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", 346 | "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==" 347 | }, 348 | "node_modules/follow-redirects": { 349 | "version": "1.15.9", 350 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", 351 | "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", 352 | "funding": [ 353 | { 354 | "type": "individual", 355 | "url": "https://github.com/sponsors/RubenVerborgh" 356 | } 357 | ], 358 | "engines": { 359 | "node": ">=4.0" 360 | }, 361 | "peerDependenciesMeta": { 362 | "debug": { 363 | "optional": true 364 | } 365 | } 366 | }, 367 | "node_modules/form-data": { 368 | "version": "4.0.2", 369 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", 370 | "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", 371 | "dependencies": { 372 | "asynckit": "^0.4.0", 373 | "combined-stream": "^1.0.8", 374 | "es-set-tostringtag": "^2.1.0", 375 | "mime-types": "^2.1.12" 376 | }, 377 | "engines": { 378 | "node": ">= 6" 379 | } 380 | }, 381 | "node_modules/function-bind": { 382 | "version": "1.1.2", 383 | "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", 384 | "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", 385 | "funding": { 386 | "url": "https://github.com/sponsors/ljharb" 387 | } 388 | }, 389 | "node_modules/get-intrinsic": { 390 | "version": "1.3.0", 391 | "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", 392 | "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", 393 | "dependencies": { 394 | "call-bind-apply-helpers": "^1.0.2", 395 | "es-define-property": "^1.0.1", 396 | "es-errors": "^1.3.0", 397 | "es-object-atoms": "^1.1.1", 398 | "function-bind": "^1.1.2", 399 | "get-proto": "^1.0.1", 400 | "gopd": "^1.2.0", 401 | "has-symbols": "^1.1.0", 402 | "hasown": "^2.0.2", 403 | "math-intrinsics": "^1.1.0" 404 | }, 405 | "engines": { 406 | "node": ">= 0.4" 407 | }, 408 | "funding": { 409 | "url": "https://github.com/sponsors/ljharb" 410 | } 411 | }, 412 | "node_modules/get-proto": { 413 | "version": "1.0.1", 414 | "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", 415 | "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", 416 | "dependencies": { 417 | "dunder-proto": "^1.0.1", 418 | "es-object-atoms": "^1.0.0" 419 | }, 420 | "engines": { 421 | "node": ">= 0.4" 422 | } 423 | }, 424 | "node_modules/gopd": { 425 | "version": "1.2.0", 426 | "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", 427 | "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", 428 | "engines": { 429 | "node": ">= 0.4" 430 | }, 431 | "funding": { 432 | "url": "https://github.com/sponsors/ljharb" 433 | } 434 | }, 435 | "node_modules/gpt-3-encoder": { 436 | "version": "1.1.4", 437 | "resolved": "https://registry.npmjs.org/gpt-3-encoder/-/gpt-3-encoder-1.1.4.tgz", 438 | "integrity": "sha512-fSQRePV+HUAhCn7+7HL7lNIXNm6eaFWFbNLOOGtmSJ0qJycyQvj60OvRlH7mee8xAMjBDNRdMXlMwjAbMTDjkg==" 439 | }, 440 | "node_modules/has-symbols": { 441 | "version": "1.1.0", 442 | "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", 443 | "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", 444 | "engines": { 445 | "node": ">= 0.4" 446 | }, 447 | "funding": { 448 | "url": "https://github.com/sponsors/ljharb" 449 | } 450 | }, 451 | "node_modules/has-tostringtag": { 452 | "version": "1.0.2", 453 | "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", 454 | "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", 455 | "dependencies": { 456 | "has-symbols": "^1.0.3" 457 | }, 458 | "engines": { 459 | "node": ">= 0.4" 460 | }, 461 | "funding": { 462 | "url": "https://github.com/sponsors/ljharb" 463 | } 464 | }, 465 | "node_modules/hasown": { 466 | "version": "2.0.2", 467 | "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", 468 | "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", 469 | "dependencies": { 470 | "function-bind": "^1.1.2" 471 | }, 472 | "engines": { 473 | "node": ">= 0.4" 474 | } 475 | }, 476 | "node_modules/is-any-array": { 477 | "version": "2.0.1", 478 | "resolved": "https://registry.npmjs.org/is-any-array/-/is-any-array-2.0.1.tgz", 479 | "integrity": "sha512-UtilS7hLRu++wb/WBAw9bNuP1Eg04Ivn1vERJck8zJthEvXCBEBpGR/33u/xLKWEQf95803oalHrVDptcAvFdQ==" 480 | }, 481 | "node_modules/is-retry-allowed": { 482 | "version": "2.2.0", 483 | "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-2.2.0.tgz", 484 | "integrity": "sha512-XVm7LOeLpTW4jV19QSH38vkswxoLud8sQ57YwJVTPWdiaI9I8keEhGFpBlslyVsgdQy4Opg8QOLb8YRgsyZiQg==", 485 | "engines": { 486 | "node": ">=10" 487 | }, 488 | "funding": { 489 | "url": "https://github.com/sponsors/sindresorhus" 490 | } 491 | }, 492 | "node_modules/js-tiktoken": { 493 | "version": "1.0.19", 494 | "resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.19.tgz", 495 | "integrity": "sha512-XC63YQeEcS47Y53gg950xiZ4IWmkfMe4p2V9OSaBt26q+p47WHn18izuXzSclCI73B7yGqtfRsT6jcZQI0y08g==", 496 | "dependencies": { 497 | "base64-js": "^1.5.1" 498 | } 499 | }, 500 | "node_modules/langsmith": { 501 | "version": "0.1.68", 502 | "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.68.tgz", 503 | "integrity": "sha512-otmiysWtVAqzMx3CJ4PrtUBhWRG5Co8Z4o7hSZENPjlit9/j3/vm3TSvbaxpDYakZxtMjhkcJTqrdYFipISEiQ==", 504 | "dependencies": { 505 | "@types/uuid": "^10.0.0", 506 | "commander": "^10.0.1", 507 | "p-queue": "^6.6.2", 508 | "p-retry": "4", 509 | "semver": "^7.6.3", 510 | "uuid": "^10.0.0" 511 | }, 512 | "peerDependencies": { 513 | "openai": "*" 514 | }, 515 | "peerDependenciesMeta": { 516 | "openai": { 517 | "optional": true 518 | } 519 | } 520 | }, 521 | "node_modules/langsmith/node_modules/uuid": { 522 | "version": "10.0.0", 523 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", 524 | "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", 525 | "funding": [ 526 | "https://github.com/sponsors/broofa", 527 | "https://github.com/sponsors/ctavan" 528 | ], 529 | "bin": { 530 | "uuid": "dist/bin/uuid" 531 | } 532 | }, 533 | "node_modules/make-error": { 534 | "version": "1.3.6", 535 | "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", 536 | "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", 537 | "dev": true 538 | }, 539 | "node_modules/math-intrinsics": { 540 | "version": "1.1.0", 541 | "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", 542 | "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", 543 | "engines": { 544 | "node": ">= 0.4" 545 | } 546 | }, 547 | "node_modules/mime-db": { 548 | "version": "1.52.0", 549 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", 550 | "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", 551 | "engines": { 552 | "node": ">= 0.6" 553 | } 554 | }, 555 | "node_modules/mime-types": { 556 | "version": "2.1.35", 557 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", 558 | "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", 559 | "dependencies": { 560 | "mime-db": "1.52.0" 561 | }, 562 | "engines": { 563 | "node": ">= 0.6" 564 | } 565 | }, 566 | "node_modules/ml-array-mean": { 567 | "version": "1.1.6", 568 | "resolved": "https://registry.npmjs.org/ml-array-mean/-/ml-array-mean-1.1.6.tgz", 569 | "integrity": "sha512-MIdf7Zc8HznwIisyiJGRH9tRigg3Yf4FldW8DxKxpCCv/g5CafTw0RRu51nojVEOXuCQC7DRVVu5c7XXO/5joQ==", 570 | "dependencies": { 571 | "ml-array-sum": "^1.1.6" 572 | } 573 | }, 574 | "node_modules/ml-array-sum": { 575 | "version": "1.1.6", 576 | "resolved": "https://registry.npmjs.org/ml-array-sum/-/ml-array-sum-1.1.6.tgz", 577 | "integrity": "sha512-29mAh2GwH7ZmiRnup4UyibQZB9+ZLyMShvt4cH4eTK+cL2oEMIZFnSyB3SS8MlsTh6q/w/yh48KmqLxmovN4Dw==", 578 | "dependencies": { 579 | "is-any-array": "^2.0.0" 580 | } 581 | }, 582 | "node_modules/ml-distance": { 583 | "version": "4.0.1", 584 | "resolved": "https://registry.npmjs.org/ml-distance/-/ml-distance-4.0.1.tgz", 585 | "integrity": "sha512-feZ5ziXs01zhyFUUUeZV5hwc0f5JW0Sh0ckU1koZe/wdVkJdGxcP06KNQuF0WBTj8FttQUzcvQcpcrOp/XrlEw==", 586 | "dependencies": { 587 | "ml-array-mean": "^1.1.6", 588 | "ml-distance-euclidean": "^2.0.0", 589 | "ml-tree-similarity": "^1.0.0" 590 | } 591 | }, 592 | "node_modules/ml-distance-euclidean": { 593 | "version": "2.0.0", 594 | "resolved": "https://registry.npmjs.org/ml-distance-euclidean/-/ml-distance-euclidean-2.0.0.tgz", 595 | "integrity": "sha512-yC9/2o8QF0A3m/0IXqCTXCzz2pNEzvmcE/9HFKOZGnTjatvBbsn4lWYJkxENkA4Ug2fnYl7PXQxnPi21sgMy/Q==" 596 | }, 597 | "node_modules/ml-tree-similarity": { 598 | "version": "1.0.0", 599 | "resolved": "https://registry.npmjs.org/ml-tree-similarity/-/ml-tree-similarity-1.0.0.tgz", 600 | "integrity": "sha512-XJUyYqjSuUQkNQHMscr6tcjldsOoAekxADTplt40QKfwW6nd++1wHWV9AArl0Zvw/TIHgNaZZNvr8QGvE8wLRg==", 601 | "dependencies": { 602 | "binary-search": "^1.3.5", 603 | "num-sort": "^2.0.0" 604 | } 605 | }, 606 | "node_modules/mustache": { 607 | "version": "4.2.0", 608 | "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", 609 | "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", 610 | "bin": { 611 | "mustache": "bin/mustache" 612 | } 613 | }, 614 | "node_modules/num-sort": { 615 | "version": "2.1.0", 616 | "resolved": "https://registry.npmjs.org/num-sort/-/num-sort-2.1.0.tgz", 617 | "integrity": "sha512-1MQz1Ed8z2yckoBeSfkQHHO9K1yDRxxtotKSJ9yvcTUUxSvfvzEq5GwBrjjHEpMlq/k5gvXdmJ1SbYxWtpNoVg==", 618 | "engines": { 619 | "node": ">=8" 620 | }, 621 | "funding": { 622 | "url": "https://github.com/sponsors/sindresorhus" 623 | } 624 | }, 625 | "node_modules/p-finally": { 626 | "version": "1.0.0", 627 | "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", 628 | "integrity": "sha512-LICb2p9CB7FS+0eR1oqWnHhp0FljGLZCWBE9aix0Uye9W8LTQPwMTYVGWQWIw9RdQiDg4+epXQODwIYJtSJaow==", 629 | "engines": { 630 | "node": ">=4" 631 | } 632 | }, 633 | "node_modules/p-queue": { 634 | "version": "6.6.2", 635 | "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz", 636 | "integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==", 637 | "dependencies": { 638 | "eventemitter3": "^4.0.4", 639 | "p-timeout": "^3.2.0" 640 | }, 641 | "engines": { 642 | "node": ">=8" 643 | }, 644 | "funding": { 645 | "url": "https://github.com/sponsors/sindresorhus" 646 | } 647 | }, 648 | "node_modules/p-retry": { 649 | "version": "4.6.2", 650 | "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.6.2.tgz", 651 | "integrity": "sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==", 652 | "dependencies": { 653 | "@types/retry": "0.12.0", 654 | "retry": "^0.13.1" 655 | }, 656 | "engines": { 657 | "node": ">=8" 658 | } 659 | }, 660 | "node_modules/p-timeout": { 661 | "version": "3.2.0", 662 | "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz", 663 | "integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==", 664 | "dependencies": { 665 | "p-finally": "^1.0.0" 666 | }, 667 | "engines": { 668 | "node": ">=8" 669 | } 670 | }, 671 | "node_modules/proxy-from-env": { 672 | "version": "1.1.0", 673 | "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", 674 | "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" 675 | }, 676 | "node_modules/retry": { 677 | "version": "0.13.1", 678 | "resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz", 679 | "integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==", 680 | "engines": { 681 | "node": ">= 4" 682 | } 683 | }, 684 | "node_modules/semver": { 685 | "version": "7.7.1", 686 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", 687 | "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", 688 | "bin": { 689 | "semver": "bin/semver.js" 690 | }, 691 | "engines": { 692 | "node": ">=10" 693 | } 694 | }, 695 | "node_modules/ts-node": { 696 | "version": "10.9.2", 697 | "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", 698 | "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", 699 | "dev": true, 700 | "dependencies": { 701 | "@cspotcode/source-map-support": "^0.8.0", 702 | "@tsconfig/node10": "^1.0.7", 703 | "@tsconfig/node12": "^1.0.7", 704 | "@tsconfig/node14": "^1.0.0", 705 | "@tsconfig/node16": "^1.0.2", 706 | "acorn": "^8.4.1", 707 | "acorn-walk": "^8.1.1", 708 | "arg": "^4.1.0", 709 | "create-require": "^1.1.0", 710 | "diff": "^4.0.1", 711 | "make-error": "^1.1.1", 712 | "v8-compile-cache-lib": "^3.0.1", 713 | "yn": "3.1.1" 714 | }, 715 | "bin": { 716 | "ts-node": "dist/bin.js", 717 | "ts-node-cwd": "dist/bin-cwd.js", 718 | "ts-node-esm": "dist/bin-esm.js", 719 | "ts-node-script": "dist/bin-script.js", 720 | "ts-node-transpile-only": "dist/bin-transpile.js", 721 | "ts-script": "dist/bin-script-deprecated.js" 722 | }, 723 | "peerDependencies": { 724 | "@swc/core": ">=1.2.50", 725 | "@swc/wasm": ">=1.2.50", 726 | "@types/node": "*", 727 | "typescript": ">=2.7" 728 | }, 729 | "peerDependenciesMeta": { 730 | "@swc/core": { 731 | "optional": true 732 | }, 733 | "@swc/wasm": { 734 | "optional": true 735 | } 736 | } 737 | }, 738 | "node_modules/typescript": { 739 | "version": "5.8.3", 740 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", 741 | "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", 742 | "dev": true, 743 | "bin": { 744 | "tsc": "bin/tsc", 745 | "tsserver": "bin/tsserver" 746 | }, 747 | "engines": { 748 | "node": ">=14.17" 749 | } 750 | }, 751 | "node_modules/undici-types": { 752 | "version": "6.19.8", 753 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", 754 | "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", 755 | "dev": true 756 | }, 757 | "node_modules/uuid": { 758 | "version": "9.0.1", 759 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", 760 | "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", 761 | "funding": [ 762 | "https://github.com/sponsors/broofa", 763 | "https://github.com/sponsors/ctavan" 764 | ], 765 | "bin": { 766 | "uuid": "dist/bin/uuid" 767 | } 768 | }, 769 | "node_modules/v8-compile-cache-lib": { 770 | "version": "3.0.1", 771 | "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", 772 | "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", 773 | "dev": true 774 | }, 775 | "node_modules/yn": { 776 | "version": "3.1.1", 777 | "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", 778 | "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", 779 | "dev": true, 780 | "engines": { 781 | "node": ">=6" 782 | } 783 | }, 784 | "node_modules/zod": { 785 | "version": "3.24.2", 786 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz", 787 | "integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==", 788 | "funding": { 789 | "url": "https://github.com/sponsors/colinhacks" 790 | } 791 | }, 792 | "node_modules/zod-to-json-schema": { 793 | "version": "3.24.5", 794 | "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.24.5.tgz", 795 | "integrity": "sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g==", 796 | "peerDependencies": { 797 | "zod": "^3.24.1" 798 | } 799 | } 800 | } 801 | } 802 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "langchain-llm7", 3 | "version": "2025.04.291003", 4 | "description": "LangChain integration for the LLM7 Chat API", 5 | "main": "./dist/index.js", 6 | "module": "./dist/index.js", 7 | "types": "dist/index.d.ts", 8 | "type": "module", 9 | "files": [ 10 | "dist" 11 | ], 12 | "exports": { 13 | ".": { 14 | "import": "./dist/index.js", 15 | "require": "./dist/index.js", 16 | "types": "./dist/index.d.ts" 17 | } 18 | }, 19 | "scripts": { 20 | "build": "tsc", 21 | "prepublishOnly": "npm run build" 22 | }, 23 | "repository": { 24 | "type": "git", 25 | "url": "https://github.com/chigwell/npm-langchain-llm7.git" 26 | }, 27 | "keywords": [ 28 | "langchain", 29 | "llm", 30 | "ai", 31 | "llm7" 32 | ], 33 | "author": "Eugene Evstafev ", 34 | "license": "Apache-2.0", 35 | "dependencies": { 36 | "@langchain/core": "^0.1.0", 37 | "axios": "^1.6.0", 38 | "axios-retry": "^4.0.0", 39 | "gpt-3-encoder": "^1.1.4" 40 | }, 41 | "devDependencies": { 42 | "@types/node": "^20.0.0", 43 | "ts-node": "^10.9.2", 44 | "typescript": "^5.0.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | SimpleChatModel, 3 | type BaseChatModelParams, 4 | } from "@langchain/core/language_models/chat_models"; 5 | import type { 6 | BaseMessage, 7 | MessageContentComplex, // Import the complex type 8 | MessageContentText, // Import the text part type 9 | } from "@langchain/core/messages"; 10 | import { 11 | AIMessageChunk, 12 | HumanMessage, 13 | SystemMessage, 14 | AIMessage, 15 | } from "@langchain/core/messages"; 16 | import { ChatGenerationChunk } from "@langchain/core/outputs"; 17 | import type { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager"; 18 | import axios, { AxiosInstance, AxiosError } from "axios"; 19 | import axiosRetry from "axios-retry"; 20 | // import { encode } from 'gpt-3-encoder'; // Keep commented unless needed later 21 | 22 | export interface ChatLLM7Params extends BaseChatModelParams { 23 | baseUrl?: string; 24 | modelName?: string; 25 | temperature?: number; 26 | maxTokens?: number; 27 | timeout?: number; 28 | maxRetries?: number; 29 | stop?: string[]; 30 | } 31 | 32 | type LLM7Message = { 33 | role: "user" | "assistant" | "system"; 34 | content: string; 35 | }; 36 | 37 | export class ChatLLM7 extends SimpleChatModel implements ChatLLM7Params { 38 | static lc_name() { 39 | return "ChatLLM7"; 40 | } 41 | 42 | baseUrl: string; 43 | modelName: string; 44 | temperature: number; 45 | maxTokens?: number; 46 | timeout: number; 47 | maxRetries: number; 48 | stop?: string[]; 49 | 50 | private client: AxiosInstance; 51 | 52 | constructor(fields: ChatLLM7Params = {}) { 53 | super(fields); 54 | this.baseUrl = fields.baseUrl ?? "https://api.llm7.io/v1"; 55 | this.modelName = fields.modelName ?? "gpt-4.1-nano"; 56 | this.temperature = fields.temperature ?? 1.0; 57 | this.maxTokens = fields.maxTokens; 58 | this.timeout = fields.timeout ?? 120; 59 | this.maxRetries = fields.maxRetries ?? 3; 60 | this.stop = fields.stop; 61 | 62 | this.client = axios.create({ 63 | baseURL: this.baseUrl, 64 | timeout: this.timeout * 1000, 65 | headers: { "Content-Type": "application/json" }, 66 | }); 67 | 68 | axiosRetry(this.client, { 69 | retries: this.maxRetries, 70 | retryDelay: axiosRetry.exponentialDelay, 71 | retryCondition: (error: AxiosError) => { 72 | return ( 73 | axiosRetry.isNetworkError(error) || 74 | axiosRetry.isRetryableError(error) || 75 | error.response?.status === 429 76 | ); 77 | }, 78 | }); 79 | } 80 | 81 | _llmType(): string { 82 | return "llm7-chat"; 83 | } 84 | 85 | private _formatMessages(messages: BaseMessage[]): LLM7Message[] { 86 | return messages.map((message) => { 87 | let role: LLM7Message["role"]; 88 | let content: string; 89 | 90 | // Determine role 91 | if (message._getType() === "human") { 92 | role = "user"; 93 | } else if (message._getType() === "ai") { 94 | role = "assistant"; 95 | } else if (message._getType() === "system") { 96 | role = "system"; 97 | } else { 98 | throw new Error(`Unsupported message type: ${message._getType()}`); 99 | } 100 | 101 | // Handle content: string | MessageContentComplex[] 102 | if (typeof message.content === "string") { 103 | content = message.content; 104 | } else if (Array.isArray(message.content)) { 105 | // --- Fix for Error 1 --- 106 | // Filter out non-text parts and concatenate text content 107 | const textParts = message.content 108 | .filter((part): part is MessageContentText => part.type === "text") 109 | .map(part => part.text); 110 | 111 | if (textParts.length === 0) { 112 | console.warn(`Message content array did not contain any text parts: ${JSON.stringify(message.content)}`); 113 | content = ""; // Or throw an error if empty text messages are invalid 114 | } else { 115 | content = textParts.join("\n"); // Join text parts, e.g., with newline 116 | } 117 | // Warn if non-text parts were present and ignored 118 | if (textParts.length < message.content.length) { 119 | console.warn(`Ignoring non-text parts in message content for role ${role}. LLM7 only supports text.`); 120 | } 121 | } else { 122 | throw new Error( 123 | `Unsupported message content type: ${typeof message.content}` 124 | ); 125 | } 126 | 127 | return { role, content }; 128 | }); 129 | } 130 | 131 | /** 132 | * Internal method to construct the API request payload. 133 | * @param messages A list of LangChain BaseMessage objects. 134 | * @param stream Whether the request is for streaming. 135 | * @param runtimeStop Optional list of stop sequences passed at runtime. 136 | * @returns The payload object for the LLM7 API request. 137 | */ 138 | // --- Updated signature and logic for Errors 2 & 3 --- 139 | private _createPayload( 140 | messages: BaseMessage[], 141 | stream: boolean, 142 | runtimeStop?: string[] 143 | ): Record { // Explicitly return Record 144 | const payload: Record = { 145 | model: this.modelName, 146 | messages: this._formatMessages(messages), 147 | temperature: this.temperature, 148 | stream: stream, 149 | }; 150 | 151 | if (this.maxTokens !== undefined) { 152 | payload.max_tokens = this.maxTokens; 153 | } 154 | 155 | // Combine constructor stop sequences and runtime stop sequences 156 | const stopSequences = [...(this.stop ?? []), ...(runtimeStop ?? [])]; 157 | if (stopSequences.length > 0) { 158 | // Use a Set to remove duplicates, then convert back to array 159 | payload.stop = Array.from(new Set(stopSequences)); 160 | } 161 | 162 | return payload; 163 | } 164 | 165 | async _call( 166 | messages: BaseMessage[], 167 | options: this["ParsedCallOptions"], 168 | runManager?: CallbackManagerForLLMRun 169 | ): Promise { 170 | // --- Updated call to _createPayload for Errors 2 & 3 --- 171 | const payload = this._createPayload(messages, false, options.stop); 172 | 173 | try { 174 | const response = await this.client.post( 175 | "/chat/completions", 176 | payload, 177 | { signal: options.signal } 178 | ); 179 | 180 | if (response.status !== 200) { 181 | throw new Error( 182 | `API request failed with status ${response.status}: ${response.statusText} - ${response.data}` 183 | ); 184 | } 185 | 186 | const responseData = response.data; 187 | if (!responseData.choices?.[0]?.message) { 188 | throw new Error(`Invalid API response format: ${JSON.stringify(responseData)}`); 189 | } 190 | 191 | return responseData.choices[0].message.content; 192 | } catch (error) { 193 | runManager?.handleLLMError(error); 194 | if (axios.isAxiosError(error)) { 195 | throw new Error( 196 | `LLM7 API request error: ${error.message} - ${error.response?.status} ${error.response?.data}` 197 | ); 198 | } 199 | throw error; 200 | } 201 | } 202 | 203 | async *_streamResponseChunks( 204 | messages: BaseMessage[], 205 | options: this["ParsedCallOptions"], 206 | runManager?: CallbackManagerForLLMRun 207 | ): AsyncGenerator { 208 | // --- Updated call to _createPayload for Errors 2 & 3 --- 209 | const payload = this._createPayload(messages, true, options.stop); 210 | 211 | let responseStream; 212 | try { 213 | const response = await this.client.post( 214 | "/chat/completions", 215 | payload, 216 | { responseType: "stream", signal: options.signal } 217 | ); 218 | 219 | if (response.status !== 200) { 220 | let errorBody = ''; 221 | try { for await (const chunk of response.data) { errorBody += chunk.toString(); } } catch (e) {/* Ignore */} 222 | throw new Error(`API request failed with status ${response.status}: ${response.statusText} - ${errorBody}`); 223 | } 224 | responseStream = response.data; 225 | } catch (error) { 226 | runManager?.handleLLMError(error); 227 | if (axios.isAxiosError(error)) { 228 | throw new Error(`LLM7 API stream request error: ${error.message} - ${error.response?.status} ${error.response?.data}`); 229 | } 230 | throw error; 231 | } 232 | 233 | let buffer = ""; 234 | try { 235 | for await (const chunk of responseStream) { 236 | buffer += chunk.toString("utf-8"); 237 | let newlineIndex; 238 | while ((newlineIndex = buffer.indexOf("\n")) !== -1) { 239 | const line = buffer.substring(0, newlineIndex).trim(); 240 | buffer = buffer.substring(newlineIndex + 1); 241 | 242 | if (line === "" || !line.startsWith("data:")) continue; 243 | const jsonData = line.substring("data: ".length); 244 | if (jsonData === "[DONE]") return; 245 | 246 | try { 247 | const parsedChunk = JSON.parse(jsonData); 248 | const delta = parsedChunk.choices?.[0]?.delta; 249 | const content = delta?.content; 250 | 251 | if (typeof content === "string" && content !== "") { 252 | const generationChunk = new ChatGenerationChunk({ 253 | message: new AIMessageChunk({ content: content }), 254 | text: content, 255 | }); 256 | yield generationChunk; 257 | // --- Fix for Error --- 258 | // Use the simplest signature, passing only the token string. 259 | await runManager?.handleLLMNewToken(content); 260 | } 261 | } catch (e) { 262 | console.warn(`Failed to parse stream chunk JSON: ${jsonData}`, e); 263 | } 264 | } 265 | } 266 | } catch (error) { 267 | runManager?.handleLLMError(error); 268 | throw new Error(`Error processing LLM7 stream: ${error}`); 269 | } finally { 270 | if (responseStream && typeof responseStream.destroy === 'function') { 271 | responseStream.destroy(); 272 | } 273 | } 274 | if (buffer.trim() !== "") { 275 | console.warn("Streaming finished with unprocessed buffer content:", buffer); 276 | } 277 | } 278 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "NodeNext", 5 | "moduleResolution": "NodeNext", 6 | "declaration": true, 7 | "outDir": "./dist", 8 | "rootDir": "./src", 9 | "strict": true, 10 | "esModuleInterop": true, 11 | "skipLibCheck": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "lib": ["ES2022", "DOM"] 14 | }, 15 | "include": ["src/**/*"], 16 | "exclude": ["node_modules", "dist"] 17 | } --------------------------------------------------------------------------------