diff --git a/app/components/ConversationFrontend.tsx b/app/components/ConversationFrontend.tsx index cd6083f..34ffbc7 100644 --- a/app/components/ConversationFrontend.tsx +++ b/app/components/ConversationFrontend.tsx @@ -1,13 +1,13 @@ import React, { ForwardedRef, useState, useEffect, useRef } from 'react'; -import Markdown from 'react-markdown' +import Markdown from 'react-markdown'; import rehypeRaw from 'rehype-raw'; import remarkGfm from 'remark-gfm'; import { useChatHistory } from '../hooks/useChatHistory'; type Message = { - role: string - content: string -} + role: string; + content: string; +}; interface ConversationProps { messages: Message[]; @@ -15,7 +15,7 @@ interface ConversationProps { onResendClick: () => void; onEditClick: () => void; onCopyClick: () => void; - isClicked: boolean + isClicked: boolean; } const ConversationFrontend = React.forwardRef( @@ -28,16 +28,14 @@ const ConversationFrontend = React.forwardRef const observer = new IntersectionObserver( (entries) => { if (entries[0].isIntersecting) { - console.log('End of messages reached'); setIsScrolling(true); } else { - console.log('End of messages not reached'); setIsScrolling(false); } }, { root: document.querySelector('.output'), - threshold: 1.0, // Ensure the whole element is visible + threshold: 1.0, } ); @@ -53,7 +51,6 @@ const ConversationFrontend = React.forwardRef }; }, [messages]); - // Scroll to bottom when new messages arrive useEffect(() => { if (isScrolling) { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); @@ -65,7 +62,6 @@ const ConversationFrontend = React.forwardRef
{chatHistory.chats[chatHistory.selectedIndex].messages.map((message, index) => { if (index >= 1) { - return (
); } + return null; // Ensure to return null for the first message or if condition is not met })} - +
+ ); } ); diff --git a/app/styles/header.css b/app/styles/header.css index ff5baf3..29431c5 100644 --- a/app/styles/header.css +++ b/app/styles/header.css @@ -125,4 +125,5 @@ header { position: absolute; left: 10vw; cursor: pointer; + padding: 10px; } \ No newline at end of file diff --git a/app/styles/output.css b/app/styles/output.css index 320b68b..7cc0166 100644 --- a/app/styles/output.css +++ b/app/styles/output.css @@ -35,6 +35,7 @@ margin: 5px 0; max-width: 75%; word-wrap: break-word; + overflow-wrap: break-word; } .user-message { @@ -49,42 +50,56 @@ color: var(--ai-message-text-color); } -.ai-message a{ +.ai-message a { color: var(--text-color); } -.ai-message table{ +.ai-message table { + display: block; /* Treat the table as a block element */ + position: relative; + overflow-x: auto; /* Allow horizontal scrolling */ + white-space: nowrap; /* Prevent table content from wrapping */ border: 1px solid var(--ai-message-text-color); border-collapse: collapse; background-color: var(--conversation-background-color); + max-width: 100%; /* Ensure the table doesn't exceed the container width */ + padding: 10px; /* Optional: Add padding similar to pre/code */ + border-radius: 4px; /* Optional: Add border radius similar to pre/code */ + margin-top: 5px; } -.ai-message th{ + +.ai-message th { background-color: var(--user-message-background-color); align-items: center; padding: 5px; } -.ai-message td{ +.ai-message td { align-items: center; padding: 5px; } -.ai-message img{ +.ai-message img { max-width: 80%; } -.ai-message a:hover{ +.ai-message a:hover { filter: brightness(70%); } -.ai-message li{ +.ai-message li { margin-left: 1em; } -.ai-message code{ - width: 100%; - overflow: scroll; +.ai-message code, .ai-message pre { + overflow-x: auto; + white-space: pre; + display: block; + max-width: 100%; + padding: 10px; + background-color: var(--code-background-color); + border-radius: 4px; } /* Button Container */ @@ -121,19 +136,14 @@ text-align: center; padding: 5px; border-radius: 4px; - font-size: calc(var(--font-size)*0.8); + font-size: calc(var(--font-size) * 0.8); - /* Position the tooltip */ position: absolute; top: 100%; - /* Adjusts tooltip to be below the button */ left: 50%; transform: translateX(-50%); - /* Center the tooltip */ white-space: nowrap; - /* Prevent line breaks */ - /* Add smooth transition */ opacity: 0; transition: all 0.3s; } @@ -142,7 +152,6 @@ content: ""; position: absolute; bottom: 100%; - /* Arrow on top of tooltip */ left: 50%; transform: translateX(-50%); border-width: 5px; @@ -150,20 +159,19 @@ border-color: transparent transparent var(--user-message-background-color) transparent; } -/* Show the tooltip on hover */ .tooltip:hover .tooltiptext { visibility: visible; opacity: 1; } -#copiedText{ +#copiedText { margin-top: 1em; - cursor:default; + cursor: default; pointer-events: none; user-select: none; } -#scrollToBottom{ +#scrollToBottom { scroll-behavior: smooth; visibility: hidden; position: absolute; @@ -174,4 +182,4 @@ bottom: 16dvh; left: 50%; translate: -25px; -} +} \ No newline at end of file diff --git a/deployment_scripts/windows/NOTE.txt b/deployment_scripts/windows/NOTE.txt index efcc53d..b2df255 100644 --- a/deployment_scripts/windows/NOTE.txt +++ b/deployment_scripts/windows/NOTE.txt @@ -1,7 +1,7 @@ You will need to make three folders: node-bin - contains nodejs portable -python-bin - contains python3 portable - don't forget to add the .pth file and adjust it accordingly, because import site is normally missing. +python-bin - contains python3 portable - don't forget to add the .pth file and adjust it accordingly, because import site is normally missing. -- also put your python files in here too, else it will not run! ollama.bin - contains ollama portable you also need vc redist 2019 \ No newline at end of file diff --git a/deployment_scripts/windows/python313._pth b/deployment_scripts/windows/python312._pth similarity index 75% rename from deployment_scripts/windows/python313._pth rename to deployment_scripts/windows/python312._pth index 4b5ab01..7875b3d 100644 --- a/deployment_scripts/windows/python313._pth +++ b/deployment_scripts/windows/python312._pth @@ -1,4 +1,4 @@ -python313.zip +python312.zip . # Uncomment to run site.main() automatically diff --git a/package-lock.json b/package-lock.json index 4bd730b..96f5817 100644 --- a/package-lock.json +++ b/package-lock.json @@ -685,9 +685,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "20.16.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.10.tgz", - "integrity": "sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==", + "version": "20.16.11", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.11.tgz", + "integrity": "sha512-y+cTCACu92FyA5fgQSAI8A1H429g7aSK2HsO7K4XYUWc4dY5IUz55JSDIYT6/VsOLfGy8vmvQYC2hfb0iF16Uw==", "license": "MIT", "dependencies": { "undici-types": "~6.19.2" @@ -700,9 +700,9 @@ "license": "MIT" }, "node_modules/@types/react": { - "version": "18.3.10", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.10.tgz", - "integrity": "sha512-02sAAlBnP39JgXwkAq3PeU9DVaaGpZyF3MGcC0MKgQVkZor5IiiDAipVaxQHtDJAmO4GIy/rVBy/LzVj76Cyqg==", + "version": "18.3.11", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.11.tgz", + "integrity": "sha512-r6QZ069rFTjrEYgFdOck1gK7FLVsgJE7tTz0pQBczlBNUhBNk0MQH4UbnFSwjpQLMkLzgqvBBa+qGpLje16eTQ==", "license": "MIT", "dependencies": { "@types/prop-types": "*", @@ -745,17 +745,17 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.0.tgz", - "integrity": "sha512-wORFWjU30B2WJ/aXBfOm1LX9v9nyt9D3jsSOxC3cCaTQGCW5k4jNpmjFv3U7p/7s4yvdjHzwtv2Sd2dOyhjS0A==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.1.tgz", + "integrity": "sha512-xfvdgA8AP/vxHgtgU310+WBnLB4uJQ9XdyP17RebG26rLtDrQJV3ZYrcopX91GrHmMoH8bdSwMRh2a//TiJ1jQ==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.8.0", - "@typescript-eslint/type-utils": "8.8.0", - "@typescript-eslint/utils": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0", + "@typescript-eslint/scope-manager": "8.8.1", + "@typescript-eslint/type-utils": "8.8.1", + "@typescript-eslint/utils": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -779,16 +779,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.8.0.tgz", - "integrity": "sha512-uEFUsgR+tl8GmzmLjRqz+VrDv4eoaMqMXW7ruXfgThaAShO9JTciKpEsB+TvnfFfbg5IpujgMXVV36gOJRLtZg==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.8.1.tgz", + "integrity": "sha512-hQUVn2Lij2NAxVFEdvIGxT9gP1tq2yM83m+by3whWFsWC+1y8pxxxHUFE1UqDu2VsGi2i6RLcv4QvouM84U+ow==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/scope-manager": "8.8.0", - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/typescript-estree": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0", + "@typescript-eslint/scope-manager": "8.8.1", + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/typescript-estree": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1", "debug": "^4.3.4" }, "engines": { @@ -808,14 +808,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.8.0.tgz", - "integrity": "sha512-EL8eaGC6gx3jDd8GwEFEV091210U97J0jeEHrAYvIYosmEGet4wJ+g0SYmLu+oRiAwbSA5AVrt6DxLHfdd+bUg==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.8.1.tgz", + "integrity": "sha512-X4JdU+66Mazev/J0gfXlcC/dV6JI37h+93W9BRYXrSn0hrE64IoWgVkO9MSJgEzoWkxONgaQpICWg8vAN74wlA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0" + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -826,14 +826,14 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.8.0.tgz", - "integrity": "sha512-IKwJSS7bCqyCeG4NVGxnOP6lLT9Okc3Zj8hLO96bpMkJab+10HIfJbMouLrlpyOr3yrQ1cA413YPFiGd1mW9/Q==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.8.1.tgz", + "integrity": "sha512-qSVnpcbLP8CALORf0za+vjLYj1Wp8HSoiI8zYU5tHxRVj30702Z1Yw4cLwfNKhTPWp5+P+k1pjmD5Zd1nhxiZA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "8.8.0", - "@typescript-eslint/utils": "8.8.0", + "@typescript-eslint/typescript-estree": "8.8.1", + "@typescript-eslint/utils": "8.8.1", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -851,9 +851,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.8.0.tgz", - "integrity": "sha512-QJwc50hRCgBd/k12sTykOJbESe1RrzmX6COk8Y525C9l7oweZ+1lw9JiU56im7Amm8swlz00DRIlxMYLizr2Vw==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.8.1.tgz", + "integrity": "sha512-WCcTP4SDXzMd23N27u66zTKMuEevH4uzU8C9jf0RO4E04yVHgQgW+r+TeVTNnO1KIfrL8ebgVVYYMMO3+jC55Q==", "dev": true, "license": "MIT", "engines": { @@ -865,14 +865,14 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.0.tgz", - "integrity": "sha512-ZaMJwc/0ckLz5DaAZ+pNLmHv8AMVGtfWxZe/x2JVEkD5LnmhWiQMMcYT7IY7gkdJuzJ9P14fRy28lUrlDSWYdw==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.1.tgz", + "integrity": "sha512-A5d1R9p+X+1js4JogdNilDuuq+EHZdsH9MjTVxXOdVFfTJXunKJR/v+fNNyO4TnoOn5HqobzfRlc70NC6HTcdg==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0", + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -933,16 +933,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.8.0.tgz", - "integrity": "sha512-QE2MgfOTem00qrlPgyByaCHay9yb1+9BjnMFnSFkUKQfu7adBXDTnCAivURnuPPAG/qiB+kzKkZKmKfaMT0zVg==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.8.1.tgz", + "integrity": "sha512-/QkNJDbV0bdL7H7d0/y0qBbV2HTtf0TIyjSDTvvmQEzeVx8jEImEbLuOA4EsvE8gIgqMitns0ifb5uQhMj8d9w==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.8.0", - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/typescript-estree": "8.8.0" + "@typescript-eslint/scope-manager": "8.8.1", + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/typescript-estree": "8.8.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -956,13 +956,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.0.tgz", - "integrity": "sha512-8mq51Lx6Hpmd7HnA2fcHQo3YgfX1qbccxQOgZcb4tvasu//zXRaA1j5ZRFeCw/VRAdFi4mRM9DnZw0Nu0Q2d1g==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.1.tgz", + "integrity": "sha512-0/TdC3aeRAsW7MDvYRwEc1Uwm0TIBfzjPFgg60UU2Haj5qsCs9cc3zNgY71edqE3LbWfF/WoZQd3lJoDXFQpag==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/types": "8.8.1", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1457,9 +1457,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001664", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001664.tgz", - "integrity": "sha512-AmE7k4dXiNKQipgn7a2xg558IRqPN3jMQY/rOsbxDhrd0tyChwbITBfiwtnqz8bi2M5mIWbxAYBvk7W7QBUS2g==", + "version": "1.0.30001667", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001667.tgz", + "integrity": "sha512-7LTwJjcRkzKFmtqGsibMeuXmvFDfZq/nzIjnmgCGzKKRVzjD72selLDK1oPF/Oxzmt4fNcPvTDvGqSDG4tCALw==", "funding": [ { "type": "opencollective", @@ -2256,6 +2256,7 @@ "version": "8.57.1", "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.1.tgz", "integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==", + "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", "dependencies": { @@ -2423,9 +2424,9 @@ } }, "node_modules/eslint-plugin-import": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.30.0.tgz", - "integrity": "sha512-/mHNE9jINJfiD2EKkg1BKyPyUk4zdnT54YgbOgfjSakWT5oyX/qQLVNTkehyfpcMxZXMy1zyonZ2v7hZTX43Yw==", + "version": "2.31.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.31.0.tgz", + "integrity": "sha512-ixmkI62Rbc2/w8Vfxyh1jQRTdRTF52VxwRVHl/ykPAmqG+Nb7/kNn+byLP0LxPgI7zWA16Jt82SybJInmMia3A==", "dev": true, "license": "MIT", "dependencies": { @@ -2437,7 +2438,7 @@ "debug": "^3.2.7", "doctrine": "^2.1.0", "eslint-import-resolver-node": "^0.3.9", - "eslint-module-utils": "^2.9.0", + "eslint-module-utils": "^2.12.0", "hasown": "^2.0.2", "is-core-module": "^2.15.1", "is-glob": "^4.0.3", @@ -2446,13 +2447,14 @@ "object.groupby": "^1.0.3", "object.values": "^1.2.0", "semver": "^6.3.1", + "string.prototype.trimend": "^1.0.8", "tsconfig-paths": "^3.15.0" }, "engines": { "node": ">=4" }, "peerDependencies": { - "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" + "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 || ^9" } }, "node_modules/eslint-plugin-import/node_modules/debug": { @@ -4136,9 +4138,9 @@ "license": "ISC" }, "node_modules/iterator.prototype": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.2.tgz", - "integrity": "sha512-DR33HMMr8EzwuRL8Y9D3u2BMj8+RqSE850jfGu59kS7tbmPLzGkZmVSfyCFSDxuZiEY6Rzt3T2NA/qU+NwVj1w==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.3.tgz", + "integrity": "sha512-FW5iMbeQ6rBGm/oKgzq2aW4KvAGpxPzYES8N4g4xNXUKpL1mclMvOe+76AcLDTvD+Ze+sOpVhgdAQEKF4L9iGQ==", "dev": true, "license": "MIT", "dependencies": { @@ -4147,6 +4149,9 @@ "has-symbols": "^1.0.3", "reflect.getprototypeof": "^1.0.4", "set-function-name": "^2.0.1" + }, + "engines": { + "node": ">= 0.4" } }, "node_modules/jackspeak": { @@ -6294,16 +6299,16 @@ } }, "node_modules/regexp.prototype.flags": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", - "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz", + "integrity": "sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ==", "dev": true, "license": "MIT", "dependencies": { - "call-bind": "^1.0.6", + "call-bind": "^1.0.7", "define-properties": "^1.2.1", "es-errors": "^1.3.0", - "set-function-name": "^2.0.1" + "set-function-name": "^2.0.2" }, "engines": { "node": ">= 0.4" diff --git a/py/api.py b/py/api.py index b9414ae..00709ad 100644 --- a/py/api.py +++ b/py/api.py @@ -9,11 +9,11 @@ from db import DB from weather import Weather from voice import VoiceRecognition from tts import TTS - + class API: def __init__(self): - self.crypt_size = 4096 + self.crypt_size = 64 self.app = Flask(__name__) self.ai_response = {} self.ai = AI() @@ -26,7 +26,7 @@ class API: CORS(self.app) def run(self): - @self.app.route('/interstellar_ai/api/ai_create', methods=['GET']) + @self.app.route("/interstellar_ai/api/ai_create", methods=["GET"]) def create_ai(): access_token = secrets.token_urlsafe(self.crypt_size) @@ -34,112 +34,141 @@ class API: access_token = secrets.token_urlsafe(self.crypt_size) self.ai_response[access_token] = "" - return jsonify({'status': 200, 'access_token': access_token}) + return jsonify({"status": 200, "access_token": access_token}) - @self.app.route('/interstellar_ai/api/ai_send', methods=['POST']) + @self.app.route("/interstellar_ai/api/ai_send", methods=["POST"]) def send_ai(): data = request.get_json() - messages = data.get('messages') - model_type = data.get('model_type') - ai_model = data.get('ai_model') - access_token = data.get('access_token') + messages = data.get("messages") + model_type = data.get("model_type") + ai_model = data.get("ai_model") + access_token = data.get("access_token") if access_token not in self.ai_response: - return jsonify({'status': 401, 'error': 'Invalid access token'}) + return jsonify({"status": 401, "error": "Invalid access token"}) if model_type == "local": - thread = threading.Thread(target=self.ai.process_local, args=(ai_model, messages, self, access_token)) + thread = threading.Thread( + target=self.ai.process_local, + args=(ai_model, messages, self, access_token), + ) thread.start() thread.join() sleep(0.5) - return jsonify({'status': 200}) + return jsonify({"status": 200}) elif model_type == "mistral": - api_key = data.get('api_key') - thread = threading.Thread(target=self.ai.process_mistralai, - args=(ai_model, messages, self, access_token, api_key)) + api_key = data.get("api_key") + thread = threading.Thread( + target=self.ai.process_mistralai, + args=(ai_model, messages, self, access_token, api_key), + ) thread.start() thread.join() sleep(0.5) - return jsonify({'status': 200}) + return jsonify({"status": 200}) elif model_type == "openai": - api_key = data.get('api_key') - thread = threading.Thread(target=self.ai.process_openai, - args=(ai_model, messages, self, access_token, api_key)) + api_key = data.get("api_key") + thread = threading.Thread( + target=self.ai.process_openai, + args=(ai_model, messages, self, access_token, api_key), + ) thread.start() thread.join() sleep(0.5) - return jsonify({'status': 200}) + return jsonify({"status": 200}) elif model_type == "anthropic": - api_key = data.get('api_key') - thread = threading.Thread(target=self.ai.process_anthropic, - args=(ai_model, messages, self, access_token, api_key)) + api_key = data.get("api_key") + thread = threading.Thread( + target=self.ai.process_anthropic, + args=(ai_model, messages, self, access_token, api_key), + ) thread.start() thread.join() sleep(0.5) - return jsonify({'status': 200}) + return jsonify({"status": 200}) elif model_type == "google": - api_key = data.get('api_key') - thread = threading.Thread(target=self.ai.process_google, - args=(ai_model, messages, self, access_token, api_key)) + api_key = data.get("api_key") + thread = threading.Thread( + target=self.ai.process_google, + args=(ai_model, messages, self, access_token, api_key), + ) thread.start() thread.join() sleep(0.5) - return jsonify({'status': 200}) + return jsonify({"status": 200}) - return jsonify({'status': 401, 'error': 'Invalid AI model type'}) + return jsonify({"status": 401, "error": "Invalid AI model type"}) - @self.app.route('/interstellar_ai/api/ai_get', methods=['GET']) + @self.app.route("/interstellar_ai/api/ai_get", methods=["GET"]) def get_ai(): - data = request.args.get('access_token') + data = request.args.get("access_token") if data not in self.ai_response: - return jsonify({'status': 401, 'error': 'Invalid access token'}) - return jsonify({'status': 200, 'response': self.ai_response[data]}) + return jsonify({"status": 401, "error": "Invalid access token"}) + return jsonify({"status": 200, "response": self.ai_response[data]}) - @self.app.route('/interstellar_ai/db', methods=['POST']) + @self.app.route("/interstellar_ai/db", methods=["POST"]) def db_manipulate(): sent_data = request.get_json() print(sent_data) - action = sent_data.get('action') + action = sent_data.get("action") if action == "create_account": - return jsonify({'status': 200, 'response': self.db.add_user(sent_data)}) + return jsonify({"status": 200, "response": self.db.add_user(sent_data)}) elif action == "change_password": - return jsonify({'status': 200, 'response': self.db.update_password(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.update_password(sent_data)} + ) elif action == "get_settings": - return jsonify({'status': 200, 'response': self.db.get_settings(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.get_settings(sent_data)} + ) elif action == "change_settings": - return jsonify({'status': 200, 'response': self.db.change_settings(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.change_settings(sent_data)} + ) elif action == "get_history": - return jsonify({'status': 200, 'response': self.db.get_history(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.get_history(sent_data)} + ) elif action == "change_history": - return jsonify({'status': 200, 'response': self.db.change_history(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.change_history(sent_data)} + ) elif action == "check_credentials": - return jsonify({'status': 200, 'response': self.db.check_credentials(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.check_credentials(sent_data)} + ) elif action == "delete_account": - return jsonify({'status': 200, 'response': self.db.delete_user(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.delete_user(sent_data)} + ) elif action == "get_email": - return jsonify({'status': 200, 'response': self.db.get_email(sent_data)}) + return jsonify( + {"status": 200, "response": self.db.get_email(sent_data)} + ) elif action == "get_name": - return jsonify({'status': 200, 'response': self.db.get_name(sent_data)}) + return jsonify({"status": 200, "response": self.db.get_name(sent_data)}) - return jsonify({'status': 401, 'response': "Invalid action"}) + return jsonify({"status": 401, "response": "Invalid action"}) - @self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST']) + @self.app.route("/interstellar_ai/api/voice_recognition", methods=["POST"]) def voice_recognition(): - audio = request.files.get('audio') + audio = request.files.get("audio") text = self.voice.recognition(audio) - return jsonify({'status': 200, 'response': text}) + return jsonify({"status": 200, "response": text}) - @self.app.route('/interstellar_ai/api/weather', methods=['POST']) + @self.app.route("/interstellar_ai/api/weather", methods=["POST"]) def get_weather(): - unit_type = request.args.get('unit_type') - city = request.args.get('city') - return jsonify({'status': 200, 'response': self.weather.getweather(unit_type, city)}) + unit_type = request.args.get("unit_type") + city = request.args.get("city") + return jsonify( + {"status": 200, "response": self.weather.getweather(unit_type, city)} + ) - self.app.run(debug=True, host='0.0.0.0', port=5000) + self.app.run(debug=True, host="0.0.0.0", port=5000) - @self.app.route('/interstellar_ai/api/tts', methods=['POST']) + @self.app.route("/interstellar_ai/api/tts", methods=["POST"]) def tts(): - text = request.args.get('text') - return jsonify({'status': 200, 'response': self.tts.gen_tts(text)}) + text = request.args.get("text") + return jsonify({"status": 200, "response": self.tts.gen_tts(text)}) api = API()