├── .github ├── FUNDING.yml └── workflows │ └── npm-publish.yml ├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── build ├── cjs │ ├── index.cjs │ └── tsconfig.cjs.tsbuildinfo └── esm │ ├── index.js │ └── tsconfig.esm.tsbuildinfo ├── cli.cjs ├── compilec.js ├── example ├── chat.cjs ├── check-nsfw.cjs ├── image.cjs └── models.cjs ├── package.json ├── pnpm-lock.yaml ├── src └── index.ts ├── tsconfig.cjs.json ├── tsconfig.esm.json ├── tsconfig.json ├── tsconfig.types.json └── types ├── index.d.ts └── tsconfig.types.tsbuildinfo /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ["Rstacx"] -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | name: "publish npm" 2 | 3 | on: push 4 | 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: checkout 10 | uses: actions/checkout@v2 11 | - name: node 12 | uses: actions/setup-node@v2 13 | with: 14 | node-version: 16 15 | registry-url: https://registry.npmjs.org 16 | - name: install dependencies 17 | run: npm install 18 | - name: Build typescript 19 | run: npm run compile 20 | - name: publish 21 | run: npm publish --access public 22 | env: 23 | NODE_AUTH_TOKEN: ${{ secrets.npm_token }} 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} 2 | registry=https://registry.npmjs.org/ 3 | always-auth=true 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 R Nilaweera 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

RsnChat

2 |

The ultimate AI-powered RsnChat

3 | 4 | This package for AI chats and AI images. 5 | 6 | ## Installation 7 | 8 | **Installation For CLI** 9 | 10 | ```bash 11 | npm i -g rsnchat 12 | ``` 13 | 14 | **Installation** 15 | 16 | ```bash 17 | npm i rsnchat 18 | ``` 19 | 20 | # APIKEY 21 | 22 | Discord : [https://api.rnilaweera.lk/discord](https://api.rnilaweera.lk/discord) 23 | 24 | Join discord server and create account with **/register** slash command and get your apikey with **/generate-key** slash command for free! 25 | 26 | ## Usage Available Models 27 | 28 | ```javascript 29 | const { RsnChat } = require("rsnchat"); 30 | 31 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 32 | 33 | rsnchat.getModels().then((models) => { 34 | console.log("Active Chat Models:", models.chatModels); 35 | console.log("Active Image Models:", models.imageModels); 36 | }).catch((error) => { 37 | console.error(error.message); 38 | }); 39 | ``` 40 | 41 | ## Usage Chat Completion 42 | 43 | ```javascript 44 | const { RsnChat } = require("rsnchat"); 45 | 46 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 47 | 48 | const prompt = "Hello, what is your name?" 49 | const model = "gemini" // gpt, grok-2, llama, etc... (https://api.rnilaweera.lk/api/models) 50 | 51 | rsnchat.chat(prompt, model).then((response) => { 52 | console.log(response); 53 | }).catch((error) => { 54 | console.error(error.message); 55 | }); 56 | ``` 57 | 58 | ## Usage Image Generation 59 | 60 | ```javascript 61 | const { RsnChat } = require("rsnchat"); 62 | 63 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 64 | 65 | const prompt = "beautiful girl"; 66 | const model = "flux"; // rsnlabs, photograpy, etc... (https://api.rnilaweera.lk/api/models) 67 | 68 | rsnchat.image(prompt, model).then((response) => { 69 | console.log(response); 70 | }).catch((error) => { 71 | console.error(error.message); 72 | }); 73 | ``` 74 | 75 | ## Usage Check NSFW 76 | 77 | ```javascript 78 | const { RsnChat } = require("rsnchat"); 79 | 80 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 81 | 82 | const image_url = ""; 83 | 84 | rsnchat.checkNSFW(image_url).then((response) => { 85 | console.log(response); 86 | }).catch((error) => { 87 | console.error(error.message); 88 | }); 89 | ``` 90 | 91 | **Example CLI Command** 92 | 93 | ```hs 94 | rsnchat 95 | ``` -------------------------------------------------------------------------------- /build/cjs/index.cjs: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 4 | return new (P || (P = Promise))(function (resolve, reject) { 5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 8 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 9 | }); 10 | }; 11 | var __importDefault = (this && this.__importDefault) || function (mod) { 12 | return (mod && mod.__esModule) ? mod : { "default": mod }; 13 | }; 14 | Object.defineProperty(exports, "__esModule", { value: true }); 15 | exports.RsnChat = void 0; 16 | const axios_1 = __importDefault(require("axios")); 17 | const apiUrl = "https://api.rnilaweera.lk/api/"; 18 | class RsnChat { 19 | /** 20 | * **RsnChat** 21 | * 22 | * Discord: https://api.rnilaweera.lk/discord 23 | * 24 | * Join the Discord server and create an account with `/register` slash command. 25 | * Get your API key using `/generate-key` for free! 26 | * 27 | * @param {string} apikey - RsnChat API Key (required) 28 | */ 29 | constructor(apikey) { 30 | if (!apikey) { 31 | throw new Error("Please provide an API key."); 32 | } 33 | this.headers = { Authorization: `Bearer ${apikey}` }; 34 | } 35 | /** 36 | * Get available active models list (Chat & Image) 37 | * @returns {Promise} - Returns active chat and image models 38 | * @example 39 | * ```js 40 | * const rsnchat = new RsnChat("your_api_key"); 41 | * rsnchat.getModels().then(models => { 42 | * console.log(models.chatModels); // Active chat models 43 | * console.log(models.imageModels); // Active image models 44 | * }); 45 | * ``` 46 | */ 47 | getModels() { 48 | return __awaiter(this, void 0, void 0, function* () { 49 | var _a, _b; 50 | try { 51 | const response = yield axios_1.default.get(`${apiUrl}models`, { headers: this.headers }); 52 | const chatModels = response.data.chat_models 53 | .filter((model) => model.status === "active") 54 | .map((model) => model.name); 55 | const imageModels = response.data.image_models 56 | .filter((model) => model.status === "active") 57 | .map((model) => model.name); 58 | return { chatModels, imageModels }; 59 | } 60 | catch (error) { 61 | throw new Error(`Failed to fetch models: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 62 | } 63 | }); 64 | } 65 | /** 66 | * Generate Text Completion 67 | * @param {string} prompt - Required text input 68 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 69 | * @returns {Promise} 70 | */ 71 | chat(prompt, model) { 72 | return __awaiter(this, void 0, void 0, function* () { 73 | var _a, _b; 74 | if (!prompt || typeof prompt !== "string") { 75 | throw new Error("Prompt is required and must be a string."); 76 | } 77 | if (!model || typeof model !== "string") { 78 | throw new Error("Model is required and must be a string."); 79 | } 80 | try { 81 | const response = yield axios_1.default.post(`${apiUrl}chat/generate`, { prompt, model }, { headers: this.headers }); 82 | return response.data; 83 | } 84 | catch (error) { 85 | throw new Error(`Chat Generation Error: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 86 | } 87 | }); 88 | } 89 | /** 90 | * Generate Image Completion 91 | * @param {string} prompt - Required image description 92 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 93 | * @returns {Promise} 94 | */ 95 | image(prompt, model) { 96 | return __awaiter(this, void 0, void 0, function* () { 97 | var _a, _b; 98 | if (!prompt || typeof prompt !== "string") { 99 | throw new Error("Prompt is required and must be a string."); 100 | } 101 | if (!model || typeof model !== "string") { 102 | throw new Error("Model is required and must be a string."); 103 | } 104 | try { 105 | const response = yield axios_1.default.post(`${apiUrl}image/generate`, { prompt, model }, { headers: this.headers }); 106 | return response.data; 107 | } 108 | catch (error) { 109 | throw new Error(`Image Generation Error: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 110 | } 111 | }); 112 | } 113 | /** 114 | * Check NSFW Image Completion 115 | * @param {string} image_url - Required image url 116 | * @returns {Promise} 117 | */ 118 | checkNSFW(image_url) { 119 | return __awaiter(this, void 0, void 0, function* () { 120 | var _a, _b; 121 | if (!image_url || typeof image_url !== "string") { 122 | throw new Error("image_url is required and must be a string."); 123 | } 124 | try { 125 | const response = yield axios_1.default.post(`${apiUrl}image/check-nsfw`, { image_url }, { headers: this.headers }); 126 | return response.data; 127 | } 128 | catch (error) { 129 | throw new Error(`Check NSFW Error: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 130 | } 131 | }); 132 | } 133 | } 134 | exports.RsnChat = RsnChat; 135 | -------------------------------------------------------------------------------- /build/cjs/tsconfig.cjs.tsbuildinfo: -------------------------------------------------------------------------------- 1 | {"root":["../../src/index.ts","../../types/index.d.ts"],"version":"5.7.3"} -------------------------------------------------------------------------------- /build/esm/index.js: -------------------------------------------------------------------------------- 1 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 2 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | import axios from "axios"; 11 | const apiUrl = "https://api.rnilaweera.lk/api/"; 12 | class RsnChat { 13 | /** 14 | * **RsnChat** 15 | * 16 | * Discord: https://api.rnilaweera.lk/discord 17 | * 18 | * Join the Discord server and create an account with `/register` slash command. 19 | * Get your API key using `/generate-key` for free! 20 | * 21 | * @param {string} apikey - RsnChat API Key (required) 22 | */ 23 | constructor(apikey) { 24 | if (!apikey) { 25 | throw new Error("Please provide an API key."); 26 | } 27 | this.headers = { Authorization: `Bearer ${apikey}` }; 28 | } 29 | /** 30 | * Get available active models list (Chat & Image) 31 | * @returns {Promise} - Returns active chat and image models 32 | * @example 33 | * ```js 34 | * const rsnchat = new RsnChat("your_api_key"); 35 | * rsnchat.getModels().then(models => { 36 | * console.log(models.chatModels); // Active chat models 37 | * console.log(models.imageModels); // Active image models 38 | * }); 39 | * ``` 40 | */ 41 | getModels() { 42 | return __awaiter(this, void 0, void 0, function* () { 43 | var _a, _b; 44 | try { 45 | const response = yield axios.get(`${apiUrl}models`, { headers: this.headers }); 46 | const chatModels = response.data.chat_models 47 | .filter((model) => model.status === "active") 48 | .map((model) => model.name); 49 | const imageModels = response.data.image_models 50 | .filter((model) => model.status === "active") 51 | .map((model) => model.name); 52 | return { chatModels, imageModels }; 53 | } 54 | catch (error) { 55 | throw new Error(`Failed to fetch models: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 56 | } 57 | }); 58 | } 59 | /** 60 | * Generate Text Completion 61 | * @param {string} prompt - Required text input 62 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 63 | * @returns {Promise} 64 | */ 65 | chat(prompt, model) { 66 | return __awaiter(this, void 0, void 0, function* () { 67 | var _a, _b; 68 | if (!prompt || typeof prompt !== "string") { 69 | throw new Error("Prompt is required and must be a string."); 70 | } 71 | if (!model || typeof model !== "string") { 72 | throw new Error("Model is required and must be a string."); 73 | } 74 | try { 75 | const response = yield axios.post(`${apiUrl}chat/generate`, { prompt, model }, { headers: this.headers }); 76 | return response.data; 77 | } 78 | catch (error) { 79 | throw new Error(`Chat Generation Error: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 80 | } 81 | }); 82 | } 83 | /** 84 | * Generate Image Completion 85 | * @param {string} prompt - Required image description 86 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 87 | * @returns {Promise} 88 | */ 89 | image(prompt, model) { 90 | return __awaiter(this, void 0, void 0, function* () { 91 | var _a, _b; 92 | if (!prompt || typeof prompt !== "string") { 93 | throw new Error("Prompt is required and must be a string."); 94 | } 95 | if (!model || typeof model !== "string") { 96 | throw new Error("Model is required and must be a string."); 97 | } 98 | try { 99 | const response = yield axios.post(`${apiUrl}image/generate`, { prompt, model }, { headers: this.headers }); 100 | return response.data; 101 | } 102 | catch (error) { 103 | throw new Error(`Image Generation Error: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 104 | } 105 | }); 106 | } 107 | /** 108 | * Check NSFW Image Completion 109 | * @param {string} image_url - Required image url 110 | * @returns {Promise} 111 | */ 112 | checkNSFW(image_url) { 113 | return __awaiter(this, void 0, void 0, function* () { 114 | var _a, _b; 115 | if (!image_url || typeof image_url !== "string") { 116 | throw new Error("image_url is required and must be a string."); 117 | } 118 | try { 119 | const response = yield axios.post(`${apiUrl}image/check-nsfw`, { image_url }, { headers: this.headers }); 120 | return response.data; 121 | } 122 | catch (error) { 123 | throw new Error(`Check NSFW Error: ${((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || error.message}`); 124 | } 125 | }); 126 | } 127 | } 128 | export { RsnChat }; 129 | -------------------------------------------------------------------------------- /build/esm/tsconfig.esm.tsbuildinfo: -------------------------------------------------------------------------------- 1 | {"root":["../../src/index.ts","../../types/index.d.ts"],"version":"5.7.3"} -------------------------------------------------------------------------------- /cli.cjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const { RsnChat } = require("./build/cjs/index.cjs"); 4 | const colors = require("colors"); 5 | const readline = require("readline"); 6 | const axios = require("axios"); 7 | 8 | const rl = readline.createInterface({ 9 | input: process.stdin, 10 | output: process.stdout, 11 | }); 12 | 13 | const asciiArt = ` 14 | ## 15 | #### #### ## ## 16 | ## # #### # ## ### # ## # ### ##### 17 | ## # ## ## ## ## ##### ## ## 18 | #### #### ## ## ## ## ## #### ## 19 | ## # #### ## ## ## ## ## ## ## ## 20 | ## # ## ## ## ### ## ## ## ## ## 21 | ## # #### ## ## #### ## ## ## # ### 22 | `; 23 | 24 | async function fetchActiveModels() { 25 | try { 26 | const response = await axios.get("https://api.rnilaweera.lk/api/models"); 27 | if (response.status === 200) { 28 | return response.data.chat_models 29 | .filter((model) => model.status === "active") 30 | .map((model) => model.name.toUpperCase()); 31 | } else { 32 | console.error(colors.red("Failed to fetch models. Using defaults.")); 33 | return ["GPT", "GEMINI", "GROK-2", "GROK-2-MINI"]; 34 | } 35 | } catch (error) { 36 | console.error(colors.red("Error fetching models:"), error.message); 37 | return ["GPT", "GEMINI", "GROK-2", "GROK-2-MINI"]; 38 | } 39 | } 40 | 41 | function promptApiKey() { 42 | console.log(colors.bold.green(asciiArt)); 43 | 44 | rl.question(colors.bold.green("Enter your API key: "), async (apiKey) => { 45 | try { 46 | const response = await axios.post( 47 | "https://api.rnilaweera.lk/api/auth/validate", 48 | { apikey: apiKey } 49 | ); 50 | 51 | if (response.status === 200) { 52 | const username = response.data.name; 53 | const rsnChat = new RsnChat(apiKey); 54 | startChat(rsnChat, username); 55 | } else { 56 | handleErrorResponse(response.status); 57 | } 58 | } catch (error) { 59 | if (error.response && error.response.status) { 60 | handleErrorResponse(error.response.status); 61 | } else { 62 | console.error(colors.red("Error validating API key:"), error.message); 63 | promptApiKey(); 64 | } 65 | } 66 | }); 67 | } 68 | 69 | function handleErrorResponse(status) { 70 | if (status === 401) { 71 | console.error(colors.red("Invalid API key. Please try again.")); 72 | } else if (status === 503) { 73 | console.error(colors.red("Service Unavailable - Maintain Mode")); 74 | } else { 75 | console.error( 76 | colors.red(`Unexpected response from the server. Status: ${status}. Please try again.`) 77 | ); 78 | } 79 | promptApiKey(); 80 | } 81 | 82 | async function startChat(rsnChat, username) { 83 | console.log(colors.bold.yellow(`\nWelcome to ${username}'s RsnChat CLI!\n`)); 84 | 85 | const availableModels = await fetchActiveModels(); 86 | 87 | function promptChatMethod() { 88 | console.log(colors.cyan(`Available chat models: ${availableModels.join(", ")}`)); 89 | 90 | rl.question(colors.cyan('Select a chat model or type "exit" to quit: '), (method) => { 91 | method = method.toUpperCase().trim(); 92 | if (method === "EXIT") { 93 | console.log(colors.yellow("\nExiting RsnChat CLI. Goodbye!\n")); 94 | rl.close(); 95 | } else if (availableModels.includes(method)) { 96 | promptUser(method, rsnChat); 97 | } else { 98 | console.error(colors.red("Invalid selection. Try again.")); 99 | promptChatMethod(); 100 | } 101 | }); 102 | } 103 | 104 | function promptUser(method, rsnChat) { 105 | rl.question(colors.green(`Enter your ${method} prompt (or type "exit" to quit): `), async (prompt) => { 106 | if (prompt.toLowerCase().trim() === "exit") { 107 | console.log(colors.yellow("\nExiting RsnChat CLI. Goodbye!\n")); 108 | rl.close(); 109 | } else { 110 | try { 111 | const response = await rsnChat.chat(prompt, method.toLowerCase()); 112 | console.log(colors.bold.blue(`${method} Response:`), response.message); 113 | } catch (error) { 114 | console.error(colors.red(`Error calling ${method}:`), error.message); 115 | } 116 | 117 | rl.question(colors.cyan(`Do you want to select another model or continue chatting with "${method}"? (type "exit" to quit, or "another" for a new model): `), (choice) => { 118 | if (choice.toLowerCase().trim() === "exit") { 119 | console.log(colors.yellow("\nExiting RsnChat CLI. Goodbye!\n")); 120 | rl.close(); 121 | } else if (choice.toLowerCase().trim() === "another") { 122 | promptChatMethod(); 123 | } else { 124 | promptUser(method, rsnChat); 125 | } 126 | }); 127 | } 128 | }); 129 | } 130 | 131 | promptChatMethod(); 132 | } 133 | 134 | promptApiKey(); -------------------------------------------------------------------------------- /compilec.js: -------------------------------------------------------------------------------- 1 | import { renameSync, readdirSync } from "fs"; 2 | 3 | readdirSync("./build/cjs").forEach((e) => { 4 | renameSync(`./build/cjs/${e}`, `./build/cjs/${e.replace(".js", ".cjs")}`); 5 | }); 6 | -------------------------------------------------------------------------------- /example/chat.cjs: -------------------------------------------------------------------------------- 1 | const { RsnChat } = require("../build/cjs/index.cjs"); 2 | 3 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 4 | 5 | const prompt = "Hello, what is your name?" 6 | const model = "gemini" 7 | 8 | rsnchat.chat(prompt, model).then((response) => { 9 | console.log(response); 10 | }).catch((error) => { 11 | console.error(error.message); 12 | }); -------------------------------------------------------------------------------- /example/check-nsfw.cjs: -------------------------------------------------------------------------------- 1 | const { RsnChat } = require("../build/cjs/index.cjs"); 2 | 3 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 4 | 5 | const image_url = ""; 6 | 7 | rsnchat.checkNSFW(image_url).then((response) => { 8 | console.log(response); 9 | }).catch((error) => { 10 | console.error(error.message); 11 | }); -------------------------------------------------------------------------------- /example/image.cjs: -------------------------------------------------------------------------------- 1 | const { RsnChat } = require("../build/cjs/index.cjs"); 2 | 3 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 4 | 5 | const prompt = "beautiful girl"; 6 | const model = "flux"; 7 | 8 | rsnchat.image(prompt, model).then((response) => { 9 | console.log(response); 10 | }).catch((error) => { 11 | console.error(error.message); 12 | }); -------------------------------------------------------------------------------- /example/models.cjs: -------------------------------------------------------------------------------- 1 | const { RsnChat } = require("../build/cjs/index.cjs"); 2 | 3 | const rsnchat = new RsnChat("rsnlabs_××××××××××××××××××××××××××××××"); 4 | 5 | rsnchat.getModels().then((models) => { 6 | console.log("Active Chat Models:", models.chatModels); 7 | console.log("Active Image Models:", models.imageModels); 8 | }).catch((error) => { 9 | console.error(error.message); 10 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rsnchat", 3 | "version": "5.0.0-beta.3", 4 | "description": "A package for AI chats and AI images.", 5 | "type": "module", 6 | "types": "./types/index.d.ts", 7 | "bin": { 8 | "rsnchat": "./cli.cjs" 9 | }, 10 | "exports": { 11 | ".": { 12 | "types": "./types/index.d.ts", 13 | "require": "./build/cjs/index.cjs", 14 | "import": "./build/esm/index.js", 15 | "default": "./build/esm/index.js" 16 | }, 17 | "./*": { 18 | "types": "./types/*.d.ts", 19 | "require": "./build/cjs/*.cjs", 20 | "import": "./build/esm/*.js", 21 | "default": "./build/esm/*.js" 22 | } 23 | }, 24 | "scripts": { 25 | "test": "node example/test.cjs && node example/image.cjs", 26 | "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json && node compilec.js", 27 | "build:clean": "rm -rf ./build", 28 | "build": "npm-run-all build:clean compile" 29 | }, 30 | "repository": { 31 | "type": "git", 32 | "url": "https://github.com/RsnLabs/rsnchat-js" 33 | }, 34 | "funding": { 35 | "type": "buymeacoffee", 36 | "url": "https://www.buymeacoffee.com/rnilaweera" 37 | }, 38 | "author": "rnilaweera", 39 | "license": "MIT", 40 | "keywords": [ 41 | "ai", 42 | "chatbot", 43 | "chatgpt", 44 | "gpt", 45 | "claude", 46 | "openchat", 47 | "bard", 48 | "llama", 49 | "mixtral", 50 | "gemini", 51 | "bing", 52 | "api", 53 | "image", 54 | "image-generator", 55 | "ai-images", 56 | "ai-images-generator", 57 | "gpt", 58 | "discord", 59 | "chat", 60 | "chatbot", 61 | "chatgpt4", 62 | "chatgpt-4", 63 | "openai", 64 | "open-ai", 65 | "bot", 66 | "robot", 67 | "axios", 68 | "free", 69 | "stable", 70 | "absolutebeauty", 71 | "icon", 72 | "sdxl", 73 | "dalle", 74 | "prodia", 75 | "kandinsky", 76 | "claude", 77 | "grok", 78 | "gemini", 79 | "deepseek" 80 | ], 81 | "dependencies": { 82 | "axios": "^1.6.3", 83 | "colors": "^1.4.0", 84 | "readline": "^1.3.0" 85 | }, 86 | "devDependencies": { 87 | "@types/node": "^20.11.6", 88 | "npm-run-all": "^4.1.5", 89 | "typescript": "^5.3.3", 90 | "undici-types": "^6.4.0" 91 | } 92 | } -------------------------------------------------------------------------------- /pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | dependencies: 8 | axios: 9 | specifier: ^1.6.3 10 | version: 1.6.6 11 | colors: 12 | specifier: ^1.4.0 13 | version: 1.4.0 14 | readline: 15 | specifier: ^1.3.0 16 | version: 1.3.0 17 | 18 | devDependencies: 19 | '@types/node': 20 | specifier: ^20.11.6 21 | version: 20.11.6 22 | typescript: 23 | specifier: ^5.3.3 24 | version: 5.3.3 25 | undici-types: 26 | specifier: ^6.4.0 27 | version: 6.4.0 28 | 29 | packages: 30 | 31 | /@types/node@20.11.6: 32 | resolution: {integrity: sha512-+EOokTnksGVgip2PbYbr3xnR7kZigh4LbybAfBAw5BpnQ+FqBYUsvCEjYd70IXKlbohQ64mzEYmMtlWUY8q//Q==} 33 | dependencies: 34 | undici-types: 5.26.5 35 | dev: true 36 | 37 | /asynckit@0.4.0: 38 | resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} 39 | dev: false 40 | 41 | /axios@1.6.6: 42 | resolution: {integrity: sha512-XZLZDFfXKM9U/Y/B4nNynfCRUqNyVZ4sBC/n9GDRCkq9vd2mIvKjKKsbIh1WPmHmNbg6ND7cTBY3Y2+u1G3/2Q==} 43 | dependencies: 44 | follow-redirects: 1.15.5 45 | form-data: 4.0.0 46 | proxy-from-env: 1.1.0 47 | transitivePeerDependencies: 48 | - debug 49 | dev: false 50 | 51 | /colors@1.4.0: 52 | resolution: {integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==} 53 | engines: {node: '>=0.1.90'} 54 | dev: false 55 | 56 | /combined-stream@1.0.8: 57 | resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} 58 | engines: {node: '>= 0.8'} 59 | dependencies: 60 | delayed-stream: 1.0.0 61 | dev: false 62 | 63 | /delayed-stream@1.0.0: 64 | resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} 65 | engines: {node: '>=0.4.0'} 66 | dev: false 67 | 68 | /follow-redirects@1.15.5: 69 | resolution: {integrity: sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==} 70 | engines: {node: '>=4.0'} 71 | peerDependencies: 72 | debug: '*' 73 | peerDependenciesMeta: 74 | debug: 75 | optional: true 76 | dev: false 77 | 78 | /form-data@4.0.0: 79 | resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} 80 | engines: {node: '>= 6'} 81 | dependencies: 82 | asynckit: 0.4.0 83 | combined-stream: 1.0.8 84 | mime-types: 2.1.35 85 | dev: false 86 | 87 | /mime-db@1.52.0: 88 | resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} 89 | engines: {node: '>= 0.6'} 90 | dev: false 91 | 92 | /mime-types@2.1.35: 93 | resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} 94 | engines: {node: '>= 0.6'} 95 | dependencies: 96 | mime-db: 1.52.0 97 | dev: false 98 | 99 | /proxy-from-env@1.1.0: 100 | resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} 101 | dev: false 102 | 103 | /readline@1.3.0: 104 | resolution: {integrity: sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==} 105 | dev: false 106 | 107 | /typescript@5.3.3: 108 | resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} 109 | engines: {node: '>=14.17'} 110 | hasBin: true 111 | dev: true 112 | 113 | /undici-types@5.26.5: 114 | resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} 115 | dev: true 116 | 117 | /undici-types@6.4.0: 118 | resolution: {integrity: sha512-hF4VKFUTypcLYImmZ13xVhjDaFhRlNULLUCOpm2ADKjuoqWpBFL1oXJXe2+hPq7aBv4v/FagI+MEDUNb8H9vHA==} 119 | dev: true 120 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | const apiUrl = "https://api.rnilaweera.lk/api/"; 4 | 5 | interface Result { 6 | success: string; 7 | } 8 | 9 | interface Model { 10 | name: string; 11 | status: string; 12 | } 13 | 14 | interface ModelsResponse { 15 | chatModels: string[]; 16 | imageModels: string[]; 17 | } 18 | 19 | interface TextResult extends Result { 20 | message: string; 21 | } 22 | 23 | interface Image extends Result { 24 | image_url: string; 25 | } 26 | 27 | interface checkNSFW extends Result { 28 | nsfw: boolean; 29 | } 30 | 31 | class RsnChat { 32 | headers: { Authorization: string }; 33 | 34 | /** 35 | * **RsnChat** 36 | * 37 | * Discord: https://api.rnilaweera.lk/discord 38 | * 39 | * Join the Discord server and create an account with `/register` slash command. 40 | * Get your API key using `/generate-key` for free! 41 | * 42 | * @param {string} apikey - RsnChat API Key (required) 43 | */ 44 | constructor(apikey: string) { 45 | if (!apikey) { 46 | throw new Error("Please provide an API key."); 47 | } 48 | 49 | this.headers = { Authorization: `Bearer ${apikey}` }; 50 | } 51 | 52 | /** 53 | * Get available active models list (Chat & Image) 54 | * @returns {Promise} - Returns active chat and image models 55 | * @example 56 | * ```js 57 | * const rsnchat = new RsnChat("your_api_key"); 58 | * rsnchat.getModels().then(models => { 59 | * console.log(models.chatModels); // Active chat models 60 | * console.log(models.imageModels); // Active image models 61 | * }); 62 | * ``` 63 | */ 64 | async getModels(): Promise { 65 | try { 66 | const response = await axios.get(`${apiUrl}models`, { headers: this.headers }); 67 | 68 | const chatModels = response.data.chat_models 69 | .filter((model: Model) => model.status === "active") 70 | .map((model: Model) => model.name); 71 | 72 | const imageModels = response.data.image_models 73 | .filter((model: Model) => model.status === "active") 74 | .map((model: Model) => model.name); 75 | 76 | return { chatModels, imageModels }; 77 | } catch (error: any) { 78 | throw new Error(`Failed to fetch models: ${error.response?.data?.error || error.message}`); 79 | } 80 | } 81 | 82 | /** 83 | * Generate Text Completion 84 | * @param {string} prompt - Required text input 85 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 86 | * @returns {Promise} 87 | */ 88 | async chat(prompt: string, model: string): Promise { 89 | if (!prompt || typeof prompt !== "string") { 90 | throw new Error("Prompt is required and must be a string."); 91 | } 92 | if (!model || typeof model !== "string") { 93 | throw new Error("Model is required and must be a string."); 94 | } 95 | 96 | try { 97 | const response = await axios.post( 98 | `${apiUrl}chat/generate`, 99 | { prompt, model }, 100 | { headers: this.headers } 101 | ); 102 | return response.data as TextResult; 103 | } catch (error: any) { 104 | throw new Error(`Chat Generation Error: ${error.response?.data?.error || error.message}`); 105 | } 106 | } 107 | 108 | /** 109 | * Generate Image Completion 110 | * @param {string} prompt - Required image description 111 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 112 | * @returns {Promise} 113 | */ 114 | async image(prompt: string, model: string): Promise { 115 | if (!prompt || typeof prompt !== "string") { 116 | throw new Error("Prompt is required and must be a string."); 117 | } 118 | if (!model || typeof model !== "string") { 119 | throw new Error("Model is required and must be a string."); 120 | } 121 | 122 | try { 123 | const response = await axios.post( 124 | `${apiUrl}image/generate`, 125 | { prompt, model }, 126 | { headers: this.headers } 127 | ); 128 | return response.data as Image; 129 | } catch (error: any) { 130 | throw new Error(`Image Generation Error: ${error.response?.data?.error || error.message}`); 131 | } 132 | } 133 | 134 | /** 135 | * Check NSFW Image Completion 136 | * @param {string} image_url - Required image url 137 | * @returns {Promise} 138 | */ 139 | async checkNSFW(image_url: string): Promise { 140 | if (!image_url || typeof image_url !== "string") { 141 | throw new Error("image_url is required and must be a string."); 142 | } 143 | 144 | try { 145 | const response = await axios.post( 146 | `${apiUrl}image/check-nsfw`, 147 | { image_url }, 148 | { headers: this.headers } 149 | ); 150 | return response.data as checkNSFW; 151 | } catch (error: any) { 152 | throw new Error(`Check NSFW Error: ${error.response?.data?.error || error.message}`); 153 | } 154 | } 155 | } 156 | 157 | export { RsnChat, Result, Image, TextResult, ModelsResponse, checkNSFW }; -------------------------------------------------------------------------------- /tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./build/cjs", 5 | "module": "commonjs" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./build/esm", 5 | "moduleResolution": "NodeNext", 6 | "module": "NodeNext" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 4 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 5 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 6 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ 7 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 8 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 9 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 10 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 11 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 12 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 13 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 14 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 15 | 16 | /* Modules */ 17 | "module": "NodeNext" /* Specify what module code is generated. */, 18 | // "rootDir": "./", /* Specify the root folder within your source files. */ 19 | // "moduleResolution": "NodeNext" /* Specify how TypeScript looks up a file from a given module specifier. */, 20 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 21 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 22 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 23 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 24 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 25 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 26 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 27 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ 28 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ 29 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ 30 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ 31 | // "resolveJsonModule": true, /* Enable importing .json files. */ 32 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ 33 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 34 | 35 | /* JavaScript Support */ 36 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 37 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 38 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 39 | 40 | /* Emit */ 41 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 42 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 43 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 44 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 45 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 46 | // "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. */ 47 | "outDir": "./build/" /* Specify an output folder for all emitted files. */, 48 | // "removeComments": true, /* Disable emitting comments. */ 49 | // "noEmit": true, /* Disable emitting files from a compilation. */ 50 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 51 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 52 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 53 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 54 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 55 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 56 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 57 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 58 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 59 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 60 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 61 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 62 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 63 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 64 | 65 | /* Interop Constraints */ 66 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 67 | // "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. */ 68 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 69 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, 70 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 71 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 72 | 73 | /* Type Checking */ 74 | "strict": true /* Enable all strict type-checking options. */, 75 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 76 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 77 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 78 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 79 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 80 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 81 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 82 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 83 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 84 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 85 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 86 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 87 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 88 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 89 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 90 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 91 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 92 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 93 | 94 | /* Completeness */ 95 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 96 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /tsconfig.types.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./types", 5 | "declaration": true, 6 | "emitDeclarationOnly": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | interface Result { 2 | success: string; 3 | } 4 | interface ModelsResponse { 5 | chatModels: string[]; 6 | imageModels: string[]; 7 | } 8 | interface TextResult extends Result { 9 | message: string; 10 | } 11 | interface Image extends Result { 12 | image_url: string; 13 | } 14 | interface checkNSFW extends Result { 15 | nsfw: boolean; 16 | } 17 | declare class RsnChat { 18 | headers: { 19 | Authorization: string; 20 | }; 21 | /** 22 | * **RsnChat** 23 | * 24 | * Discord: https://api.rnilaweera.lk/discord 25 | * 26 | * Join the Discord server and create an account with `/register` slash command. 27 | * Get your API key using `/generate-key` for free! 28 | * 29 | * @param {string} apikey - RsnChat API Key (required) 30 | */ 31 | constructor(apikey: string); 32 | /** 33 | * Get available active models list (Chat & Image) 34 | * @returns {Promise} - Returns active chat and image models 35 | * @example 36 | * ```js 37 | * const rsnchat = new RsnChat("your_api_key"); 38 | * rsnchat.getModels().then(models => { 39 | * console.log(models.chatModels); // Active chat models 40 | * console.log(models.imageModels); // Active image models 41 | * }); 42 | * ``` 43 | */ 44 | getModels(): Promise; 45 | /** 46 | * Generate Text Completion 47 | * @param {string} prompt - Required text input 48 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 49 | * @returns {Promise} 50 | */ 51 | chat(prompt: string, model: string): Promise; 52 | /** 53 | * Generate Image Completion 54 | * @param {string} prompt - Required image description 55 | * @param {string} model - AI model name (https://api.rnilaweera.lk/api/models) 56 | * @returns {Promise} 57 | */ 58 | image(prompt: string, model: string): Promise; 59 | /** 60 | * Check NSFW Image Completion 61 | * @param {string} image_url - Required image url 62 | * @returns {Promise} 63 | */ 64 | checkNSFW(image_url: string): Promise; 65 | } 66 | export { RsnChat, Result, Image, TextResult, ModelsResponse, checkNSFW }; 67 | -------------------------------------------------------------------------------- /types/tsconfig.types.tsbuildinfo: -------------------------------------------------------------------------------- 1 | {"root":["../src/index.ts"],"version":"5.7.3"} --------------------------------------------------------------------------------