forked from React-Group/interstellar_ai
		
	main #13
					 22 changed files with 121 additions and 18 deletions
				
			
		|  | @ -1,6 +1,6 @@ | |||
| import React, { useState } from 'react'; | ||||
| import InputFrontend from './InputFrontend'; | ||||
| import ConversationFrontend from './ConversationFrontend'; | ||||
| import InputFrontend from '../components/InputFrontend'; | ||||
| import ConversationFrontend from '../components/ConversationFrontend'; | ||||
| import { Mistral } from '@mistralai/mistralai'; | ||||
| 
 | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| "use client" | ||||
| import React, { useEffect, useRef, useState } from "react"; | ||||
| import ConversationFrontend from "./ConversationFrontend"; | ||||
| import InputFrontend from "./InputFrontend"; | ||||
| import ConversationFrontend from "../components/ConversationFrontend"; | ||||
| import InputFrontend from "../components/InputFrontend"; | ||||
| 
 | ||||
| const handleMicClick = () => { | ||||
|   console.log('Mic clicked!'); | ||||
|  | @ -1,6 +1,6 @@ | |||
| // AI.tsx
 | ||||
| import React from 'react'; | ||||
| import InputOutputBackend from './InputOutputHandler'; | ||||
| import InputOutputBackend from '../backend/InputOutputHandler'; | ||||
| 
 | ||||
| const AI: React.FC = () => { | ||||
|   return ( | ||||
|  | @ -1,4 +1,4 @@ | |||
| import Header from "./Header"; | ||||
| import Header from "./components/Header"; | ||||
| 
 | ||||
| 
 | ||||
| export const metadata = { | ||||
|  |  | |||
							
								
								
									
										12
									
								
								app/page.tsx
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								app/page.tsx
									
										
									
									
									
								
							|  | @ -1,11 +1,11 @@ | |||
| "use client"; | ||||
| import React, { useState, useEffect, useRef } from 'react'; | ||||
| import Header from './Header'; | ||||
| import AI from './AI'; | ||||
| import FAQ from './Faq'; // Ensure the import path is correct
 | ||||
| import Documentation from './Documentation'; // Ensure the import path is correct
 | ||||
| import History from './History'; | ||||
| import Models from './Models'; | ||||
| import Header from './components/Header'; | ||||
| import AI from './components/AI'; | ||||
| import FAQ from './components/Faq'; // Ensure the import path is correct
 | ||||
| import Documentation from './components/Documentation'; // Ensure the import path is correct
 | ||||
| import History from './components/History'; | ||||
| import Models from './components/Models'; | ||||
| import './styles/master.css'; | ||||
| 
 | ||||
| const LandingPage: React.FC = () => { | ||||
|  |  | |||
							
								
								
									
										54
									
								
								py/api.py
									
										
									
									
									
								
							
							
						
						
									
										54
									
								
								py/api.py
									
										
									
									
									
								
							|  | @ -2,19 +2,23 @@ from flask import Flask, request, jsonify | |||
| from flask_cors import CORS | ||||
| import secrets | ||||
| from ai import AI | ||||
| from db import DB | ||||
| from OpenSSL import crypto | ||||
| 
 | ||||
| 
 | ||||
| class API: | ||||
|     def __init__(self): | ||||
|         self.crypt_size = 4096 | ||||
|         self.app = Flask(__name__) | ||||
|         self.ai_response = {} | ||||
|         self.ai = AI() | ||||
|         self.db = DB() | ||||
|         CORS(self.app) | ||||
| 
 | ||||
|     def run(self): | ||||
|         @self.app.route('/interstellar/api/ai_create', methods=['GET']) | ||||
|         def create_ai(): | ||||
|             access_token = secrets.token_urlsafe(4096) | ||||
|             access_token = secrets.token_urlsafe(self.crypt_size) | ||||
|             self.ai_response[access_token] = "" | ||||
|             return jsonify({'status': 200, 'access_token': access_token}) | ||||
| 
 | ||||
|  | @ -36,7 +40,53 @@ class API: | |||
|                 return jsonify({'status': 401, 'error': 'Invalid access token'}) | ||||
|             return jsonify({'status': 200, 'response': self.ai_response[data]}) | ||||
| 
 | ||||
|         ssl_context = ('cert.pem', 'key.pem') | ||||
|         @self.app.route('/interstellar/api/db', methods=['POST']) | ||||
|         def db_manipulate(): | ||||
|             action = request.args.get('action') | ||||
|             data = request.args.get('data') | ||||
|             if action == "create_account": | ||||
|                 self.db.add_user(data) | ||||
|             if action == "change_password": | ||||
|                 self.db.update_password(data) | ||||
|             if action == "get_data": | ||||
|                 self.db.get_additional_info(data) | ||||
|             if action == "check_credentials": | ||||
|                 self.db.check_credentials(data) | ||||
| 
 | ||||
|         email_address = "emailAddress" | ||||
|         common_name = "commonName" | ||||
|         country_name = "NT" | ||||
|         locality_name = "localityName" | ||||
|         state_or_province_name = "stateOrProvinceName" | ||||
|         organization_name = "organizationName" | ||||
|         organization_unit_name = "organizationUnitName" | ||||
|         serial_number = 0 | ||||
|         validity_start_in_seconds = 0 | ||||
|         validity_end_in_seconds = 10 * 365 * 24 * 60 * 60 | ||||
|         k = crypto.PKey() | ||||
|         k.generate_key(crypto.TYPE_RSA, 4096) | ||||
|         cert = crypto.X509() | ||||
|         cert.get_subject().C = country_name | ||||
|         cert.get_subject().ST = state_or_province_name | ||||
|         cert.get_subject().L = locality_name | ||||
|         cert.get_subject().O = organization_name | ||||
|         cert.get_subject().OU = organization_unit_name | ||||
|         cert.get_subject().CN = common_name | ||||
|         cert.get_subject().emailAddress = email_address | ||||
|         cert.set_serial_number(serial_number) | ||||
|         cert.gmtime_adj_notBefore(validity_start_in_seconds) | ||||
|         cert.gmtime_adj_notAfter(validity_end_in_seconds) | ||||
|         cert.set_issuer(cert.get_subject()) | ||||
|         cert.set_pubkey(k) | ||||
|         cert.sign(k, 'sha512') | ||||
| 
 | ||||
|         with open("cert.pem", "wt") as f: | ||||
|             f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8")) | ||||
| 
 | ||||
|         with open("key.pem", "wt") as f: | ||||
|             f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8")) | ||||
| 
 | ||||
|         ssl_context = ("cert.pem", "key.pem") | ||||
|         self.app.run(debug=True, host='0.0.0.0', port=5000, ssl_context=ssl_context) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										51
									
								
								py/db.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								py/db.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,51 @@ | |||
| import json | ||||
| import hashlib | ||||
| 
 | ||||
| 
 | ||||
| class DB: | ||||
|     def __init__(self): | ||||
|         self.database = {} | ||||
| 
 | ||||
|     @staticmethod | ||||
|     def hash_password(password): | ||||
|         salt = "your_secret_salt" | ||||
|         hashed_password = hashlib.sha256((password + salt).encode()).hexdigest() | ||||
|         return hashed_password | ||||
| 
 | ||||
|     def add_user(self, data): | ||||
|         username = data.get['username'] | ||||
|         password = data.get['password'] | ||||
|         hashed_password = self.hash_password(password) | ||||
|         user_data = {"hashed_password": hashed_password} | ||||
|         self.database[username] = user_data | ||||
| 
 | ||||
|     def update_password(self, data): | ||||
|         username = data.get['username'] | ||||
|         old_password = data.get['old_password'] | ||||
|         new_password = data.get['new_password'] | ||||
|         if not self.check_credentials(data): | ||||
|             return False | ||||
| 
 | ||||
|         hashed_new_password = self.hash_password(new_password) | ||||
|         self.database[username].update({"hashed_password": hashed_new_password}) | ||||
|         return True | ||||
| 
 | ||||
|     def check_credentials(self, data): | ||||
|         username = data.get['username'] | ||||
|         password = data.get['password'] | ||||
|         if username not in self.database: | ||||
|             return False | ||||
| 
 | ||||
|         stored_hashed_password = self.database[username]["hashed_password"] | ||||
|         entered_hashed_password = self.hash_password(password) | ||||
|         return stored_hashed_password == entered_hashed_password | ||||
| 
 | ||||
|     def get_additional_info(self, data): | ||||
|         username = data.get['username'] | ||||
|         password = data.get['password'] | ||||
|         if not self.check_credentials(data): | ||||
|             return None | ||||
| 
 | ||||
|         send_back = self.database[username] | ||||
|         del send_back['hashed_password'] | ||||
|         return send_back | ||||
|  | @ -1,4 +1,3 @@ | |||
| openssl req -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365 | ||||
| python -m venv venv | ||||
| source venv/bin/activate | ||||
| pip install -r requirements.txt | ||||
|  |  | |||
|  | @ -2,3 +2,4 @@ flask | |||
| flask-cors | ||||
| ollama | ||||
| mistralai | ||||
| pyOpenSSL | ||||
|  | @ -9,11 +9,13 @@ const config: Config = { | |||
|   theme: { | ||||
|     extend: { | ||||
|       colors: { | ||||
|         background: "var(--background)", | ||||
|         foreground: "var(--foreground)", | ||||
|         'history-background': 'var(--history-background-color)', | ||||
|         'text-color': 'var(--text-color)', | ||||
|         'input-button-hover-color': 'var(--input-button-hover-color)', | ||||
|       }, | ||||
|     }, | ||||
|   }, | ||||
|   plugins: [], | ||||
| }; | ||||
| 
 | ||||
| export default config; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue