├── .github ├── FUNDING.yml └── workflows │ └── dependency-review.yml ├── LICENSE ├── README.md ├── index.js ├── main.js ├── main.ts ├── package-lock.json ├── package.json ├── promise.js ├── promise.ts └── tsconfig.json /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [yandricr] 2 | ko_fi: yandricr 3 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Dependency Review Action 2 | # 3 | # This Action will scan dependency manifest files that change as part of a Pull Request, 4 | # surfacing known-vulnerable versions of the packages declared or updated in the PR. 5 | # Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable 6 | # packages will be blocked from merging. 7 | # 8 | # Source repository: https://github.com/actions/dependency-review-action 9 | # Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement 10 | name: 'Dependency review' 11 | on: 12 | pull_request: 13 | branches: [ "main" ] 14 | 15 | # If using a dependency submission action in this workflow this permission will need to be set to: 16 | # 17 | # permissions: 18 | # contents: write 19 | # 20 | # https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api 21 | permissions: 22 | contents: read 23 | # Write permissions for pull-requests are required for using the `comment-summary-in-pr` option, comment out if you aren't using this option 24 | pull-requests: write 25 | 26 | jobs: 27 | dependency-review: 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: 'Checkout repository' 31 | uses: actions/checkout@v4 32 | - name: 'Dependency Review' 33 | uses: actions/dependency-review-action@v4 34 | # Commonly enabled options, see https://github.com/actions/dependency-review-action#configuration-options for all available options. 35 | with: 36 | comment-summary-in-pr: always 37 | # fail-on-severity: moderate 38 | # deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later 39 | # retry-on-snapshot-warnings: true 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 yandricr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # GPTI 3 | 4 | ![npm](https://img.shields.io/npm/dw/gpti?style=for-the-badge) ![License](https://img.shields.io/npm/l/gpti?style=for-the-badge) [![Contributors](https://img.shields.io/github/contributors/yandricr/gpti-js?style=for-the-badge)](https://github.com/yandricr/gpti-js/graphs/contributors) [![Size Package](https://img.shields.io/github/languages/code-size/yandricr/gpti-js?style=for-the-badge)](https://github.com/yandricr/gpti-js) ![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E) ![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white) 5 | 6 | 7 | This package simplifies your interaction with various GPT models, eliminating the need for tokens or other methods to access GPT. It also allows you to use three artificial intelligences to generate images: DALL·E, Prodia, and more, some of which are premium while others are free, all of this without restrictions or limits. 8 | 9 | ## Installation 10 | 11 | You can install the package via NPM 12 | 13 | ```bash 14 | npm i gpti 15 | ``` 16 | 17 | ## Buy code 18 | 19 | Purchase my API code through [Patreon](https://www.patreon.com/yandricr) and use it without limitations on any model, hassle-free and with no restrictions. 20 | 21 | ## Available Models 22 | 23 | GPTI provides access to a variety of artificial intelligence models to meet various needs. Currently, the available models include: 24 | 25 | - [**ChatGPT**](#gpt) 26 | - [**GPT-3.5-Turbo**](#gpt-v2) 27 | - [**ChatGPT Web**](#gptweb) 28 | - [**GPT-4o**](#gpt-4o) 29 | - [**Bing**](#bing) 30 | - [**LLaMA-3.1**](#llama-3.1) 31 | - [**Blackbox**](#blackbox) 32 | - [**AI Images**](#ai-images) 33 | 34 | ## Api key 35 | 36 | If you want to access the premium models, enter your credentials. You can obtain them by [clicking here](https://nexra.aryahcr.cc/api-key/en). 37 | 38 | ```js 39 | // import { nexra } from "gpti"; 40 | // const { nexra } = require("gpti"); 41 | 42 | const { nexra } = require("gpti"); 43 | 44 | nexra("user-xxxxxxxx", "nx-xxxxxxx-xxxxx-xxxxx"); 45 | ``` 46 | 47 | 48 | ## Usage GPT 49 | 50 | ```javascript 51 | // import { gpt } from "gpti"; 52 | const { gpt } = require("gpti"); 53 | 54 | let data = await gpt.v1({ 55 | messages: [ 56 | { 57 | role: "assistant", 58 | content: "Hello! How are you today?" 59 | }, 60 | { 61 | role: "user", 62 | content: "Hello, my name is Yandri." 63 | }, 64 | { 65 | role: "assistant", 66 | content: "Hello, Yandri! How are you today?" 67 | } 68 | ], 69 | prompt: "Can you repeat my name?", 70 | model: "GPT-4", 71 | markdown: false 72 | }); 73 | 74 | console.log(data); 75 | ``` 76 | 77 | #### Models 78 | 79 | Select one of these available models in the API to enhance your experience. 80 | 81 | - gpt-4 82 | - gpt-4-0613 83 | - gpt-4-32k 84 | - gpt-4-0314 85 | - gpt-4-32k-0314 86 | - gpt-3.5-turbo 87 | - gpt-3.5-turbo-16k 88 | - gpt-3.5-turbo-0613 89 | - gpt-3.5-turbo-16k-0613 90 | - gpt-3.5-turbo-0301 91 | - text-davinci-003 92 | - text-davinci-002 93 | - code-davinci-002 94 | - gpt-3 95 | - text-curie-001 96 | - text-babbage-001 97 | - text-ada-001 98 | - davinci 99 | - curie 100 | - babbage 101 | - ada 102 | - babbage-002 103 | - davinci-002 104 | 105 | 106 | ## Usage GPT v2 107 | 108 | It's quite similar, with the difference that it has the capability to generate real-time responses via streaming using gpt-3.5-turbo. 109 | 110 | ```javascript 111 | // import { gpt } from "gpti"; 112 | const { gpt } = require("gpti"); 113 | 114 | let messages = [ 115 | { 116 | "role": "assistant", 117 | "content": "Hello! How are you today?" 118 | }, 119 | { 120 | "role": "user", 121 | "content": "Hello, my name is Yandri." 122 | }, 123 | { 124 | "role": "assistant", 125 | "content": "Hello, Yandri! How are you today?" 126 | }, 127 | { 128 | "role": "user", 129 | "content": "Can you repeat my name?" 130 | } 131 | ]; 132 | 133 | let data = await gpt.v2({ 134 | messages: messages, 135 | markdown: false, 136 | stream: false 137 | }); 138 | 139 | console.log(data); 140 | 141 | /* 142 | // Streaming 143 | 144 | gpt.v2({ 145 | messages: messages, 146 | stream: true, 147 | markdown: false, 148 | results: (err, data) => { 149 | console.log(err, data); 150 | } 151 | }); 152 | */ 153 | ``` 154 | 155 | 156 | ## Usage GPT Web 157 | 158 | GPT-4 has been enhanced by me, but errors may arise due to technological complexity. It is advisable to exercise caution when relying entirely on its accuracy for online queries. 159 | 160 | ```javascript 161 | // import { gpt } from "gpti"; 162 | const { gpt } = require("gpti"); 163 | 164 | let data = await gpt.web({ 165 | prompt: "Are you familiar with the movie Wonka released in 2023?", 166 | markdown: false 167 | }); 168 | 169 | console.log(data); 170 | ``` 171 | 172 | 173 | ## Usage GPT-4o 174 | 175 | ```javascript 176 | // import { gpt } from "gpti"; 177 | const { gpt } = require("gpti"); 178 | 179 | let history = [ 180 | { 181 | "role": "user", 182 | "content": "Hello! How are you? Could you tell me your name?" 183 | } 184 | ]; 185 | 186 | let data = await gpt.v3({ 187 | messages: history, 188 | markdown: false, 189 | stream: false 190 | }); 191 | 192 | console.log(data); 193 | 194 | /* 195 | // Streaming 196 | 197 | gpt.v3({ 198 | messages: history, 199 | stream: true, 200 | markdown: false, 201 | results: (err, data) => { 202 | console.log(err, data); 203 | } 204 | }); 205 | */ 206 | ``` 207 | 208 | 209 | ## Usage Bing 210 | 211 | ```javascript 212 | // import { bing } from "gpti"; 213 | const { bing } = require("gpti"); 214 | 215 | let history = [ 216 | { 217 | role: "assistant", 218 | content: "Hello! How can I help you today? 😊" 219 | }, 220 | { 221 | role: "user", 222 | content: "Hi, tell me the names of the movies released in 2023." 223 | }, 224 | { 225 | role: "assistant", 226 | content: "Certainly! Here are some movies that were released in 2023:\n\n1. **About My Father** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n2. **The Little Mermaid** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n3. **Fast X** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n4. **Spider-Man: Across the Spider-Verse** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n5. **The Machine** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n6. **Book Club: The Next Chapter** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n7. **Guardians of the Galaxy Vol. 3** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n8. **John Wick: Chapter 4** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n9. **Are You There God? It's Me, Margaret** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n10. **Evil Dead Rise** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n11. **The Super Mario Bros. Movie** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n12. **Love Again** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n13. **Kandahar** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n14. **Dungeons & Dragons: Honor Among Thieves** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n15. **Shin Kamen Rider** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n16. **Knights of the Zodiac** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n17. **The Pope's Exorcist** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n18. **Shazam! Fury of the Gods** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n19. **All That Breathes** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n20. **Sailor Moon Cosmos** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n21. **Hypnotic** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n22. **Sound of Freedom** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n23. **The Boogeyman** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n24. **Chicken Run: Dawn of the Nugget** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n25. **A Lot of Nothing** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n26. **Followers** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n27. **Big George Foreman** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n28. **Asterix & Obelix: The Middle Kingdom** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n29. **Ant-Man and the Wasp: Quantumania** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n30. **Transformers: Rise of the Beasts** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n31. **Follow Her** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n32. **Prom Pact** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n33. **God Is a Bullet** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n34. **Still: A Michael J. Fox Movie** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n35. **Nefarious** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n36. **Nanny Dearest** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n37. **Monica** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n38. **Wild Life** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n39. **Palm Trees and Power Lines** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n40. **What's Love Got to Do with It?** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n41. **Creed III** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n42. **One True Loves** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n43. **BlackBerry** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n44. **Suzume** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n45. **Rock Dog 3: Battle the Beat** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n46. **Gridman Universe** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n47. **Digimon Adventure 02: The Beginning** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n48. **Woman of the Photographs** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n49. **El Tonto** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n50. **Seriously Red** [^1^](https://editorial.rottentomatoes.com/guide/best-movies-of-2023/)\n\nI hope this helps! Let me know if you have any other questions." 227 | }, 228 | { 229 | role: "user", 230 | content: "Can you tell me how many movies you've told me about?" 231 | } 232 | ]; 233 | 234 | let data = await bing({ 235 | messages: history, 236 | conversation_style: "Balanced", 237 | markdown: false, 238 | stream: false 239 | }); 240 | 241 | console.log(data); 242 | 243 | /* 244 | // Streaming 245 | 246 | bing({ 247 | messages: history, 248 | conversation_style: "Balanced", 249 | stream: true, 250 | markdown: false, 251 | results: (err, data) => { 252 | console.log(err, data); 253 | } 254 | }); 255 | */ 256 | ``` 257 | 258 | #### Parameters 259 | 260 | | Parameter | Default | Description | 261 | |--------------------|----------|---------------------------------------------------------------------------------------------------------| 262 | | conversation_style | Balanced | You can use between: "Balanced", "Creative" and "Precise" | 263 | | markdown | false | You can convert the dialogues into continuous streams or not into Markdown | 264 | | stream | false | You are given the option to choose whether you prefer the responses to be in real-time or not | 265 | 266 | 267 | ## Usage LLaMA 3.1 268 | 269 | ```javascript 270 | // import { llama } from "gpti"; 271 | const { llama } = require("gpti"); 272 | 273 | let history = [ 274 | { 275 | "role": "user", 276 | "content": "Hello! How are you? Could you tell me your name?" 277 | } 278 | ]; 279 | 280 | let data = await llama({ 281 | messages: history, 282 | markdown: false, 283 | stream: false 284 | }); 285 | 286 | console.log(data); 287 | 288 | /* 289 | // Streaming 290 | 291 | llama({ 292 | messages: history, 293 | stream: true, 294 | markdown: false, 295 | results: (err, data) => { 296 | console.log(err, data); 297 | } 298 | }); 299 | */ 300 | ``` 301 | 302 | 303 | ## Usage Blackbox 304 | 305 | ```javascript 306 | // import { blackbox } from "gpti"; 307 | const { blackbox } = require("gpti"); 308 | 309 | let history = [ 310 | { 311 | "role": "user", 312 | "content": "Hello! How are you? Could you tell me your name?" 313 | } 314 | ]; 315 | 316 | let data = await blackbox({ 317 | messages: history, 318 | markdown: false, 319 | stream: false 320 | }); 321 | 322 | console.log(data); 323 | 324 | /* 325 | // Streaming 326 | 327 | blackbox({ 328 | messages: history, 329 | stream: true, 330 | markdown: false, 331 | results: (err, data) => { 332 | console.log(err, data); 333 | } 334 | }); 335 | */ 336 | ``` 337 | 338 | 339 | ## AI Images 340 | 341 | Check the documentation [here](https://nexra.aryahcr.cc/documentation/en) to learn how to use the different image generation models. 342 | 343 | ```javascript 344 | // import { imageai } from "gpti"; 345 | const { imageai } = require("gpti"); 346 | 347 | let data = await imageai({ 348 | prompt: "cat color red", 349 | model: "dalle", 350 | response: "url" | "base64", 351 | data: {} 352 | }); 353 | 354 | console.log(data); 355 | ``` 356 | 357 | ## API Reference 358 | 359 | Currently, some models require your credentials to access them, while others are free. For more details and examples, please refer to the complete [documentation](https://nexra.aryahcr.cc/). 360 | 361 | #### Code Errors 362 | 363 | These are the error codes that will be presented in case the API fails. 364 | 365 | | Code | Error | Description | 366 | |------|----------------------:|------------------------------------------------| 367 | | 400 | BAD_REQUEST | Not all parameters have been entered correctly | 368 | | 500 | INTERNAL_SERVER_ERROR | The server has experienced failures | 369 | | 200 | | The API worked without issues | 370 | | 403 | FORBIDDEN | The API credentials are not valid | 371 | | 401 | UNAUTHORIZED | API credentials are required | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { 2 | nexra, 3 | gpt, 4 | bing, 5 | llama, 6 | blackbox, 7 | imageai 8 | } = require("./main"); 9 | 10 | module.exports = { 11 | nexra, 12 | gpt, 13 | bing, 14 | llama, 15 | blackbox, 16 | imageai 17 | } -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | /* 3 | Author: yandricr 4 | API: https://nexra.aryahcr.cc/ 5 | */ 6 | var __assign = (this && this.__assign) || function () { 7 | __assign = Object.assign || function(t) { 8 | for (var s, i = 1, n = arguments.length; i < n; i++) { 9 | s = arguments[i]; 10 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) 11 | t[p] = s[p]; 12 | } 13 | return t; 14 | }; 15 | return __assign.apply(this, arguments); 16 | }; 17 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 18 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 19 | return new (P || (P = Promise))(function (resolve, reject) { 20 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 21 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 22 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 23 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 24 | }); 25 | }; 26 | var __generator = (this && this.__generator) || function (thisArg, body) { 27 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 28 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 29 | function verb(n) { return function (v) { return step([n, v]); }; } 30 | function step(op) { 31 | if (f) throw new TypeError("Generator is already executing."); 32 | while (g && (g = 0, op[0] && (_ = 0)), _) try { 33 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 34 | if (y = 0, t) op = [op[0] & 2, t.value]; 35 | switch (op[0]) { 36 | case 0: case 1: t = op; break; 37 | case 4: _.label++; return { value: op[1], done: false }; 38 | case 5: _.label++; y = op[1]; op = [0]; continue; 39 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 40 | default: 41 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 42 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 43 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 44 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 45 | if (t[2]) _.ops.pop(); 46 | _.trys.pop(); continue; 47 | } 48 | op = body.call(thisArg, _); 49 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 50 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 51 | } 52 | }; 53 | Object.defineProperty(exports, "__esModule", { value: true }); 54 | exports.imageai = exports.blackbox = exports.llama = exports.bing = exports.gpt = exports.nexra = void 0; 55 | var axios_1 = require("axios"); 56 | /* types */ 57 | var sleep = function (n) { return __awaiter(void 0, void 0, void 0, function () { 58 | return __generator(this, function (_a) { 59 | return [2 /*return*/, new Promise(function (res) { 60 | try { 61 | setTimeout(function () { 62 | return res("OK"); 63 | }, n); 64 | } 65 | catch (error) { 66 | return res("OK"); 67 | } 68 | })]; 69 | }); 70 | }); }; 71 | var cred = { 72 | "x-nexra-user": null, 73 | "x-nexra-secret": null 74 | }; 75 | var nexra = function (user, secret) { 76 | cred["x-nexra-secret"] = secret; 77 | cred["x-nexra-user"] = user; 78 | }; 79 | exports.nexra = nexra; 80 | function consult_(api, data) { 81 | return __awaiter(this, void 0, void 0, function () { 82 | var _this = this; 83 | return __generator(this, function (_a) { 84 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () { 85 | var request, id, response, data_, result, success_, error_1; 86 | return __generator(this, function (_a) { 87 | switch (_a.label) { 88 | case 0: 89 | _a.trys.push([0, 6, , 7]); 90 | return [4 /*yield*/, axios_1.default.post(api, data, { 91 | headers: __assign({ "Content-Type": "application/json" }, cred) 92 | })]; 93 | case 1: 94 | request = _a.sent(); 95 | if (request.status != 200) { 96 | throw new Error("error"); 97 | } 98 | id = request.data.id; 99 | response = null; 100 | data_ = true; 101 | result = null; 102 | success_ = false; 103 | _a.label = 2; 104 | case 2: 105 | if (!data_) return [3 /*break*/, 5]; 106 | return [4 /*yield*/, sleep(1000)]; 107 | case 3: 108 | _a.sent(); 109 | return [4 /*yield*/, axios_1.default.get('https://nexra.aryahcr.cc/api/chat/task/' + encodeURIComponent(id))]; 110 | case 4: 111 | response = _a.sent(); 112 | response = response.data; 113 | switch (response.status) { 114 | case "pending": 115 | data_ = true; 116 | break; 117 | case "error": 118 | case "completed": 119 | success_ = true; 120 | result = response; 121 | case "not_found": 122 | default: 123 | result = response; 124 | data_ = false; 125 | break; 126 | } 127 | return [3 /*break*/, 2]; 128 | case 5: 129 | if (result === undefined || result === null) { 130 | throw new Error("error"); 131 | } 132 | if (success_ === false) { 133 | return [2 /*return*/, rej(result)]; 134 | } 135 | else { 136 | return [2 /*return*/, res(result)]; 137 | } 138 | return [3 /*break*/, 7]; 139 | case 6: 140 | error_1 = _a.sent(); 141 | try { 142 | if (error_1.response) { 143 | if (typeof error_1.response.data === "object") { 144 | return [2 /*return*/, rej(error_1.response.data)]; 145 | } 146 | else { 147 | throw new Error("error"); 148 | } 149 | } 150 | else if (error_1.request) { 151 | return [2 /*return*/, rej({ 152 | "code": 404, 153 | "error": "NOT_FOUND", 154 | "message": "the service is currently unavailable" 155 | })]; 156 | } 157 | else { 158 | return [2 /*return*/, rej({ 159 | "code": 500, 160 | "error": "INTERNAL_SERVER_ERROR", 161 | "message": "general (unknown) error" 162 | })]; 163 | } 164 | } 165 | catch (e) { 166 | return [2 /*return*/, rej({ 167 | "code": 500, 168 | "error": "INTERNAL_SERVER_ERROR", 169 | "message": "general (unknown) error" 170 | })]; 171 | } 172 | return [3 /*break*/, 7]; 173 | case 7: return [2 /*return*/]; 174 | } 175 | }); 176 | }); })]; 177 | }); 178 | }); 179 | } 180 | function consult_img(data) { 181 | return __awaiter(this, void 0, void 0, function () { 182 | var _this = this; 183 | return __generator(this, function (_a) { 184 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () { 185 | var request, id, response, data_, result, success_, error_2; 186 | return __generator(this, function (_a) { 187 | switch (_a.label) { 188 | case 0: 189 | _a.trys.push([0, 6, , 7]); 190 | return [4 /*yield*/, axios_1.default.post("https://nexra.aryahcr.cc/api/image/complements", data, { 191 | headers: __assign({ "Content-Type": "application/json" }, cred) 192 | })]; 193 | case 1: 194 | request = _a.sent(); 195 | if (request.status != 200) { 196 | throw new Error("error"); 197 | } 198 | id = request.data.id; 199 | response = null; 200 | data_ = true; 201 | result = null; 202 | success_ = false; 203 | _a.label = 2; 204 | case 2: 205 | if (!data_) return [3 /*break*/, 5]; 206 | return [4 /*yield*/, sleep(1000)]; 207 | case 3: 208 | _a.sent(); 209 | return [4 /*yield*/, axios_1.default.get('https://nexra.aryahcr.cc/api/image/complements/' + encodeURIComponent(id))]; 210 | case 4: 211 | response = _a.sent(); 212 | response = response.data; 213 | switch (response.status) { 214 | case "pending": 215 | data_ = true; 216 | break; 217 | case "error": 218 | case "completed": 219 | success_ = true; 220 | result = response; 221 | case "not_found": 222 | default: 223 | result = response; 224 | data_ = false; 225 | break; 226 | } 227 | return [3 /*break*/, 2]; 228 | case 5: 229 | if (result === undefined || result === null) { 230 | throw new Error("error"); 231 | } 232 | if (success_ === false) { 233 | return [2 /*return*/, rej(result)]; 234 | } 235 | else { 236 | return [2 /*return*/, res(result)]; 237 | } 238 | return [3 /*break*/, 7]; 239 | case 6: 240 | error_2 = _a.sent(); 241 | try { 242 | if (error_2.response) { 243 | if (typeof error_2.response.data === "object") { 244 | return [2 /*return*/, rej(error_2.response.data)]; 245 | } 246 | else { 247 | throw new Error("error"); 248 | } 249 | } 250 | else if (error_2.request) { 251 | return [2 /*return*/, rej({ 252 | "code": 404, 253 | "error": "NOT_FOUND", 254 | "message": "the service is currently unavailable" 255 | })]; 256 | } 257 | else { 258 | return [2 /*return*/, rej({ 259 | "code": 500, 260 | "error": "INTERNAL_SERVER_ERROR", 261 | "message": "general (unknown) error" 262 | })]; 263 | } 264 | } 265 | catch (e) { 266 | return [2 /*return*/, rej({ 267 | "code": 500, 268 | "error": "INTERNAL_SERVER_ERROR", 269 | "message": "general (unknown) error" 270 | })]; 271 | } 272 | return [3 /*break*/, 7]; 273 | case 7: return [2 /*return*/]; 274 | } 275 | }); 276 | }); })]; 277 | }); 278 | }); 279 | } 280 | function consult_strm(api, data, process) { 281 | return __awaiter(this, void 0, void 0, function () { 282 | var response, chat_1, error_4, tmp_1, error_3, err_1; 283 | return __generator(this, function (_a) { 284 | switch (_a.label) { 285 | case 0: 286 | _a.trys.push([0, 2, , 3]); 287 | return [4 /*yield*/, axios_1.default.post(api, __assign(__assign({}, data), { "stream": true }), { 288 | headers: __assign({ "Content-Type": "application/json" }, cred), 289 | responseType: "stream" 290 | })]; 291 | case 1: 292 | response = _a.sent(); 293 | if (response.status === 200) { 294 | chat_1 = null; 295 | error_4 = false; 296 | tmp_1 = null; 297 | response.data.on("data", function (chunk) { 298 | var chk = chunk.toString(); 299 | chk = chk.split(""); 300 | chk.forEach(function (data) { 301 | var result = null; 302 | var convert = ""; 303 | try { 304 | convert = JSON.parse(data); 305 | result = data; 306 | tmp_1 = null; 307 | } 308 | catch (e) { 309 | if (tmp_1 === null) { 310 | tmp_1 = data; 311 | } 312 | else { 313 | try { 314 | convert = JSON.parse(tmp_1); 315 | result = tmp_1; 316 | tmp_1 = null; 317 | } 318 | catch (e) { 319 | tmp_1 = tmp_1 + data; 320 | try { 321 | convert = JSON.parse(tmp_1); 322 | result = tmp_1; 323 | tmp_1 = null; 324 | } 325 | catch (e) { 326 | tmp_1 = tmp_1; 327 | } 328 | } 329 | } 330 | } 331 | if (result != null) { 332 | try { 333 | result = JSON.parse(result); 334 | if (chat_1 === null && result != null) { 335 | chat_1 = ""; 336 | } 337 | if (result != undefined && result != null && result.code === undefined && result.status === undefined) { 338 | if (error_4 != true) { 339 | if (result != undefined && result != null && result.finish != undefined && result.finish != null && result.finish === true) { 340 | chat_1 = result; 341 | } 342 | else { 343 | chat_1 = result; 344 | process(null, result); 345 | } 346 | } 347 | } 348 | else { 349 | error_4 = true; 350 | chat_1 = result; 351 | } 352 | } 353 | catch (e) { 354 | // continue 355 | } 356 | } 357 | }); 358 | }); 359 | response.data.on("end", function () { 360 | if (chat_1 != null) { 361 | if (error_4 != true) { 362 | return process(null, chat_1); 363 | } 364 | else { 365 | return process(chat_1, null); 366 | } 367 | } 368 | else { 369 | return process({ 370 | "code": 500, 371 | "status": false, 372 | "error": "INTERNAL_SERVER_ERROR", 373 | "message": "general (unknown) error" 374 | }, null); 375 | } 376 | }); 377 | response.data.on("error", function (err) { 378 | }); 379 | } 380 | else { 381 | return [2 /*return*/, process({ 382 | "code": 500, 383 | "status": false, 384 | "error": "INTERNAL_SERVER_ERROR", 385 | "message": "general (unknown) error" 386 | }, null)]; 387 | } 388 | return [3 /*break*/, 3]; 389 | case 2: 390 | error_3 = _a.sent(); 391 | try { 392 | if (error_3.response) { 393 | try { 394 | err_1 = null; 395 | error_3.response.data.on("data", function (chk) { 396 | if (err_1 != null) { 397 | err_1 += chk.toString(); 398 | } 399 | else { 400 | err_1 = chk.toString(); 401 | } 402 | }); 403 | error_3.response.data.on("end", function () { 404 | try { 405 | err_1 = JSON.parse(err_1); 406 | return process(err_1, null); 407 | } 408 | catch (error) { 409 | return process({ 410 | "code": 500, 411 | "status": false, 412 | "error": "INTERNAL_SERVER_ERROR", 413 | "message": "general (unknown) error" 414 | }, null); 415 | } 416 | }); 417 | error_3.response.data.on("error", function () { 418 | }); 419 | } 420 | catch (error) { 421 | return [2 /*return*/, process({ 422 | "code": 500, 423 | "status": false, 424 | "error": "INTERNAL_SERVER_ERROR", 425 | "message": "general (unknown) error" 426 | }, null)]; 427 | } 428 | } 429 | else if (error_3.request) { 430 | return [2 /*return*/, process({ 431 | "code": 404, 432 | "error": "NOT_FOUND", 433 | "message": "the service is currently unavailable" 434 | }, null)]; 435 | } 436 | else { 437 | return [2 /*return*/, process({ 438 | "code": 500, 439 | "status": false, 440 | "error": "INTERNAL_SERVER_ERROR", 441 | "message": "general (unknown) error" 442 | }, null)]; 443 | } 444 | } 445 | catch (error) { 446 | return [2 /*return*/, process({ 447 | "code": 500, 448 | "status": false, 449 | "error": "INTERNAL_SERVER_ERROR", 450 | "message": "general (unknown) error" 451 | }, null)]; 452 | } 453 | return [3 /*break*/, 3]; 454 | case 3: return [2 /*return*/]; 455 | } 456 | }); 457 | }); 458 | } 459 | var gpt = /** @class */ (function () { 460 | function gpt() { 461 | } 462 | gpt.v1 = function (_a) { 463 | return __awaiter(this, arguments, void 0, function (_b) { 464 | var _this = this; 465 | var _c = _b.prompt, prompt = _c === void 0 ? "" : _c, _d = _b.messages, messages = _d === void 0 ? [] : _d, _e = _b.model, model = _e === void 0 ? "" : _e, _f = _b.markdown, markdown = _f === void 0 ? false : _f; 466 | return __generator(this, function (_g) { 467 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () { 468 | var response, error_5; 469 | return __generator(this, function (_a) { 470 | switch (_a.label) { 471 | case 0: 472 | _a.trys.push([0, 2, , 3]); 473 | return [4 /*yield*/, consult_("https://nexra.aryahcr.cc/api/chat/gpt", { 474 | messages: messages, 475 | prompt: prompt, 476 | model: model, 477 | markdown: markdown 478 | })]; 479 | case 1: 480 | response = _a.sent(); 481 | return [2 /*return*/, res(response)]; 482 | case 2: 483 | error_5 = _a.sent(); 484 | if (typeof error_5 === "object") { 485 | return [2 /*return*/, rej(error_5)]; 486 | } 487 | else { 488 | return [2 /*return*/, rej({ 489 | "code": 500, 490 | "status": false, 491 | "error": "INTERNAL_SERVER_ERROR", 492 | "message": "general (unknown) error" 493 | })]; 494 | } 495 | return [3 /*break*/, 3]; 496 | case 3: return [2 /*return*/]; 497 | } 498 | }); 499 | }); })]; 500 | }); 501 | }); 502 | }; 503 | gpt.v2 = function (_a) { 504 | return __awaiter(this, arguments, void 0, function (_b) { 505 | var stream_; 506 | var _this = this; 507 | var _c = _b.messages, messages = _c === void 0 ? [] : _c, _d = _b.markdown, markdown = _d === void 0 ? false : _d, _e = _b.stream, stream = _e === void 0 ? false : _e, _f = _b.results, results = _f === void 0 ? function () { } : _f; 508 | return __generator(this, function (_g) { 509 | stream_ = false; 510 | try { 511 | if (stream === true) { 512 | stream_ = true; 513 | } 514 | else { 515 | throw new Error("error"); 516 | } 517 | } 518 | catch (error) { 519 | stream_ = false; 520 | } 521 | if (stream_ === false) { 522 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () { 523 | var response, error_6; 524 | return __generator(this, function (_a) { 525 | switch (_a.label) { 526 | case 0: 527 | _a.trys.push([0, 2, , 3]); 528 | return [4 /*yield*/, consult_("https://nexra.aryahcr.cc/api/chat/complements", { 529 | messages: messages, 530 | markdown: markdown, 531 | stream: false, 532 | model: "chatgpt" 533 | })]; 534 | case 1: 535 | response = _a.sent(); 536 | return [2 /*return*/, res(response)]; 537 | case 2: 538 | error_6 = _a.sent(); 539 | if (typeof error_6 === "object") { 540 | return [2 /*return*/, rej(error_6)]; 541 | } 542 | else { 543 | return [2 /*return*/, rej({ 544 | "code": 500, 545 | "status": false, 546 | "error": "INTERNAL_SERVER_ERROR", 547 | "message": "general (unknown) error" 548 | })]; 549 | } 550 | return [3 /*break*/, 3]; 551 | case 3: return [2 /*return*/]; 552 | } 553 | }); 554 | }); })]; 555 | } 556 | else { 557 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 558 | messages: messages, 559 | markdown: markdown, 560 | stream: false, 561 | model: "chatgpt" 562 | }, function (err, data) { 563 | if ((data === null || data === void 0 ? void 0 : data.finish) === true) { 564 | return results(err, data); 565 | } 566 | else { 567 | results(err, data); 568 | } 569 | }); 570 | } 571 | return [2 /*return*/]; 572 | }); 573 | }); 574 | }; 575 | gpt.v3 = function (_a) { 576 | return __awaiter(this, arguments, void 0, function (_b) { 577 | var stream_; 578 | var _this = this; 579 | var _c = _b.messages, messages = _c === void 0 ? [] : _c, _d = _b.markdown, markdown = _d === void 0 ? false : _d, _e = _b.stream, stream = _e === void 0 ? false : _e, _f = _b.results, results = _f === void 0 ? function () { } : _f; 580 | return __generator(this, function (_g) { 581 | stream_ = false; 582 | try { 583 | if (stream === true) { 584 | stream_ = true; 585 | } 586 | else { 587 | throw new Error("error"); 588 | } 589 | } 590 | catch (error) { 591 | stream_ = false; 592 | } 593 | if (stream_ === false) { 594 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () { 595 | var response, error_7; 596 | return __generator(this, function (_a) { 597 | switch (_a.label) { 598 | case 0: 599 | _a.trys.push([0, 2, , 3]); 600 | return [4 /*yield*/, consult_("https://nexra.aryahcr.cc/api/chat/complements", { 601 | messages: messages, 602 | markdown: markdown, 603 | stream: false, 604 | model: "gpt-4o" 605 | })]; 606 | case 1: 607 | response = _a.sent(); 608 | return [2 /*return*/, res(response)]; 609 | case 2: 610 | error_7 = _a.sent(); 611 | if (typeof error_7 === "object") { 612 | return [2 /*return*/, rej(error_7)]; 613 | } 614 | else { 615 | return [2 /*return*/, rej({ 616 | "code": 500, 617 | "status": false, 618 | "error": "INTERNAL_SERVER_ERROR", 619 | "message": "general (unknown) error" 620 | })]; 621 | } 622 | return [3 /*break*/, 3]; 623 | case 3: return [2 /*return*/]; 624 | } 625 | }); 626 | }); })]; 627 | } 628 | else { 629 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 630 | messages: messages, 631 | markdown: markdown, 632 | model: "gpt-4o" 633 | }, function (err, data) { 634 | if ((data === null || data === void 0 ? void 0 : data.finish) === true) { 635 | return results(err, data); 636 | } 637 | else { 638 | results(err, data); 639 | } 640 | }); 641 | } 642 | return [2 /*return*/]; 643 | }); 644 | }); 645 | }; 646 | gpt.web = function (_a) { 647 | return __awaiter(this, arguments, void 0, function (_b) { 648 | var _this = this; 649 | var _c = _b.prompt, prompt = _c === void 0 ? "" : _c, _d = _b.markdown, markdown = _d === void 0 ? false : _d; 650 | return __generator(this, function (_e) { 651 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () { 652 | var response, error_8; 653 | return __generator(this, function (_a) { 654 | switch (_a.label) { 655 | case 0: 656 | _a.trys.push([0, 2, , 3]); 657 | return [4 /*yield*/, consult_("https://nexra.aryahcr.cc/api/chat/gptweb", { 658 | prompt: prompt, 659 | markdown: markdown 660 | })]; 661 | case 1: 662 | response = _a.sent(); 663 | return [2 /*return*/, res(response)]; 664 | case 2: 665 | error_8 = _a.sent(); 666 | if (typeof error_8 === "object") { 667 | return [2 /*return*/, rej(error_8)]; 668 | } 669 | else { 670 | return [2 /*return*/, rej({ 671 | "code": 500, 672 | "status": false, 673 | "error": "INTERNAL_SERVER_ERROR", 674 | "message": "general (unknown) error" 675 | })]; 676 | } 677 | return [3 /*break*/, 3]; 678 | case 3: return [2 /*return*/]; 679 | } 680 | }); 681 | }); })]; 682 | }); 683 | }); 684 | }; 685 | return gpt; 686 | }()); 687 | exports.gpt = gpt; 688 | var bing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) { 689 | var stream_; 690 | var _c = _b.messages, messages = _c === void 0 ? [] : _c, _d = _b.markdown, markdown = _d === void 0 ? false : _d, _e = _b.stream, stream = _e === void 0 ? false : _e, _f = _b.conversation_style, conversation_style = _f === void 0 ? "Balanced" : _f, _g = _b.results, results = _g === void 0 ? function () { } : _g; 691 | return __generator(this, function (_h) { 692 | stream_ = false; 693 | try { 694 | if (stream === true) { 695 | stream_ = true; 696 | } 697 | else { 698 | throw new Error("error"); 699 | } 700 | } 701 | catch (error) { 702 | stream_ = false; 703 | } 704 | if (stream_ === false) { 705 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(void 0, void 0, void 0, function () { 706 | var response, error_9; 707 | return __generator(this, function (_a) { 708 | switch (_a.label) { 709 | case 0: 710 | _a.trys.push([0, 2, , 3]); 711 | return [4 /*yield*/, consult_("https://nexra.aryahcr.cc/api/chat/complements", { 712 | messages: messages, 713 | markdown: markdown, 714 | stream: false, 715 | conversation_style: conversation_style, 716 | model: "Bing" 717 | })]; 718 | case 1: 719 | response = _a.sent(); 720 | return [2 /*return*/, res(response)]; 721 | case 2: 722 | error_9 = _a.sent(); 723 | if (typeof error_9 === "object") { 724 | return [2 /*return*/, rej(error_9)]; 725 | } 726 | else { 727 | return [2 /*return*/, rej({ 728 | "code": 500, 729 | "status": false, 730 | "error": "INTERNAL_SERVER_ERROR", 731 | "message": "general (unknown) error" 732 | })]; 733 | } 734 | return [3 /*break*/, 3]; 735 | case 3: return [2 /*return*/]; 736 | } 737 | }); 738 | }); })]; 739 | } 740 | else { 741 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 742 | messages: messages, 743 | markdown: markdown, 744 | conversation_style: conversation_style, 745 | model: "Bing" 746 | }, function (err, data) { 747 | if ((data === null || data === void 0 ? void 0 : data.finish) === true) { 748 | return results(err, data); 749 | } 750 | else { 751 | results(err, data); 752 | } 753 | }); 754 | } 755 | return [2 /*return*/]; 756 | }); 757 | }); }; 758 | exports.bing = bing; 759 | var llama = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) { 760 | var stream_; 761 | var _c = _b.messages, messages = _c === void 0 ? [] : _c, _d = _b.markdown, markdown = _d === void 0 ? false : _d, _e = _b.stream, stream = _e === void 0 ? false : _e, _f = _b.results, results = _f === void 0 ? function () { } : _f; 762 | return __generator(this, function (_g) { 763 | stream_ = false; 764 | try { 765 | if (stream === true) { 766 | stream_ = true; 767 | } 768 | else { 769 | throw new Error("error"); 770 | } 771 | } 772 | catch (error) { 773 | stream_ = false; 774 | } 775 | if (stream_ === false) { 776 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(void 0, void 0, void 0, function () { 777 | var response, error_10; 778 | return __generator(this, function (_a) { 779 | switch (_a.label) { 780 | case 0: 781 | _a.trys.push([0, 2, , 3]); 782 | return [4 /*yield*/, consult_("https://nexra.aryahcr.cc/api/chat/complements", { 783 | messages: messages, 784 | markdown: markdown, 785 | stream: false, 786 | model: "llama-3.1" 787 | })]; 788 | case 1: 789 | response = _a.sent(); 790 | return [2 /*return*/, res(response)]; 791 | case 2: 792 | error_10 = _a.sent(); 793 | if (typeof error_10 === "object") { 794 | return [2 /*return*/, rej(error_10)]; 795 | } 796 | else { 797 | return [2 /*return*/, rej({ 798 | "code": 500, 799 | "status": false, 800 | "error": "INTERNAL_SERVER_ERROR", 801 | "message": "general (unknown) error" 802 | })]; 803 | } 804 | return [3 /*break*/, 3]; 805 | case 3: return [2 /*return*/]; 806 | } 807 | }); 808 | }); })]; 809 | } 810 | else { 811 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 812 | messages: messages, 813 | markdown: markdown, 814 | model: "llama-3.1" 815 | }, function (err, data) { 816 | if ((data === null || data === void 0 ? void 0 : data.finish) === true) { 817 | return results(err, data); 818 | } 819 | else { 820 | results(err, data); 821 | } 822 | }); 823 | } 824 | return [2 /*return*/]; 825 | }); 826 | }); }; 827 | exports.llama = llama; 828 | var blackbox = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) { 829 | var stream_; 830 | var _c = _b.messages, messages = _c === void 0 ? [] : _c, _d = _b.markdown, markdown = _d === void 0 ? false : _d, _e = _b.stream, stream = _e === void 0 ? false : _e, _f = _b.results, results = _f === void 0 ? function () { } : _f; 831 | return __generator(this, function (_g) { 832 | stream_ = false; 833 | try { 834 | if (stream === true) { 835 | stream_ = true; 836 | } 837 | else { 838 | throw new Error("error"); 839 | } 840 | } 841 | catch (error) { 842 | stream_ = false; 843 | } 844 | if (stream_ === false) { 845 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(void 0, void 0, void 0, function () { 846 | var response, error_11; 847 | return __generator(this, function (_a) { 848 | switch (_a.label) { 849 | case 0: 850 | _a.trys.push([0, 2, , 3]); 851 | return [4 /*yield*/, consult_("https://nexra.aryahcr.cc/api/chat/complements", { 852 | messages: messages, 853 | markdown: markdown, 854 | stream: false, 855 | model: "blackbox" 856 | })]; 857 | case 1: 858 | response = _a.sent(); 859 | return [2 /*return*/, res(response)]; 860 | case 2: 861 | error_11 = _a.sent(); 862 | if (typeof error_11 === "object") { 863 | return [2 /*return*/, rej(error_11)]; 864 | } 865 | else { 866 | return [2 /*return*/, rej({ 867 | "code": 500, 868 | "status": false, 869 | "error": "INTERNAL_SERVER_ERROR", 870 | "message": "general (unknown) error" 871 | })]; 872 | } 873 | return [3 /*break*/, 3]; 874 | case 3: return [2 /*return*/]; 875 | } 876 | }); 877 | }); })]; 878 | } 879 | else { 880 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 881 | messages: messages, 882 | markdown: markdown, 883 | model: "blackbox" 884 | }, function (err, data) { 885 | if ((data === null || data === void 0 ? void 0 : data.finish) === true) { 886 | return results(err, data); 887 | } 888 | else { 889 | results(err, data); 890 | } 891 | }); 892 | } 893 | return [2 /*return*/]; 894 | }); 895 | }); }; 896 | exports.blackbox = blackbox; 897 | var imageai = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) { 898 | var _c = _b.prompt, prompt = _c === void 0 ? "" : _c, _d = _b.model, model = _d === void 0 ? "" : _d, _e = _b.response, response = _e === void 0 ? "url" : _e, Object = _b.data; 899 | return __generator(this, function (_f) { 900 | return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(void 0, void 0, void 0, function () { 901 | var response_, error_12; 902 | return __generator(this, function (_a) { 903 | switch (_a.label) { 904 | case 0: 905 | _a.trys.push([0, 2, , 3]); 906 | return [4 /*yield*/, consult_img({ 907 | prompt: prompt, 908 | model: model, 909 | response: response 910 | })]; 911 | case 1: 912 | response_ = _a.sent(); 913 | return [2 /*return*/, res(response_)]; 914 | case 2: 915 | error_12 = _a.sent(); 916 | if (typeof error_12 === "object") { 917 | return [2 /*return*/, rej(error_12)]; 918 | } 919 | else { 920 | return [2 /*return*/, rej({ 921 | "code": 500, 922 | "status": false, 923 | "error": "INTERNAL_SERVER_ERROR", 924 | "message": "general (unknown) error" 925 | })]; 926 | } 927 | return [3 /*break*/, 3]; 928 | case 3: return [2 /*return*/]; 929 | } 930 | }); 931 | }); })]; 932 | }); 933 | }); }; 934 | exports.imageai = imageai; 935 | exports.default = { 936 | nexra: nexra, 937 | gpt: gpt, 938 | bing: bing, 939 | llama: llama, 940 | blackbox: blackbox, 941 | imageai: imageai 942 | }; 943 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Author: yandricr 3 | API: https://nexra.aryahcr.cc/ 4 | */ 5 | 6 | import axios from "axios"; 7 | 8 | /* types */ 9 | 10 | type messages_ = { 11 | role?: "user" | "assistant", 12 | content?: string 13 | } 14 | 15 | type gptv1_d = { 16 | prompt?: string, 17 | messages: messages_[], 18 | model?: string, 19 | markdown?: boolean 20 | } 21 | 22 | type gptweb_d = { 23 | prompt: string, 24 | markdown?: boolean 25 | } 26 | 27 | type chatn_d = { 28 | messages?: messages_[], 29 | markdown?: boolean, 30 | stream?: boolean, 31 | results?: (err?: any, data?: any) => void 32 | } 33 | 34 | type bing_d = { 35 | messages: messages_[], 36 | markdown?: boolean, 37 | stream?: boolean, 38 | conversation_style?: "Balanced" | "Creative" | "Precise", 39 | results?: (err?: any, data?: any) => void 40 | } 41 | 42 | type imageai_d = { 43 | prompt: string, 44 | model: string, 45 | response?: "base64" | "url" 46 | data?: Object 47 | } 48 | 49 | /* types */ 50 | 51 | const sleep = async (n: number) => { 52 | return new Promise((res) => { 53 | try { 54 | setTimeout(() => { 55 | return res("OK"); 56 | }, n); 57 | } catch (error) { 58 | return res("OK"); 59 | } 60 | }); 61 | } 62 | 63 | let cred = { 64 | "x-nexra-user": null, 65 | "x-nexra-secret": null 66 | } 67 | 68 | const nexra = (user: any, secret: any) => { 69 | cred["x-nexra-secret"] = secret; 70 | cred["x-nexra-user"] = user; 71 | } 72 | 73 | async function consult_(api: any, data: any) { 74 | return new Promise(async(res, rej) => { 75 | try { 76 | let request = await axios.post(api, data, { 77 | headers: { 78 | "Content-Type": "application/json", 79 | ...cred 80 | } 81 | }); 82 | 83 | if(request.status != 200){ 84 | throw new Error("error"); 85 | } 86 | 87 | let id: any = request.data.id; 88 | let response: any = null; 89 | let data_ = true; 90 | let result = null; 91 | let success_ = false; 92 | while(data_){ 93 | await sleep(1000); 94 | response = await axios.get('https://nexra.aryahcr.cc/api/chat/task/' + encodeURIComponent(id)); 95 | response = response.data; 96 | 97 | switch(response.status){ 98 | case "pending": 99 | data_ = true; 100 | break; 101 | case "error": 102 | case "completed": 103 | success_ = true; 104 | result = response; 105 | case "not_found": 106 | default: 107 | result = response; 108 | data_ = false; 109 | break; 110 | } 111 | } 112 | 113 | if(result === undefined || result === null){ 114 | throw new Error("error"); 115 | } 116 | 117 | if(success_ === false){ 118 | return rej(result); 119 | } else { 120 | return res(result); 121 | } 122 | } catch (error: any) { 123 | try { 124 | if(error.response){ 125 | if(typeof error.response.data === "object"){ 126 | return rej(error.response.data); 127 | } else { 128 | throw new Error("error"); 129 | } 130 | } else if(error.request){ 131 | return rej({ 132 | "code": 404, 133 | "error": "NOT_FOUND", 134 | "message": "the service is currently unavailable" 135 | }); 136 | } else { 137 | return rej({ 138 | "code": 500, 139 | "error": "INTERNAL_SERVER_ERROR", 140 | "message": "general (unknown) error" 141 | }); 142 | } 143 | } catch(e){ 144 | return rej({ 145 | "code": 500, 146 | "error": "INTERNAL_SERVER_ERROR", 147 | "message": "general (unknown) error" 148 | }); 149 | } 150 | } 151 | }); 152 | } 153 | 154 | async function consult_img(data: any) { 155 | return new Promise(async(res, rej) => { 156 | try { 157 | let request = await axios.post("https://nexra.aryahcr.cc/api/image/complements", data, { 158 | headers: { 159 | "Content-Type": "application/json", 160 | ...cred 161 | } 162 | }); 163 | 164 | if(request.status != 200){ 165 | throw new Error("error"); 166 | } 167 | 168 | let id: any = request.data.id; 169 | let response: any = null; 170 | let data_ = true; 171 | let result = null; 172 | let success_ = false; 173 | while(data_){ 174 | await sleep(1000); 175 | response = await axios.get('https://nexra.aryahcr.cc/api/image/complements/' + encodeURIComponent(id)); 176 | response = response.data; 177 | 178 | switch(response.status){ 179 | case "pending": 180 | data_ = true; 181 | break; 182 | case "error": 183 | case "completed": 184 | success_ = true; 185 | result = response; 186 | case "not_found": 187 | default: 188 | result = response; 189 | data_ = false; 190 | break; 191 | } 192 | } 193 | 194 | if(result === undefined || result === null){ 195 | throw new Error("error"); 196 | } 197 | 198 | if(success_ === false){ 199 | return rej(result); 200 | } else { 201 | return res(result); 202 | } 203 | } catch (error: any) { 204 | try { 205 | if(error.response){ 206 | if(typeof error.response.data === "object"){ 207 | return rej(error.response.data); 208 | } else { 209 | throw new Error("error"); 210 | } 211 | } else if(error.request){ 212 | return rej({ 213 | "code": 404, 214 | "error": "NOT_FOUND", 215 | "message": "the service is currently unavailable" 216 | }); 217 | } else { 218 | return rej({ 219 | "code": 500, 220 | "error": "INTERNAL_SERVER_ERROR", 221 | "message": "general (unknown) error" 222 | }); 223 | } 224 | } catch(e){ 225 | return rej({ 226 | "code": 500, 227 | "error": "INTERNAL_SERVER_ERROR", 228 | "message": "general (unknown) error" 229 | }); 230 | } 231 | } 232 | }); 233 | } 234 | 235 | async function consult_strm(api: any, data: any, process: (err: any, data: any) => void){ 236 | try { 237 | let response = await axios.post(api, { 238 | ...data, 239 | "stream": true 240 | }, { 241 | headers: { 242 | "Content-Type": "application/json", 243 | ...cred 244 | }, 245 | responseType: "stream" 246 | }); 247 | 248 | if(response.status === 200){ 249 | let chat: any = null; 250 | let error: any = false; 251 | let tmp: any = null; 252 | 253 | response.data.on("data", (chunk: any) => { 254 | let chk = chunk.toString(); 255 | chk = chk.split(""); 256 | 257 | chk.forEach((data: any) => { 258 | let result = null; 259 | let convert = ""; 260 | 261 | try { 262 | convert = JSON.parse(data); 263 | result = data; 264 | tmp = null; 265 | } catch(e){ 266 | if(tmp === null){ 267 | tmp = data; 268 | } else { 269 | try { 270 | convert = JSON.parse(tmp); 271 | result = tmp; 272 | tmp = null; 273 | } catch(e){ 274 | tmp = tmp + data; 275 | try { 276 | convert = JSON.parse(tmp); 277 | result = tmp; 278 | tmp = null; 279 | } catch(e){ 280 | tmp = tmp; 281 | } 282 | } 283 | } 284 | } 285 | 286 | if(result != null){ 287 | try { 288 | result = JSON.parse(result); 289 | if(chat === null && result != null){ 290 | chat = ""; 291 | } 292 | 293 | if(result != undefined && result != null && result.code === undefined && result.status === undefined){ 294 | if(error != true){ 295 | if(result != undefined && result != null && result.finish != undefined && result.finish != null && result.finish === true){ 296 | chat = result; 297 | } else { 298 | chat = result; 299 | process(null, result); 300 | } 301 | } 302 | } else { 303 | error = true; 304 | chat = result; 305 | } 306 | } catch(e){ 307 | // continue 308 | } 309 | } 310 | }); 311 | }) 312 | 313 | response.data.on("end", () => { 314 | if(chat != null){ 315 | if(error != true){ 316 | return process(null, chat); 317 | } else { 318 | return process(chat, null); 319 | } 320 | } else { 321 | return process({ 322 | "code": 500, 323 | "status": false, 324 | "error": "INTERNAL_SERVER_ERROR", 325 | "message": "general (unknown) error" 326 | }, null); 327 | } 328 | }); 329 | 330 | response.data.on("error", (err: any) => { 331 | 332 | }); 333 | } else { 334 | return process({ 335 | "code": 500, 336 | "status": false, 337 | "error": "INTERNAL_SERVER_ERROR", 338 | "message": "general (unknown) error" 339 | }, null); 340 | } 341 | } catch (error: any) { 342 | try { 343 | if (error.response) { 344 | try { 345 | let err: any = null; 346 | error.response.data.on("data", (chk: any) => { 347 | if(err != null){ 348 | err += chk.toString(); 349 | } else { 350 | err = chk.toString(); 351 | } 352 | }); 353 | 354 | error.response.data.on("end", () => { 355 | try { 356 | err = JSON.parse(err); 357 | return process(err, null); 358 | } catch (error) { 359 | return process({ 360 | "code": 500, 361 | "status": false, 362 | "error": "INTERNAL_SERVER_ERROR", 363 | "message": "general (unknown) error" 364 | }, null); 365 | } 366 | }); 367 | 368 | error.response.data.on("error", () => { 369 | 370 | }); 371 | } catch (error) { 372 | return process({ 373 | "code": 500, 374 | "status": false, 375 | "error": "INTERNAL_SERVER_ERROR", 376 | "message": "general (unknown) error" 377 | }, null); 378 | } 379 | } else if (error.request) { 380 | return process({ 381 | "code": 404, 382 | "error": "NOT_FOUND", 383 | "message": "the service is currently unavailable" 384 | }, null); 385 | } else { 386 | return process({ 387 | "code": 500, 388 | "status": false, 389 | "error": "INTERNAL_SERVER_ERROR", 390 | "message": "general (unknown) error" 391 | }, null); 392 | } 393 | } catch (error) { 394 | return process({ 395 | "code": 500, 396 | "status": false, 397 | "error": "INTERNAL_SERVER_ERROR", 398 | "message": "general (unknown) error" 399 | }, null); 400 | } 401 | } 402 | } 403 | 404 | class gpt { 405 | static async v1({ 406 | prompt = "", 407 | messages = [], 408 | model = "", 409 | markdown = false 410 | }: gptv1_d){ 411 | return new Promise(async (res, rej) => { 412 | try { 413 | let response = await consult_("https://nexra.aryahcr.cc/api/chat/gpt", { 414 | messages: messages, 415 | prompt: prompt, 416 | model: model, 417 | markdown: markdown 418 | }); 419 | 420 | return res(response); 421 | } catch (error: any) { 422 | if(typeof error === "object"){ 423 | return rej(error); 424 | } else { 425 | return rej({ 426 | "code": 500, 427 | "status": false, 428 | "error": "INTERNAL_SERVER_ERROR", 429 | "message": "general (unknown) error" 430 | }); 431 | } 432 | } 433 | }); 434 | } 435 | static async v2({ 436 | messages = [], 437 | markdown = false, 438 | stream = false, 439 | results = () => {} 440 | }: chatn_d){ 441 | let stream_ = false; 442 | try { 443 | if(stream === true){ 444 | stream_ = true; 445 | } else { 446 | throw new Error("error"); 447 | } 448 | } catch (error) { 449 | stream_ = false; 450 | } 451 | 452 | if(stream_ === false){ 453 | return new Promise(async (res, rej) => { 454 | try { 455 | let response = await consult_("https://nexra.aryahcr.cc/api/chat/complements", { 456 | messages: messages, 457 | markdown: markdown, 458 | stream: false, 459 | model: "chatgpt" 460 | }); 461 | 462 | return res(response); 463 | } catch (error: any) { 464 | if(typeof error === "object"){ 465 | return rej(error); 466 | } else { 467 | return rej({ 468 | "code": 500, 469 | "status": false, 470 | "error": "INTERNAL_SERVER_ERROR", 471 | "message": "general (unknown) error" 472 | }); 473 | } 474 | } 475 | }); 476 | } else { 477 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 478 | messages: messages, 479 | markdown: markdown, 480 | stream: false, 481 | model: "chatgpt" 482 | }, (err: any, data: any) => { 483 | if(data?.finish === true){ 484 | return results(err, data); 485 | } else { 486 | results(err, data); 487 | } 488 | }); 489 | } 490 | } 491 | static async v3({ 492 | messages = [], 493 | markdown = false, 494 | stream = false, 495 | results = () => {} 496 | }: chatn_d){ 497 | let stream_ = false; 498 | try { 499 | if(stream === true){ 500 | stream_ = true; 501 | } else { 502 | throw new Error("error"); 503 | } 504 | } catch (error) { 505 | stream_ = false; 506 | } 507 | 508 | if(stream_ === false){ 509 | return new Promise(async (res, rej) => { 510 | try { 511 | let response = await consult_("https://nexra.aryahcr.cc/api/chat/complements", { 512 | messages: messages, 513 | markdown: markdown, 514 | stream: false, 515 | model: "gpt-4o" 516 | }); 517 | 518 | return res(response); 519 | } catch (error: any) { 520 | if(typeof error === "object"){ 521 | return rej(error); 522 | } else { 523 | return rej({ 524 | "code": 500, 525 | "status": false, 526 | "error": "INTERNAL_SERVER_ERROR", 527 | "message": "general (unknown) error" 528 | }); 529 | } 530 | } 531 | }); 532 | } else { 533 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 534 | messages: messages, 535 | markdown: markdown, 536 | model: "gpt-4o" 537 | }, (err: any, data: any) => { 538 | if(data?.finish === true){ 539 | return results(err, data); 540 | } else { 541 | results(err, data); 542 | } 543 | }); 544 | } 545 | } 546 | static async web({ 547 | prompt = "", 548 | markdown = false 549 | }: gptweb_d){ 550 | return new Promise(async (res, rej) => { 551 | try { 552 | let response = await consult_("https://nexra.aryahcr.cc/api/chat/gptweb", { 553 | prompt: prompt, 554 | markdown: markdown 555 | }); 556 | 557 | return res(response); 558 | } catch (error: any) { 559 | if(typeof error === "object"){ 560 | return rej(error); 561 | } else { 562 | return rej({ 563 | "code": 500, 564 | "status": false, 565 | "error": "INTERNAL_SERVER_ERROR", 566 | "message": "general (unknown) error" 567 | }); 568 | } 569 | } 570 | }); 571 | } 572 | } 573 | 574 | const bing = async ({ 575 | messages = [], 576 | markdown = false, 577 | stream = false, 578 | conversation_style = "Balanced", 579 | results = () => {} 580 | }: bing_d) => { 581 | let stream_ = false; 582 | try { 583 | if(stream === true){ 584 | stream_ = true; 585 | } else { 586 | throw new Error("error"); 587 | } 588 | } catch (error) { 589 | stream_ = false; 590 | } 591 | 592 | if(stream_ === false){ 593 | return new Promise(async (res, rej) => { 594 | try { 595 | let response = await consult_("https://nexra.aryahcr.cc/api/chat/complements", { 596 | messages: messages, 597 | markdown: markdown, 598 | stream: false, 599 | conversation_style: conversation_style, 600 | model: "Bing" 601 | }); 602 | 603 | return res(response); 604 | } catch (error: any) { 605 | if(typeof error === "object"){ 606 | return rej(error); 607 | } else { 608 | return rej({ 609 | "code": 500, 610 | "status": false, 611 | "error": "INTERNAL_SERVER_ERROR", 612 | "message": "general (unknown) error" 613 | }); 614 | } 615 | } 616 | }); 617 | } else { 618 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 619 | messages: messages, 620 | markdown: markdown, 621 | conversation_style: conversation_style, 622 | model: "Bing" 623 | }, (err: any, data: any) => { 624 | if(data?.finish === true){ 625 | return results(err, data); 626 | } else { 627 | results(err, data); 628 | } 629 | }); 630 | } 631 | } 632 | 633 | const llama = async ({ 634 | messages = [], 635 | markdown = false, 636 | stream = false, 637 | results = () => {} 638 | }: chatn_d) => { 639 | let stream_ = false; 640 | try { 641 | if(stream === true){ 642 | stream_ = true; 643 | } else { 644 | throw new Error("error"); 645 | } 646 | } catch (error) { 647 | stream_ = false; 648 | } 649 | 650 | if(stream_ === false){ 651 | return new Promise(async (res, rej) => { 652 | try { 653 | let response = await consult_("https://nexra.aryahcr.cc/api/chat/complements", { 654 | messages: messages, 655 | markdown: markdown, 656 | stream: false, 657 | model: "llama-3.1" 658 | }); 659 | 660 | return res(response); 661 | } catch (error: any) { 662 | if(typeof error === "object"){ 663 | return rej(error); 664 | } else { 665 | return rej({ 666 | "code": 500, 667 | "status": false, 668 | "error": "INTERNAL_SERVER_ERROR", 669 | "message": "general (unknown) error" 670 | }); 671 | } 672 | } 673 | }); 674 | } else { 675 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 676 | messages: messages, 677 | markdown: markdown, 678 | model: "llama-3.1" 679 | }, (err: any, data: any) => { 680 | if(data?.finish === true){ 681 | return results(err, data); 682 | } else { 683 | results(err, data); 684 | } 685 | }); 686 | } 687 | } 688 | 689 | const blackbox = async ({ 690 | messages = [], 691 | markdown = false, 692 | stream = false, 693 | results = () => {} 694 | }: chatn_d) => { 695 | let stream_ = false; 696 | try { 697 | if(stream === true){ 698 | stream_ = true; 699 | } else { 700 | throw new Error("error"); 701 | } 702 | } catch (error) { 703 | stream_ = false; 704 | } 705 | 706 | if(stream_ === false){ 707 | return new Promise(async (res, rej) => { 708 | try { 709 | let response = await consult_("https://nexra.aryahcr.cc/api/chat/complements", { 710 | messages: messages, 711 | markdown: markdown, 712 | stream: false, 713 | model: "blackbox" 714 | }); 715 | 716 | return res(response); 717 | } catch (error: any) { 718 | if(typeof error === "object"){ 719 | return rej(error); 720 | } else { 721 | return rej({ 722 | "code": 500, 723 | "status": false, 724 | "error": "INTERNAL_SERVER_ERROR", 725 | "message": "general (unknown) error" 726 | }); 727 | } 728 | } 729 | }); 730 | } else { 731 | consult_strm("https://nexra.aryahcr.cc/api/chat/complements", { 732 | messages: messages, 733 | markdown: markdown, 734 | model: "blackbox" 735 | }, (err: any, data: any) => { 736 | if(data?.finish === true){ 737 | return results(err, data); 738 | } else { 739 | results(err, data); 740 | } 741 | }); 742 | } 743 | } 744 | 745 | const imageai = async ({ 746 | prompt = "", 747 | model = "", 748 | response = "url", 749 | data: Object 750 | }: imageai_d) => { 751 | return new Promise(async (res, rej) => { 752 | try { 753 | let response_ = await consult_img({ 754 | prompt: prompt, 755 | model: model, 756 | response: response 757 | }); 758 | 759 | return res(response_); 760 | } catch (error: any) { 761 | if(typeof error === "object"){ 762 | return rej(error); 763 | } else { 764 | return rej({ 765 | "code": 500, 766 | "status": false, 767 | "error": "INTERNAL_SERVER_ERROR", 768 | "message": "general (unknown) error" 769 | }); 770 | } 771 | } 772 | }); 773 | } 774 | 775 | export { 776 | nexra, 777 | gpt, 778 | bing, 779 | llama, 780 | blackbox, 781 | imageai 782 | } 783 | 784 | export default { 785 | nexra, 786 | gpt, 787 | bing, 788 | llama, 789 | blackbox, 790 | imageai 791 | } -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gpti", 3 | "version": "2.1.8", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "gpti", 9 | "version": "2.1.8", 10 | "license": "MIT", 11 | "dependencies": { 12 | "axios": "^1.7.2" 13 | }, 14 | "devDependencies": { 15 | "ts-node": "^10.9.1", 16 | "typescript": "^5.5.2" 17 | }, 18 | "funding": { 19 | "type": "individual", 20 | "url": "https://ko-fi.com/yandricr" 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.4.15", 46 | "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", 47 | "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", 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/@tsconfig/node10": { 61 | "version": "1.0.11", 62 | "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", 63 | "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", 64 | "dev": true 65 | }, 66 | "node_modules/@tsconfig/node12": { 67 | "version": "1.0.11", 68 | "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", 69 | "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", 70 | "dev": true 71 | }, 72 | "node_modules/@tsconfig/node14": { 73 | "version": "1.0.3", 74 | "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", 75 | "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", 76 | "dev": true 77 | }, 78 | "node_modules/@tsconfig/node16": { 79 | "version": "1.0.4", 80 | "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", 81 | "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", 82 | "dev": true 83 | }, 84 | "node_modules/@types/node": { 85 | "version": "20.12.4", 86 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.4.tgz", 87 | "integrity": "sha512-E+Fa9z3wSQpzgYQdYmme5X3OTuejnnTx88A6p6vkkJosR3KBz+HpE3kqNm98VE6cfLFcISx7zW7MsJkH6KwbTw==", 88 | "dev": true, 89 | "peer": true, 90 | "dependencies": { 91 | "undici-types": "~5.26.4" 92 | } 93 | }, 94 | "node_modules/acorn": { 95 | "version": "8.11.3", 96 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", 97 | "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", 98 | "dev": true, 99 | "bin": { 100 | "acorn": "bin/acorn" 101 | }, 102 | "engines": { 103 | "node": ">=0.4.0" 104 | } 105 | }, 106 | "node_modules/acorn-walk": { 107 | "version": "8.3.2", 108 | "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", 109 | "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", 110 | "dev": true, 111 | "engines": { 112 | "node": ">=0.4.0" 113 | } 114 | }, 115 | "node_modules/arg": { 116 | "version": "4.1.3", 117 | "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", 118 | "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", 119 | "dev": true 120 | }, 121 | "node_modules/asynckit": { 122 | "version": "0.4.0", 123 | "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", 124 | "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" 125 | }, 126 | "node_modules/axios": { 127 | "version": "1.7.2", 128 | "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", 129 | "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", 130 | "dependencies": { 131 | "follow-redirects": "^1.15.6", 132 | "form-data": "^4.0.0", 133 | "proxy-from-env": "^1.1.0" 134 | } 135 | }, 136 | "node_modules/combined-stream": { 137 | "version": "1.0.8", 138 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", 139 | "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", 140 | "dependencies": { 141 | "delayed-stream": "~1.0.0" 142 | }, 143 | "engines": { 144 | "node": ">= 0.8" 145 | } 146 | }, 147 | "node_modules/create-require": { 148 | "version": "1.1.1", 149 | "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", 150 | "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", 151 | "dev": true 152 | }, 153 | "node_modules/delayed-stream": { 154 | "version": "1.0.0", 155 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 156 | "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", 157 | "engines": { 158 | "node": ">=0.4.0" 159 | } 160 | }, 161 | "node_modules/diff": { 162 | "version": "4.0.2", 163 | "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", 164 | "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", 165 | "dev": true, 166 | "engines": { 167 | "node": ">=0.3.1" 168 | } 169 | }, 170 | "node_modules/follow-redirects": { 171 | "version": "1.15.6", 172 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", 173 | "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", 174 | "funding": [ 175 | { 176 | "type": "individual", 177 | "url": "https://github.com/sponsors/RubenVerborgh" 178 | } 179 | ], 180 | "engines": { 181 | "node": ">=4.0" 182 | }, 183 | "peerDependenciesMeta": { 184 | "debug": { 185 | "optional": true 186 | } 187 | } 188 | }, 189 | "node_modules/form-data": { 190 | "version": "4.0.0", 191 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", 192 | "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", 193 | "dependencies": { 194 | "asynckit": "^0.4.0", 195 | "combined-stream": "^1.0.8", 196 | "mime-types": "^2.1.12" 197 | }, 198 | "engines": { 199 | "node": ">= 6" 200 | } 201 | }, 202 | "node_modules/make-error": { 203 | "version": "1.3.6", 204 | "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", 205 | "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", 206 | "dev": true 207 | }, 208 | "node_modules/mime-db": { 209 | "version": "1.52.0", 210 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", 211 | "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", 212 | "engines": { 213 | "node": ">= 0.6" 214 | } 215 | }, 216 | "node_modules/mime-types": { 217 | "version": "2.1.35", 218 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", 219 | "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", 220 | "dependencies": { 221 | "mime-db": "1.52.0" 222 | }, 223 | "engines": { 224 | "node": ">= 0.6" 225 | } 226 | }, 227 | "node_modules/proxy-from-env": { 228 | "version": "1.1.0", 229 | "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", 230 | "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" 231 | }, 232 | "node_modules/ts-node": { 233 | "version": "10.9.2", 234 | "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", 235 | "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", 236 | "dev": true, 237 | "dependencies": { 238 | "@cspotcode/source-map-support": "^0.8.0", 239 | "@tsconfig/node10": "^1.0.7", 240 | "@tsconfig/node12": "^1.0.7", 241 | "@tsconfig/node14": "^1.0.0", 242 | "@tsconfig/node16": "^1.0.2", 243 | "acorn": "^8.4.1", 244 | "acorn-walk": "^8.1.1", 245 | "arg": "^4.1.0", 246 | "create-require": "^1.1.0", 247 | "diff": "^4.0.1", 248 | "make-error": "^1.1.1", 249 | "v8-compile-cache-lib": "^3.0.1", 250 | "yn": "3.1.1" 251 | }, 252 | "bin": { 253 | "ts-node": "dist/bin.js", 254 | "ts-node-cwd": "dist/bin-cwd.js", 255 | "ts-node-esm": "dist/bin-esm.js", 256 | "ts-node-script": "dist/bin-script.js", 257 | "ts-node-transpile-only": "dist/bin-transpile.js", 258 | "ts-script": "dist/bin-script-deprecated.js" 259 | }, 260 | "peerDependencies": { 261 | "@swc/core": ">=1.2.50", 262 | "@swc/wasm": ">=1.2.50", 263 | "@types/node": "*", 264 | "typescript": ">=2.7" 265 | }, 266 | "peerDependenciesMeta": { 267 | "@swc/core": { 268 | "optional": true 269 | }, 270 | "@swc/wasm": { 271 | "optional": true 272 | } 273 | } 274 | }, 275 | "node_modules/typescript": { 276 | "version": "5.5.2", 277 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", 278 | "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", 279 | "dev": true, 280 | "bin": { 281 | "tsc": "bin/tsc", 282 | "tsserver": "bin/tsserver" 283 | }, 284 | "engines": { 285 | "node": ">=14.17" 286 | } 287 | }, 288 | "node_modules/undici-types": { 289 | "version": "5.26.5", 290 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", 291 | "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", 292 | "dev": true, 293 | "peer": true 294 | }, 295 | "node_modules/v8-compile-cache-lib": { 296 | "version": "3.0.1", 297 | "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", 298 | "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", 299 | "dev": true 300 | }, 301 | "node_modules/yn": { 302 | "version": "3.1.1", 303 | "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", 304 | "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", 305 | "dev": true, 306 | "engines": { 307 | "node": ">=6" 308 | } 309 | } 310 | } 311 | } 312 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gpti", 3 | "version": "2.1.8", 4 | "description": "This package simplifies your interaction with various GPT models, removing the need for tokens or other methods to access GPT", 5 | "main": "index.js", 6 | "types": "main.ts", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1", 9 | "start": "ts-node main.ts" 10 | }, 11 | "exports": { 12 | ".": { 13 | "import": "./main.ts", 14 | "require": "./main.js" 15 | } 16 | }, 17 | "keywords": [ 18 | "gpt", 19 | "gpt-3", 20 | "gpt-3.5", 21 | "gpt-4", 22 | "gpti", 23 | "gpt-free", 24 | "ai", 25 | "blackbox", 26 | "prodia", 27 | "bing", 28 | "chat", 29 | "stream", 30 | "dalle", 31 | "generate-image", 32 | "llama-3.1", 33 | "gpt-4o" 34 | ], 35 | "author": "yandricr", 36 | "license": "MIT", 37 | "devDependencies": { 38 | "ts-node": "^10.9.1", 39 | "typescript": "^5.5.2" 40 | }, 41 | "repository": { 42 | "type": "git", 43 | "url": "https://github.com/yandricr/gpti-js" 44 | }, 45 | "homepage": "https://nexra.aryahcr.cc/", 46 | "dependencies": { 47 | "axios": "^1.7.2" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /promise.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Author: yandricr 3 | API: https://nexra.aryahcr.cc/ 4 | */ 5 | 6 | import axios from "axios"; 7 | 8 | let cred = { 9 | "x-nexra-user": null, 10 | "x-nexra-secret": null 11 | } 12 | 13 | type gptdata = { 14 | messages?: messagesdata[], 15 | prompt?: string, 16 | model?: string 17 | markdown?: boolean 18 | } 19 | 20 | type gptv2data = { 21 | messages?: messagesdata[], 22 | markdown?: boolean 23 | } 24 | 25 | type messagesdata = { 26 | role: "user" | "assistant", 27 | content: string 28 | } 29 | 30 | const nexra = (user: any, secret: any) => { 31 | cred["x-nexra-secret"] = secret; 32 | cred["x-nexra-user"] = user; 33 | } 34 | 35 | type gptwebdata = { 36 | prompt: string, 37 | markdown?: boolean 38 | } 39 | 40 | async function consult_(api: any, data: any) { 41 | return new Promise(async(res, rej) => { 42 | try { 43 | let response = await axios.post(api, data, { 44 | headers: { 45 | "Content-Type": "application/json", 46 | ...cred 47 | } 48 | }); 49 | 50 | if(response.status === 200){ 51 | if((typeof response.data).toString().toLowerCase() === "Object".toLowerCase()){ 52 | if(response.data.code != undefined && response.data.code != null && response.data.code === 200 && response.data.status != undefined && response.data.status != null && response.data.status === true){ 53 | return res(response.data); 54 | } else { 55 | return rej(response.data); 56 | } 57 | } else { 58 | let js = null; 59 | let count = -1; 60 | for(let i = 0; i < response.data.length; i++){ 61 | if(count <= -1){ 62 | if(response.data[i] === "{"){ 63 | count = i; 64 | } 65 | } else { 66 | break; 67 | } 68 | } 69 | 70 | if(count <= -1){ 71 | return rej({ 72 | "code": 500, 73 | "status": false, 74 | "error": "INTERNAL_SERVER_ERROR", 75 | "message": "general (unknown) error" 76 | }); 77 | } else { 78 | try { 79 | js = response.data.slice(count); 80 | js = JSON.parse(js); 81 | if(js != undefined && js != null && js.code != undefined && js.code != null && js.code === 200 && js.status != undefined && js.status != null && js.status === true){ 82 | return res(js); 83 | } else { 84 | return rej(js); 85 | } 86 | } catch(e){ 87 | return rej({ 88 | "code": 500, 89 | "status": false, 90 | "error": "INTERNAL_SERVER_ERROR", 91 | "message": "general (unknown) error" 92 | }); 93 | } 94 | } 95 | } 96 | } else { 97 | return rej({ 98 | "code": 500, 99 | "status": false, 100 | "error": "INTERNAL_SERVER_ERROR", 101 | "message": "general (unknown) error" 102 | }); 103 | } 104 | } catch (error: any) { 105 | try { 106 | if (error.response) { 107 | return rej(error.response.data) 108 | } else if (error.request) { 109 | return rej({ 110 | "code": 404, 111 | "error": "NOT_FOUND", 112 | "message": "the service is currently unavailable" 113 | }); 114 | } else { 115 | return rej({ 116 | "code": 500, 117 | "status": false, 118 | "error": "INTERNAL_SERVER_ERROR", 119 | "message": "general (unknown) error" 120 | }); 121 | } 122 | } catch(e){ 123 | return rej({ 124 | "code": 500, 125 | "status": false, 126 | "error": "INTERNAL_SERVER_ERROR", 127 | "message": "general (unknown) error" 128 | }); 129 | } 130 | } 131 | }); 132 | } 133 | 134 | async function consult_strm(api: any, data: any, process: (err: any, data: any) => void){ 135 | try { 136 | let response = await axios.post(api, { 137 | ...data, 138 | "stream": true 139 | }, { 140 | headers: { 141 | "Content-Type": "application/json", 142 | ...cred 143 | }, 144 | responseType: "stream" 145 | }); 146 | 147 | if(response.status === 200){ 148 | let chat: any = null; 149 | let error: any = false; 150 | response.data.on("data", (chunk: any) => { 151 | let chk = chunk.toString(); 152 | chk = chk.split(""); 153 | let tmp: any = null; 154 | 155 | chk.forEach((data: any) => { 156 | let result = null; 157 | let convert = ""; 158 | 159 | try { 160 | convert = JSON.parse(data); 161 | result = data; 162 | tmp = null; 163 | } catch(e){ 164 | if(tmp === null){ 165 | tmp = data; 166 | } else { 167 | try { 168 | convert = JSON.parse(tmp); 169 | result = tmp; 170 | tmp = null; 171 | } catch(e){ 172 | tmp = tmp + data; 173 | try { 174 | convert = JSON.parse(tmp); 175 | result = tmp; 176 | tmp = null; 177 | } catch(e){ 178 | tmp = tmp; 179 | } 180 | } 181 | } 182 | } 183 | 184 | if(result != null){ 185 | try { 186 | result = JSON.parse(result); 187 | if(chat === null && result != null){ 188 | chat = ""; 189 | } 190 | 191 | if(result != undefined && result != null && result.code === undefined && result.status === undefined){ 192 | if(error != true){ 193 | if(result != undefined && result != null && result.finish != undefined && result.finish != null && result.finish === true){ 194 | chat = result; 195 | } else { 196 | chat = result; 197 | process(null, result); 198 | } 199 | } 200 | } else { 201 | error = true; 202 | chat = result; 203 | } 204 | } catch(e){ 205 | // continue 206 | } 207 | } 208 | }); 209 | }) 210 | 211 | response.data.on("end", () => { 212 | if(chat != null){ 213 | if(error != true){ 214 | return process(null, chat); 215 | } else { 216 | return process(chat, null); 217 | } 218 | } else { 219 | return process({ 220 | "code": 500, 221 | "status": false, 222 | "error": "INTERNAL_SERVER_ERROR", 223 | "message": "general (unknown) error" 224 | }, null); 225 | } 226 | }); 227 | 228 | response.data.on("error", (err: any) => { 229 | return process({ 230 | "code": 500, 231 | "status": false, 232 | "error": "INTERNAL_SERVER_ERROR", 233 | "message": "general (unknown) error" 234 | }, null); 235 | }); 236 | } else { 237 | return process({ 238 | "code": 500, 239 | "status": false, 240 | "error": "INTERNAL_SERVER_ERROR", 241 | "message": "general (unknown) error" 242 | }, null); 243 | } 244 | } catch (error: any) { 245 | try { 246 | if (error.response) { 247 | try { 248 | let err: any = null; 249 | error.response.data.on("data", (chk: any) => { 250 | if(err != null){ 251 | err += chk.toString(); 252 | } else { 253 | err = chk.toString(); 254 | } 255 | }); 256 | 257 | error.response.data.on("end", () => { 258 | try { 259 | err = JSON.parse(err); 260 | return process(err, null); 261 | } catch (error) { 262 | return process({ 263 | "code": 500, 264 | "status": false, 265 | "error": "INTERNAL_SERVER_ERROR", 266 | "message": "general (unknown) error" 267 | }, null); 268 | } 269 | }); 270 | 271 | error.response.data.on("error", () => { 272 | return process({ 273 | "code": 500, 274 | "status": false, 275 | "error": "INTERNAL_SERVER_ERROR", 276 | "message": "general (unknown) error" 277 | }, null); 278 | }); 279 | } catch (error) { 280 | return process({ 281 | "code": 500, 282 | "status": false, 283 | "error": "INTERNAL_SERVER_ERROR", 284 | "message": "general (unknown) error" 285 | }, null); 286 | } 287 | } else if (error.request) { 288 | return process({ 289 | "code": 404, 290 | "error": "NOT_FOUND", 291 | "message": "the service is currently unavailable" 292 | }, null); 293 | } else { 294 | return process({ 295 | "code": 500, 296 | "status": false, 297 | "error": "INTERNAL_SERVER_ERROR", 298 | "message": "general (unknown) error" 299 | }, null); 300 | } 301 | } catch (error) { 302 | return process({ 303 | "code": 500, 304 | "status": false, 305 | "error": "INTERNAL_SERVER_ERROR", 306 | "message": "general (unknown) error" 307 | }, null); 308 | } 309 | } 310 | } 311 | 312 | class gpt { 313 | static v1 = async ({ 314 | messages = [], 315 | prompt = "", 316 | model = "", 317 | markdown = false 318 | }: gptdata) => { 319 | return new Promise(async (res, rej) => { 320 | try { 321 | let response = await consult_('https://nexra.aryahcr.cc/api/chat/gpt', { 322 | messages: messages != undefined && messages != null ? messages : [], 323 | prompt: prompt != undefined && prompt != null ? prompt : "", 324 | model: model != undefined && model != null ? model : "", 325 | markdown: markdown != undefined && markdown != null ? markdown : false 326 | }); 327 | 328 | return res(response); 329 | } catch(e){ 330 | if(typeof(e) == "object"){ 331 | return rej(e); 332 | } else { 333 | return rej({ 334 | "code": 500, 335 | "status": false, 336 | "error": "INTERNAL_SERVER_ERROR", 337 | "message": "general (unknown) error" 338 | }); 339 | } 340 | } 341 | }); 342 | } 343 | static v2 = async ({ 344 | messages = [], 345 | markdown = false 346 | }: gptv2data) => { 347 | return new Promise(async (res, rej) => { 348 | try { 349 | let response = await consult_('https://nexra.aryahcr.cc/api/chat/gpt', { 350 | messages: messages != undefined && messages != null ? messages : [], 351 | model: "chatgpt", 352 | markdown: markdown != undefined && markdown != null ? markdown : false, 353 | }); 354 | 355 | return res(response); 356 | } catch(e){ 357 | if(typeof(e) == "object"){ 358 | return rej(e); 359 | } else { 360 | return rej({ 361 | "code": 500, 362 | "status": false, 363 | "error": "INTERNAL_SERVER_ERROR", 364 | "message": "general (unknown) error" 365 | }); 366 | } 367 | } 368 | }); 369 | } 370 | static v2_strm = async ({ 371 | messages = [], 372 | markdown = false 373 | }: gptv2data, process: (err: any, data: any) => void) => { 374 | try { 375 | await consult_strm('https://nexra.aryahcr.cc/api/chat/complements', { 376 | messages: messages != undefined && messages != null ? messages : [], 377 | model: "chatgpt", 378 | markdown: markdown != undefined && markdown != null ? markdown : false, 379 | }, (err, data) => { 380 | return process(err, data); 381 | }); 382 | } catch(e){ 383 | return process({ 384 | "code": 500, 385 | "status": false, 386 | "error": "INTERNAL_SERVER_ERROR", 387 | "message": "general (unknown) error" 388 | }, null); 389 | } 390 | } 391 | static web = async ({ 392 | prompt = "", 393 | markdown = false 394 | }: gptwebdata) => { 395 | return new Promise(async (res, rej) => { 396 | try { 397 | let response = await consult_('https://nexra.aryahcr.cc/api/chat/gptweb', { 398 | prompt: prompt != undefined && prompt != null ? prompt : "", 399 | markdown: markdown != undefined && markdown != null ? markdown : false 400 | }); 401 | 402 | return res(response); 403 | } catch(e){ 404 | if(typeof(e) == "object"){ 405 | return rej(e); 406 | } else { 407 | return rej({ 408 | "code": 500, 409 | "status": false, 410 | "error": "INTERNAL_SERVER_ERROR", 411 | "message": "general (unknown) error" 412 | }); 413 | } 414 | } 415 | }); 416 | } 417 | } 418 | 419 | type llama2data = { 420 | messages: messagesdata[], 421 | system_message?: string, 422 | temperature?: Number, 423 | max_tokens?: Number, 424 | top_p?: Number, 425 | repetition_penalty?: Number, 426 | markdown?: boolean 427 | } 428 | 429 | class llama2 { 430 | static async asc({ 431 | messages = [], 432 | system_message = "", 433 | temperature = 0.9, 434 | max_tokens = 4096, 435 | top_p = 0.6, 436 | repetition_penalty = 1.2, 437 | markdown = false 438 | }: llama2data){ 439 | return new Promise(async (res, rej) => { 440 | try { 441 | let response = await consult_('https://nexra.aryahcr.cc/api/chat/complements', { 442 | messages: messages != undefined && messages != null ? messages : [], 443 | model: "llama2", 444 | data: { 445 | system_message: system_message != undefined && system_message != null ? system_message : "", 446 | temperature: temperature != undefined && temperature != null ? temperature : 0.9, 447 | max_tokens: max_tokens != undefined && max_tokens != null ? max_tokens : 4096, 448 | top_p: top_p != undefined && top_p != null ? top_p : 0.6, 449 | repetition_penalty: repetition_penalty != undefined && repetition_penalty != null ? repetition_penalty : 1.2, 450 | }, 451 | markdown: markdown != undefined && markdown != null ? markdown : false 452 | }); 453 | 454 | return res(response); 455 | } catch(e){ 456 | if(typeof(e) == "object"){ 457 | return rej(e); 458 | } else { 459 | return rej({ 460 | "code": 500, 461 | "status": false, 462 | "error": "INTERNAL_SERVER_ERROR", 463 | "message": "general (unknown) error" 464 | }); 465 | } 466 | } 467 | }); 468 | } 469 | static async strm({ 470 | messages = [], 471 | system_message = "", 472 | temperature = 0.9, 473 | max_tokens = 4096, 474 | top_p = 0.6, 475 | repetition_penalty = 1.2, 476 | markdown = false 477 | }: llama2data, process: (err: any, data: any) => void){ 478 | try { 479 | await consult_strm('https://nexra.aryahcr.cc/api/chat/complements', { 480 | messages: messages != undefined && messages != null ? messages : [], 481 | model: "llama2", 482 | data: { 483 | system_message: system_message != undefined && system_message != null ? system_message : "", 484 | temperature: temperature != undefined && temperature != null ? temperature : 0.9, 485 | max_tokens: max_tokens != undefined && max_tokens != null ? max_tokens : 4096, 486 | top_p: top_p != undefined && top_p != null ? top_p : 0.6, 487 | repetition_penalty: repetition_penalty != undefined && repetition_penalty != null ? repetition_penalty : 1.2 488 | }, 489 | markdown: markdown != undefined && markdown != null ? markdown : false 490 | }, (err, data) => { 491 | return process(err, data); 492 | }); 493 | } catch(e){ 494 | return process({ 495 | "code": 500, 496 | "status": false, 497 | "error": "INTERNAL_SERVER_ERROR", 498 | "message": "general (unknown) error" 499 | }, null); 500 | } 501 | } 502 | } 503 | 504 | type bingdata = { 505 | messages: messagesdata[], 506 | conversation_style?: "Balanced" | "Creative" | "Precise", 507 | markdown?: boolean 508 | } 509 | 510 | class bing { 511 | static async asc({ 512 | messages = [], 513 | conversation_style = "Balanced", 514 | markdown = false 515 | }: bingdata){ 516 | return new Promise(async (res, rej) => { 517 | try { 518 | let response = await consult_('https://nexra.aryahcr.cc/api/chat/complements', { 519 | messages: messages != undefined && messages != null ? messages : [], 520 | conversation_style: conversation_style, 521 | markdown: markdown != undefined && markdown != null ? markdown : false, 522 | model: "bing" 523 | }); 524 | 525 | return res(response); 526 | } catch(e){ 527 | if(typeof(e) == "object"){ 528 | return rej(e); 529 | } else { 530 | return rej({ 531 | "code": 500, 532 | "status": false, 533 | "error": "INTERNAL_SERVER_ERROR", 534 | "message": "general (unknown) error" 535 | }); 536 | } 537 | } 538 | }); 539 | } 540 | static async strm({ 541 | messages = [], 542 | conversation_style = "Balanced", 543 | markdown = false, 544 | }: bingdata, process: (err: any, data: any) => void){ 545 | try { 546 | await consult_strm('https://nexra.aryahcr.cc/api/chat/complements', { 547 | messages: messages != undefined && messages != null ? messages : [], 548 | conversation_style: conversation_style, 549 | markdown: markdown != undefined && markdown != null ? markdown : false, 550 | model: "bing" 551 | }, (err, data) => { 552 | return process(err, data); 553 | }); 554 | } catch(e){ 555 | return process({ 556 | "code": 500, 557 | "status": false, 558 | "error": "INTERNAL_SERVER_ERROR", 559 | "message": "general (unknown) error" 560 | }, null); 561 | } 562 | } 563 | } 564 | 565 | type pixartadata = { 566 | prompt: string, 567 | data?: { 568 | prompt_negative?: string, 569 | sampler?: "DPM-Solver" | "SA-Solver", 570 | image_style?: "(No style)" | "Cinematic" | "Photographic" | "Anime" | "Manga" | "Digital Art" | "Pixel art" | "Fantasy art" | "Neonpunk" | "3D Model", 571 | width?: Number, 572 | height?: Number, 573 | dpm_guidance_scale?: Number, 574 | dpm_inference_steps?: Number, 575 | sa_guidance_scale?: Number, 576 | sa_inference_steps?: Number 577 | } 578 | } 579 | 580 | type pixartlcmdata = { 581 | prompt: string, 582 | data?: { 583 | prompt_negative?: string, 584 | image_style?: "(No style)" | "Cinematic" | "Photographic" | "Anime" | "Manga" | "Digital Art" | "Pixel art" | "Fantasy art" | "Neonpunk" | "3D Model", 585 | width?: Number, 586 | height?: Number, 587 | lcm_inference_steps?: Number 588 | } 589 | } 590 | 591 | class pixart { 592 | static async a({ 593 | prompt = "", 594 | data = { 595 | prompt_negative: "", 596 | sampler: "DPM-Solver", 597 | image_style: "(No style)", 598 | width: 1024, 599 | height: 1024, 600 | dpm_guidance_scale: 4.5, 601 | dpm_inference_steps: 14, 602 | sa_guidance_scale: 3, 603 | sa_inference_steps: 25 604 | } 605 | }: pixartadata){ 606 | return new Promise(async (res, rej) => { 607 | try { 608 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 609 | prompt: prompt != undefined && prompt != null ? prompt : "", 610 | model: "pixart-a", 611 | data: { 612 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 613 | sampler: data != undefined && data != null && data.sampler != undefined && data.sampler != null ? data.sampler : "DPM-Solver", 614 | image_style: data != undefined && data != null && data.image_style != undefined && data.image_style != null ? data.image_style : "(No style)", 615 | width: data != undefined && data != null && data.width != undefined && data.width != null ? data.width : 1024, 616 | height: data != undefined && data != null && data.height != undefined && data.height != null ? data.height : 1024, 617 | dpm_guidance_scale: data != undefined && data != null && data.dpm_guidance_scale != undefined && data.dpm_guidance_scale != null ? data.dpm_guidance_scale : 4.5, 618 | dpm_inference_steps: data != undefined && data != null && data.dpm_inference_steps != undefined && data.dpm_inference_steps != null ? data.dpm_inference_steps : 14, 619 | sa_guidance_scale: data != undefined && data != null && data.sa_guidance_scale != undefined && data.sa_guidance_scale != null ? data.sa_guidance_scale : 3, 620 | sa_inference_steps: data != undefined && data != null && data.sa_inference_steps != undefined && data.sa_inference_steps != null ? data.sa_inference_steps : 25 621 | } 622 | }); 623 | 624 | return res(response); 625 | } catch(e){ 626 | if(typeof(e) == "object"){ 627 | return rej(e); 628 | } else { 629 | return rej({ 630 | "code": 500, 631 | "status": false, 632 | "error": "INTERNAL_SERVER_ERROR", 633 | "message": "general (unknown) error" 634 | }); 635 | } 636 | } 637 | }); 638 | } 639 | static async lcm({ 640 | prompt = "", 641 | data = { 642 | prompt_negative: "", 643 | image_style: "(No style)", 644 | width: 1024, 645 | height: 1024, 646 | lcm_inference_steps: 9 647 | } 648 | }: pixartlcmdata){ 649 | return new Promise(async (res, rej) => { 650 | try { 651 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 652 | prompt: prompt != undefined && prompt != null ? prompt : "", 653 | model: "pixart-lcm", 654 | data: { 655 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 656 | image_style: data != undefined && data != null && data.image_style != undefined && data.image_style != null ? data.image_style : "(No style)", 657 | width: data != undefined && data != null && data.width != undefined && data.width != null ? data.width : 1024, 658 | height: data != undefined && data != null && data.height != undefined && data.height != null ? data.height : 1024, 659 | lcm_inference_steps: data != undefined && data != null && data.lcm_inference_steps != undefined && data.lcm_inference_steps != null ? data.lcm_inference_steps : 9 660 | } 661 | }); 662 | 663 | return res(response); 664 | } catch(e){ 665 | if(typeof(e) == "object"){ 666 | return rej(e); 667 | } else { 668 | return rej({ 669 | "code": 500, 670 | "status": false, 671 | "error": "INTERNAL_SERVER_ERROR", 672 | "message": "general (unknown) error" 673 | }); 674 | } 675 | } 676 | }); 677 | } 678 | } 679 | 680 | type dalledata = { 681 | prompt: string 682 | } 683 | 684 | type dalle2data = { 685 | prompt: string, 686 | data?: { 687 | prompt_negative?: String, 688 | width?: Number, 689 | height?: Number, 690 | guidance_scale?: Number 691 | } 692 | } 693 | 694 | class dalle { 695 | static async v1({ 696 | prompt = "" 697 | }: dalledata){ 698 | return new Promise(async (res, rej) => { 699 | try { 700 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 701 | prompt: prompt != undefined && prompt != null ? prompt : "", 702 | model: "dalle" 703 | }); 704 | 705 | return res(response); 706 | } catch(e){ 707 | if(typeof(e) == "object"){ 708 | return rej(e); 709 | } else { 710 | return rej({ 711 | "code": 500, 712 | "status": false, 713 | "error": "INTERNAL_SERVER_ERROR", 714 | "message": "general (unknown) error" 715 | }); 716 | } 717 | } 718 | }); 719 | } 720 | static async v2({ 721 | prompt = "", 722 | data = { 723 | prompt_negative: "", 724 | width: 1024, 725 | height: 1024, 726 | guidance_scale: 6 727 | } 728 | }: dalle2data){ 729 | return new Promise(async (res, rej) => { 730 | try { 731 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 732 | prompt: prompt != undefined && prompt != null ? prompt : "", 733 | model: "dalle2", 734 | data: { 735 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 736 | width: data != undefined && data != null && data.width != undefined && data.width != null ? data.width : 1024, 737 | height: data != undefined && data != null && data.height != undefined && data.height != null ? data.height : 1024, 738 | guidance_scale: data != undefined && data != null && data.guidance_scale != undefined && data.guidance_scale != null ? data.guidance_scale : 6 739 | } 740 | }); 741 | 742 | return res(response); 743 | } catch(e){ 744 | if(typeof(e) == "object"){ 745 | return rej(e); 746 | } else { 747 | return rej({ 748 | "code": 500, 749 | "status": false, 750 | "error": "INTERNAL_SERVER_ERROR", 751 | "message": "general (unknown) error" 752 | }); 753 | } 754 | } 755 | }); 756 | } 757 | static async mini({ 758 | prompt = "" 759 | }: dalledata){ 760 | return new Promise(async (res, rej) => { 761 | try { 762 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 763 | prompt: prompt != undefined && prompt != null ? prompt : "", 764 | model: "dalle-mini" 765 | }); 766 | 767 | return res(response); 768 | } catch(e){ 769 | if(typeof(e) == "object"){ 770 | return rej(e); 771 | } else { 772 | return rej({ 773 | "code": 500, 774 | "status": false, 775 | "error": "INTERNAL_SERVER_ERROR", 776 | "message": "general (unknown) error" 777 | }); 778 | } 779 | } 780 | }); 781 | } 782 | } 783 | 784 | type prodiav1data = { 785 | prompt: string, 786 | data?: { 787 | model?: string, 788 | steps?: number, 789 | cfg_scale?: number, 790 | sampler?: string, 791 | negative_prompt?: string 792 | } 793 | } 794 | 795 | type prodiastablediffusion = { 796 | prompt: string, 797 | data?: { 798 | prompt_negative?: string, 799 | model?: string, 800 | sampling_method?: string, 801 | sampling_steps?: number, 802 | width?: number, 803 | height?: number, 804 | cfg_scale?: number 805 | } 806 | } 807 | 808 | class prodia { 809 | static async v1({ 810 | prompt = "", 811 | data = { 812 | model: "absolutereality_V16.safetensors [37db0fc3]", 813 | steps: 25, 814 | cfg_scale: 7, 815 | sampler: "DPM++ 2M Karras", 816 | negative_prompt: "" 817 | } 818 | }: prodiav1data){ 819 | return new Promise(async (res, rej) => { 820 | try { 821 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 822 | prompt: prompt != undefined && prompt != null ? prompt : "", 823 | model: "prodia", 824 | data: { 825 | model: data != undefined && data != null && data.model != undefined && data.model != null ? data.model : "absolutereality_V16.safetensors [37db0fc3]", 826 | steps: data != undefined && data != null && data.steps != undefined && data.steps != null ? data.steps : 25, 827 | cfg_scale: data != undefined && data != null && data.cfg_scale != undefined && data.cfg_scale != null ? data.cfg_scale : 7, 828 | sampler: data != undefined && data != null && data.sampler != undefined && data.sampler != null ? data.sampler : "DPM++ 2M Karras", 829 | negative_prompt: data != undefined && data != null && data.negative_prompt != undefined && data.negative_prompt != null ? data.negative_prompt : "" 830 | } 831 | }); 832 | 833 | return res(response); 834 | } catch(e){ 835 | if(typeof(e) == "object"){ 836 | return rej(e); 837 | } else { 838 | return rej({ 839 | "code": 500, 840 | "status": false, 841 | "error": "INTERNAL_SERVER_ERROR", 842 | "message": "general (unknown) error" 843 | }); 844 | } 845 | } 846 | }); 847 | } 848 | static async stablediffusion({ 849 | prompt = "", 850 | data = { 851 | prompt_negative: "", 852 | model: "absolutereality_v181.safetensors [3d9d4d2b]", 853 | sampling_method: "DPM++ 2M Karras", 854 | sampling_steps: 25, 855 | width: 512, 856 | height: 512, 857 | cfg_scale: 7 858 | } 859 | }: prodiastablediffusion){ 860 | return new Promise(async (res, rej) => { 861 | try { 862 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 863 | prompt: prompt != undefined && prompt != null ? prompt : "", 864 | model: "prodia-stablediffusion", 865 | data: { 866 | model: data != undefined && data != null && data.model != undefined && data.model != null ? data.model : "absolutereality_v181.safetensors [3d9d4d2b]", 867 | sampling_method: data != undefined && data != null && data.sampling_method != undefined && data.sampling_method != null ? data.sampling_method : "DPM++ 2M Karras", 868 | sampling_steps: data != undefined && data != null && data.sampling_steps != undefined && data.sampling_steps != null ? data.sampling_steps : 25, 869 | width: data != undefined && data != null && data.width != undefined && data.width != null ? data.width : 512, 870 | height: data != undefined && data != null && data.height != undefined && data.height != null ? data.height : 512, 871 | cfg_scale: data != undefined && data != null && data.cfg_scale != undefined && data.cfg_scale != null ? data.cfg_scale : 7, 872 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 873 | } 874 | }); 875 | 876 | return res(response); 877 | } catch(e){ 878 | if(typeof(e) == "object"){ 879 | return rej(e); 880 | } else { 881 | return rej({ 882 | "code": 500, 883 | "status": false, 884 | "error": "INTERNAL_SERVER_ERROR", 885 | "message": "general (unknown) error" 886 | }); 887 | } 888 | } 889 | }); 890 | } 891 | static async stablediffusion_xl({ 892 | prompt = "", 893 | data = { 894 | prompt_negative: "", 895 | model: "sd_xl_base_1.0.safetensors [be9edd61]", 896 | sampling_method: "DPM++ 2M Karras", 897 | sampling_steps: 25, 898 | width: 1024, 899 | height: 1024, 900 | cfg_scale: 7 901 | } 902 | }: prodiastablediffusion){ 903 | return new Promise(async (res, rej) => { 904 | try { 905 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 906 | prompt: prompt != undefined && prompt != null ? prompt : "", 907 | model: "prodia-stablediffusion-xl", 908 | data: { 909 | model: data != undefined && data != null && data.model != undefined && data.model != null ? data.model : "sd_xl_base_1.0.safetensors [be9edd61]", 910 | sampling_method: data != undefined && data != null && data.sampling_method != undefined && data.sampling_method != null ? data.sampling_method : "DPM++ 2M Karras", 911 | sampling_steps: data != undefined && data != null && data.sampling_steps != undefined && data.sampling_steps != null ? data.sampling_steps : 25, 912 | width: data != undefined && data != null && data.width != undefined && data.width != null ? data.width : 1024, 913 | height: data != undefined && data != null && data.height != undefined && data.height != null ? data.height : 1024, 914 | cfg_scale: data != undefined && data != null && data.cfg_scale != undefined && data.cfg_scale != null ? data.cfg_scale : 7, 915 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 916 | } 917 | }); 918 | 919 | return res(response); 920 | } catch(e){ 921 | if(typeof(e) == "object"){ 922 | return rej(e); 923 | } else { 924 | return rej({ 925 | "code": 500, 926 | "status": false, 927 | "error": "INTERNAL_SERVER_ERROR", 928 | "message": "general (unknown) error" 929 | }); 930 | } 931 | } 932 | }); 933 | } 934 | } 935 | 936 | type diffusionv1data = { 937 | prompt: string 938 | } 939 | 940 | type diffusionv2data = { 941 | prompt: string, 942 | data?: { 943 | prompt_negative?: string, 944 | guidance_scale?: Number 945 | } 946 | } 947 | 948 | type diffusionxldata = { 949 | prompt: string, 950 | data?: { 951 | prompt_negative?: string, 952 | image_style?: "(No style)" | "Cinematic" | "Photographic" | "Anime" | "Manga" | "Digital Art" | "Pixel art" | "Fantasy art" | "Neonpunk" | "3D Model", 953 | guidance_scale?: number 954 | } 955 | } 956 | 957 | class stablediffusion { 958 | static async v1({ 959 | prompt = "" 960 | }: diffusionv1data){ 961 | return new Promise(async (res, rej) => { 962 | try { 963 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 964 | prompt: prompt != undefined && prompt != null ? prompt : "", 965 | model: "stablediffusion-1.5" 966 | }); 967 | 968 | return res(response); 969 | } catch(e){ 970 | if(typeof(e) == "object"){ 971 | return rej(e); 972 | } else { 973 | return rej({ 974 | "code": 500, 975 | "status": false, 976 | "error": "INTERNAL_SERVER_ERROR", 977 | "message": "general (unknown) error" 978 | }); 979 | } 980 | } 981 | }); 982 | } 983 | static async v2({ 984 | prompt = "", 985 | data = { 986 | prompt_negative: "", 987 | guidance_scale: 9 988 | } 989 | }: diffusionv2data){ 990 | return new Promise(async (res, rej) => { 991 | try { 992 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 993 | prompt: prompt != undefined && prompt != null ? prompt : "", 994 | model: "stablediffusion-2.1", 995 | data: { 996 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 997 | guidance_scale: data != undefined && data != null && data.guidance_scale != undefined && data.guidance_scale != null ? data.guidance_scale : 9, 998 | } 999 | }); 1000 | 1001 | return res(response); 1002 | } catch(e){ 1003 | if(typeof(e) == "object"){ 1004 | return rej(e); 1005 | } else { 1006 | return rej({ 1007 | "code": 500, 1008 | "status": false, 1009 | "error": "INTERNAL_SERVER_ERROR", 1010 | "message": "general (unknown) error" 1011 | }); 1012 | } 1013 | } 1014 | }); 1015 | } 1016 | static async xl({ 1017 | prompt = "", 1018 | data = { 1019 | prompt_negative: "", 1020 | image_style: "(No style)", 1021 | guidance_scale: 7.5 1022 | } 1023 | }: diffusionxldata){ 1024 | return new Promise(async (res, rej) => { 1025 | try { 1026 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 1027 | prompt: prompt != undefined && prompt != null ? prompt : "", 1028 | model: "stablediffusion-xl", 1029 | data: { 1030 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 1031 | image_style: data != undefined && data != null && data.image_style != undefined && data.image_style != null ? data.image_style : "(No style)", 1032 | guidance_scale: data != undefined && data != null && data.guidance_scale != undefined && data.guidance_scale != null ? data.guidance_scale : 7.5, 1033 | } 1034 | }); 1035 | 1036 | return res(response); 1037 | } catch(e){ 1038 | if(typeof(e) == "object"){ 1039 | return rej(e); 1040 | } else { 1041 | return rej({ 1042 | "code": 500, 1043 | "status": false, 1044 | "error": "INTERNAL_SERVER_ERROR", 1045 | "message": "general (unknown) error" 1046 | }); 1047 | } 1048 | } 1049 | }); 1050 | } 1051 | } 1052 | 1053 | type emidata = { 1054 | prompt: string 1055 | } 1056 | 1057 | const emi = async ({ 1058 | prompt = "" 1059 | }: emidata) => { 1060 | return new Promise(async (res, rej) => { 1061 | try { 1062 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 1063 | prompt: prompt != undefined && prompt != null ? prompt : "", 1064 | model: "emi" 1065 | }); 1066 | 1067 | return res(response); 1068 | } catch(e){ 1069 | if(typeof(e) == "object"){ 1070 | return rej(e); 1071 | } else { 1072 | return rej({ 1073 | "code": 500, 1074 | "status": false, 1075 | "error": "INTERNAL_SERVER_ERROR", 1076 | "message": "general (unknown) error" 1077 | }); 1078 | } 1079 | } 1080 | }); 1081 | } 1082 | 1083 | type rendpixeldata = { 1084 | prompt: string, 1085 | data?: { 1086 | prompt_negative?: string 1087 | } 1088 | } 1089 | 1090 | const render3d = async ({ 1091 | prompt = "", 1092 | data = { 1093 | prompt_negative: "" 1094 | } 1095 | }: rendpixeldata) => { 1096 | return new Promise(async (res, rej) => { 1097 | try { 1098 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 1099 | prompt: prompt != undefined && prompt != null ? prompt : "", 1100 | model: "render3d", 1101 | data: { 1102 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "" 1103 | } 1104 | }); 1105 | 1106 | return res(response); 1107 | } catch(e){ 1108 | if(typeof(e) == "object"){ 1109 | return rej(e); 1110 | } else { 1111 | return rej({ 1112 | "code": 500, 1113 | "status": false, 1114 | "error": "INTERNAL_SERVER_ERROR", 1115 | "message": "general (unknown) error" 1116 | }); 1117 | } 1118 | } 1119 | }); 1120 | } 1121 | 1122 | const pixelart = async ({ 1123 | prompt = "", 1124 | data = { 1125 | prompt_negative: "" 1126 | } 1127 | }: rendpixeldata) => { 1128 | return new Promise(async (res, rej) => { 1129 | try { 1130 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 1131 | prompt: prompt != undefined && prompt != null ? prompt : "", 1132 | model: "pixel-art", 1133 | data: { 1134 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "" 1135 | } 1136 | }); 1137 | 1138 | return res(response); 1139 | } catch(e){ 1140 | if(typeof(e) == "object"){ 1141 | return rej(e); 1142 | } else { 1143 | return rej({ 1144 | "code": 500, 1145 | "status": false, 1146 | "error": "INTERNAL_SERVER_ERROR", 1147 | "message": "general (unknown) error" 1148 | }); 1149 | } 1150 | } 1151 | }); 1152 | } 1153 | 1154 | type playgrounddata = { 1155 | prompt: string, 1156 | data?: { 1157 | prompt_negative?: String, 1158 | width?: Number, 1159 | height?: Number, 1160 | guidance_scale?: Number 1161 | } 1162 | } 1163 | 1164 | const playground = async ({ 1165 | prompt = "", 1166 | data = { 1167 | prompt_negative: "", 1168 | width: 1024, 1169 | height: 1024, 1170 | guidance_scale: 3 1171 | } 1172 | }: playgrounddata) => { 1173 | return new Promise(async (res, rej) => { 1174 | try { 1175 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 1176 | prompt: prompt != undefined && prompt != null ? prompt : "", 1177 | model: "playground", 1178 | data: { 1179 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 1180 | width: data != undefined && data != null && data.width != undefined && data.width != null ? data.width : 1024, 1181 | height: data != undefined && data != null && data.height != undefined && data.height != null ? data.height : 1024, 1182 | guidance_scale: data != undefined && data != null && data.guidance_scale != undefined && data.guidance_scale != null ? data.guidance_scale : 6, 1183 | } 1184 | }); 1185 | 1186 | return res(response); 1187 | } catch(e){ 1188 | if(typeof(e) == "object"){ 1189 | return rej(e); 1190 | } else { 1191 | return rej({ 1192 | "code": 500, 1193 | "status": false, 1194 | "error": "INTERNAL_SERVER_ERROR", 1195 | "message": "general (unknown) error" 1196 | }); 1197 | } 1198 | } 1199 | }); 1200 | } 1201 | 1202 | type animaginedata = { 1203 | prompt: string, 1204 | data?: { 1205 | prompt_negative?: String, 1206 | quality_tags?: "Standard" | "Light" | "Heavy" | "(None)", 1207 | style_present?: "(None)" | "Cinematic" | "Photographic" | "Anime" | "Manga" | "Digital Art" | "Pixel art" | "Fantasy art" | "Neonpunk" | "3D Model", 1208 | width?: Number, 1209 | height?: Number, 1210 | strength?: Number, 1211 | upscale?: Number, 1212 | sampler?: "Euler a" | "DPM++ 2M Karras" | "DPM++ SDE Karras" | "DPM++ 2M SDE Karras" | "Euler" | "DDIM", 1213 | guidance_scale?: Number, 1214 | inference_steps?: Number 1215 | } 1216 | } 1217 | 1218 | const animagine = async ({ 1219 | prompt = "", 1220 | data = { 1221 | prompt_negative: "", 1222 | quality_tags: "Standard", 1223 | style_present: "(None)", 1224 | width: 1024, 1225 | height: 1024, 1226 | strength: 0.5, 1227 | upscale: 1.5, 1228 | sampler: "Euler a", 1229 | guidance_scale: 7, 1230 | inference_steps: 28 1231 | } 1232 | }: animaginedata) => { 1233 | return new Promise(async (res, rej) => { 1234 | try { 1235 | let response = await consult_('https://nexra.aryahcr.cc/api/image/complements', { 1236 | prompt: prompt != undefined && prompt != null ? prompt : "", 1237 | model: "animagine-xl", 1238 | data: { 1239 | prompt_negative: data != undefined && data != null && data.prompt_negative != undefined && data.prompt_negative != null ? data.prompt_negative : "", 1240 | width: data != undefined && data != null && data.width != undefined && data.width != null ? data.width : 1024, 1241 | height: data != undefined && data != null && data.height != undefined && data.height != null ? data.height : 1024, 1242 | guidance_scale: data != undefined && data != null && data.guidance_scale != undefined && data.guidance_scale != null ? data.guidance_scale : 7, 1243 | quality_tags: data != undefined && data != null && data.quality_tags != undefined && data.quality_tags != null ? data.quality_tags : "Standard", 1244 | style_present: data != undefined && data != null && data.style_present != undefined && data.style_present != null ? data.style_present : "(None)", 1245 | strength: data != undefined && data != null && data.strength != undefined && data.strength != null ? data.strength : 0.5, 1246 | upscale: data != undefined && data != null && data.upscale != undefined && data.upscale != null ? data.upscale : 1.5, 1247 | sampler: data != undefined && data != null && data.sampler != undefined && data.sampler != null ? data.sampler : "Euler a", 1248 | inference_steps: data != undefined && data != null && data.inference_steps != undefined && data.inference_steps != null ? data.inference_steps : 28 1249 | } 1250 | }); 1251 | 1252 | return res(response); 1253 | } catch(e){ 1254 | if(typeof(e) == "object"){ 1255 | return rej(e); 1256 | } else { 1257 | return rej({ 1258 | "code": 500, 1259 | "status": false, 1260 | "error": "INTERNAL_SERVER_ERROR", 1261 | "message": "general (unknown) error" 1262 | }); 1263 | } 1264 | } 1265 | }); 1266 | } 1267 | 1268 | export { 1269 | gpt, 1270 | bing, 1271 | pixart, 1272 | dalle, 1273 | prodia, 1274 | stablediffusion, 1275 | emi, 1276 | llama2, 1277 | pixelart, 1278 | render3d, 1279 | animagine, 1280 | nexra, 1281 | playground 1282 | } 1283 | 1284 | export default { 1285 | gpt, 1286 | bing, 1287 | pixart, 1288 | dalle, 1289 | prodia, 1290 | stablediffusion, 1291 | emi, 1292 | llama2, 1293 | pixelart, 1294 | render3d, 1295 | animagine, 1296 | nexra, 1297 | playground 1298 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "commonjs", /* Specify what module code is generated. */ 29 | // "rootDir": "./", /* Specify the root folder within your source files. */ 30 | // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 42 | // "resolveJsonModule": true, /* Enable importing .json files. */ 43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 45 | 46 | /* JavaScript Support */ 47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 50 | 51 | /* Emit */ 52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 58 | // "outDir": "./", /* Specify an output folder for all emitted files. */ 59 | // "removeComments": true, /* Disable emitting comments. */ 60 | // "noEmit": true, /* Disable emitting files from a compilation. */ 61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 68 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 75 | 76 | /* Interop Constraints */ 77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ 79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 83 | 84 | /* Type Checking */ 85 | "strict": true, /* Enable all strict type-checking options. */ 86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 104 | 105 | /* Completeness */ 106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 108 | } 109 | } --------------------------------------------------------------------------------