From 124449b4cac9ecf6cbdff0aefb221d6969c2d197 Mon Sep 17 00:00:00 2001 From: hexastack Date: Thu, 3 Oct 2024 15:15:55 +0100 Subject: [PATCH 1/2] feat(chatgpt-rag): remove chatgpt rag plugin --- .../extensions/plugins/chatgpt-rag.plugin.ts | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 api/src/extensions/plugins/chatgpt-rag.plugin.ts diff --git a/api/src/extensions/plugins/chatgpt-rag.plugin.ts b/api/src/extensions/plugins/chatgpt-rag.plugin.ts deleted file mode 100644 index ca2acd4..0000000 --- a/api/src/extensions/plugins/chatgpt-rag.plugin.ts +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright © 2024 Hexastack. All rights reserved. - * - * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: - * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. - * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). - */ - -import { Injectable } from '@nestjs/common'; -import OpenAI from 'openai'; - -import { Block } from '@/chat/schemas/block.schema'; -import { Context } from '@/chat/schemas/types/context'; -import { - OutgoingMessageFormat, - StdOutgoingTextEnvelope, -} from '@/chat/schemas/types/message'; -import { ContentService } from '@/cms/services/content.service'; -import { LoggerService } from '@/logger/logger.service'; -import { BaseBlockPlugin } from '@/plugins/base-block-plugin'; -import { PluginService } from '@/plugins/plugins.service'; -import { SettingType } from '@/setting/schemas/types'; - -@Injectable() -export class ChatGptRagPlugin extends BaseBlockPlugin { - private openai: OpenAI; - - constructor( - pluginService: PluginService, - private logger: LoggerService, - private contentService: ContentService, - ) { - super('chatgpt-rag', pluginService); - - this.settings = [ - { - id: 'token', - label: 'Token', - group: 'default', - type: SettingType.secret, - value: '', - }, - { - id: 'model', - label: 'Model', - group: 'default', - type: SettingType.text, - value: 'gpt-4o-mini', - }, - { - id: 'context', - label: 'Context', - group: 'default', - type: SettingType.textarea, - value: `You are an AI Chatbot that works for Hexastack, This is their description : Whether it concerns IT staff augmentation, web development or software consulting, we believe that each development project is a human adventure above all. - That’s why at Hexastack, soft skills and mindset are as important as technical skills to meet success. - We ensure that everyone in our team is mastering the technologies as well as the soft skills needed to rapidly connect and efficiently cooperate with your team in order to get things done in the smoothest possible way. - `, - }, - { - id: 'instructions', - label: 'Instructions', - group: 'default', - type: SettingType.textarea, - value: `answer the user QUESTION using the DOCUMENTS text above - Keep your answer ground in the facts of the DOCUMENT. - If the DOCUMENT doesn’t contain the facts to answer the QUESTION, apologize and try to give an answer that promotes the company and it's values - DO NOT SAY ANY THING ABOUT THESE DOCUMENTS, or their EXISTANCE`, - }, - ]; - - this.title = 'ChatGPT RAG'; - - this.template = { name: 'ChatGPT RAG Plugin' }; - - this.effects = { - onStoreContextData: () => {}, - }; - } - - async process(block: Block, context: Context, _convId: string) { - const RAG = await this.contentService.textSearch(context.text); - const args = block.message['args']; - const client = this.getInstance(args.token); - const completion = await client.chat.completions.create({ - model: args['model'], - messages: [ - { - role: 'system', - content: `CONTEXT: ${args.context} - DOCUMENTS: \n${RAG.reduce( - (prev, curr, index) => - `${prev}\n\tDOCUMENT ${index} \n\t\tTitle:${curr.title}\n\t\tData:${curr.rag}`, - '', - )}\nINSTRUCTIONS: - ${args.instructions} - `, - }, - { role: 'user', content: 'QUESTION: \n' + context.text }, - ], - temperature: 0.8, - }); - - const envelope: StdOutgoingTextEnvelope = { - format: OutgoingMessageFormat.text, - message: { - text: completion.choices[0].message.content, - }, - }; - return envelope; - } - - private getInstance(token: string) { - if (this.openai) { - return this.openai; - } - - try { - this.openai = new OpenAI({ - apiKey: token, - }); - return this.openai; - } catch (err) { - this.logger.warn('RAG: Unable to instanciate OpenAI', err); - } - } -} From 300eb64d3a1d92aa1ebdf55bb05eeb105d8b5c1b Mon Sep 17 00:00:00 2001 From: hexastack Date: Thu, 3 Oct 2024 15:30:14 +0100 Subject: [PATCH 2/2] feat(chatgpt-rag): remove openai package --- api/package-lock.json | 108 +----------------------------------------- api/package.json | 7 ++- 2 files changed, 4 insertions(+), 111 deletions(-) diff --git a/api/package-lock.json b/api/package-lock.json index 03513ae..fcd0323 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -43,7 +43,6 @@ "nestjs-dynamic-providers": "^0.3.4", "nestjs-i18n": "^10.4.0", "nodemailer": "^6.9.13", - "openai": "^4.54.0", "papaparse": "^5.4.1", "passport": "^0.6.0", "passport-anonymous": "^1.0.1", @@ -6127,6 +6126,7 @@ "version": "2.6.11", "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "dev": true, "dependencies": { "@types/node": "*", "form-data": "^4.0.0" @@ -6682,17 +6682,6 @@ "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==" }, - "node_modules/abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "dependencies": { - "event-target-shim": "^5.0.0" - }, - "engines": { - "node": ">=6.5" - } - }, "node_modules/accept-language-parser": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/accept-language-parser/-/accept-language-parser-1.5.0.tgz", @@ -6761,17 +6750,6 @@ "node": ">= 14" } }, - "node_modules/agentkeepalive": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz", - "integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==", - "dependencies": { - "humanize-ms": "^1.2.1" - }, - "engines": { - "node": ">= 8.0.0" - } - }, "node_modules/ajv": { "version": "8.13.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", @@ -10028,14 +10006,6 @@ "through": "^2.3.8" } }, - "node_modules/event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", - "engines": { - "node": ">=6" - } - }, "node_modules/eventemitter2": { "version": "6.4.9", "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.9.tgz", @@ -10679,23 +10649,6 @@ "node": ">= 6" } }, - "node_modules/form-data-encoder": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz", - "integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==" - }, - "node_modules/formdata-node": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz", - "integrity": "sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==", - "dependencies": { - "node-domexception": "1.0.0", - "web-streams-polyfill": "4.0.0-beta.3" - }, - "engines": { - "node": ">= 12.20" - } - }, "node_modules/formidable": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz", @@ -11376,14 +11329,6 @@ "node": ">=10.17.0" } }, - "node_modules/humanize-ms": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", - "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", - "dependencies": { - "ms": "^2.0.0" - } - }, "node_modules/husky": { "version": "8.0.3", "resolved": "https://registry.npmjs.org/husky/-/husky-8.0.3.tgz", @@ -14480,24 +14425,6 @@ "integrity": "sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==", "dev": true }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "engines": { - "node": ">=10.5.0" - } - }, "node_modules/node-emoji": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz", @@ -14771,31 +14698,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/openai": { - "version": "4.54.0", - "resolved": "https://registry.npmjs.org/openai/-/openai-4.54.0.tgz", - "integrity": "sha512-e/12BdtTtj+tXs7iHm+Dm7H7WjEWnw7O52B2wSfCQ6lD5F6cvjzo7cANXy5TJ1Q3/qc8YRPT5wBTTFtP5sBp1g==", - "dependencies": { - "@types/node": "^18.11.18", - "@types/node-fetch": "^2.6.4", - "abort-controller": "^3.0.0", - "agentkeepalive": "^4.2.1", - "form-data-encoder": "1.7.2", - "formdata-node": "^4.3.2", - "node-fetch": "^2.6.7" - }, - "bin": { - "openai": "bin/cli" - } - }, - "node_modules/openai/node_modules/@types/node": { - "version": "18.19.43", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.43.tgz", - "integrity": "sha512-Mw/YlgXnyJdEwLoFv2dpuJaDFriX+Pc+0qOBJ57jC1H6cDxIj2xc5yUrdtArDVG0m+KV6622a4p2tenEqB3C/g==", - "dependencies": { - "undici-types": "~5.26.4" - } - }, "node_modules/opencollective-postinstall": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", @@ -18740,14 +18642,6 @@ "node": ">=4.0.0" } }, - "node_modules/web-streams-polyfill": { - "version": "4.0.0-beta.3", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.3.tgz", - "integrity": "sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==", - "engines": { - "node": ">= 14" - } - }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/api/package.json b/api/package.json index 9d4aafd..1c8b5a4 100644 --- a/api/package.json +++ b/api/package.json @@ -43,6 +43,7 @@ "@nestjs/passport": "^10.0.2", "@nestjs/platform-express": "^10.0.0", "@nestjs/platform-socket.io": "^10.3.7", + "@nestjs/swagger": "^7.2.0", "@nestjs/websockets": "^10.3.7", "@resvg/resvg-js": "^2.6.2", "@tekuconcept/nestjs-csrf": "^1.1.0", @@ -63,7 +64,6 @@ "nestjs-dynamic-providers": "^0.3.4", "nestjs-i18n": "^10.4.0", "nodemailer": "^6.9.13", - "openai": "^4.54.0", "papaparse": "^5.4.1", "passport": "^0.6.0", "passport-anonymous": "^1.0.1", @@ -74,8 +74,7 @@ "rxjs": "^7.8.1", "slug": "^8.2.2", "ts-migrate-mongoose": "^3.8.3", - "uuid": "^9.0.1", - "@nestjs/swagger": "^7.2.0" + "uuid": "^9.0.1" }, "devDependencies": { "@compodoc/compodoc": "^1.1.24", @@ -158,4 +157,4 @@ "@/(.*)": "/$1" } } -} \ No newline at end of file +}