forked from React-Group/interstellar_ai
		
	Merge branch 'main' into main
This commit is contained in:
		
						commit
						9ea352cb4c
					
				
					 3 changed files with 121 additions and 57 deletions
				
			
		|  | @ -3,11 +3,30 @@ import { useChatHistory } from '../hooks/useChatHistory'; | ||||||
| 
 | 
 | ||||||
| const History: React.FC = () => { | const History: React.FC = () => { | ||||||
|   const [chatHistory, setChatHistory, setSelectedIndex] = useChatHistory() |   const [chatHistory, setChatHistory, setSelectedIndex] = useChatHistory() | ||||||
|  |   const [isEditing, setIsEditing] = useState(false); | ||||||
|  |   const [inputValue, setInputValue] = useState<string>(''); | ||||||
|  | 
 | ||||||
|  |   const handleEditButtonClick = () => { | ||||||
|  |     setIsEditing(true); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||||||
|  |     setInputValue(e.target.value); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   const handleSaveButtonClick = () => { | ||||||
|  |     setIsEditing(false); | ||||||
|  |     chatHistory.chats.push({ name: inputValue, messages: [], timestamp: 5 }) | ||||||
|  |     setInputValue("") | ||||||
|  |   }; | ||||||
| 
 | 
 | ||||||
|   const handleHistoryClick = (index: number) => { |   const handleHistoryClick = (index: number) => { | ||||||
|     setSelectedIndex(index) |     setSelectedIndex(index) | ||||||
|  |     console.log("index",index); | ||||||
|  |      | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|   return ( |   return ( | ||||||
|     <div className="history-background"> |     <div className="history-background"> | ||||||
|       <div className="history"> |       <div className="history"> | ||||||
|  | @ -18,6 +37,21 @@ const History: React.FC = () => { | ||||||
|               <a href="#" onClick={() => handleHistoryClick(index)}>{chatHistory.chats[index].name}</a> |               <a href="#" onClick={() => handleHistoryClick(index)}>{chatHistory.chats[index].name}</a> | ||||||
|             </li> |             </li> | ||||||
|           ))} |           ))} | ||||||
|  |           <li> | ||||||
|  |             {isEditing ? ( | ||||||
|  |         <div> | ||||||
|  |           <input | ||||||
|  |             type="text" | ||||||
|  |             value={inputValue} | ||||||
|  |             onChange={handleInputChange} | ||||||
|  |             placeholder="Enter text" | ||||||
|  |           /> | ||||||
|  |           <button onClick={handleSaveButtonClick}>Save</button> | ||||||
|  |         </div> | ||||||
|  |       ) : ( | ||||||
|  |         <button onClick={handleEditButtonClick}>{'New Chat'}</button> | ||||||
|  |       )} | ||||||
|  |           </li> | ||||||
|         </ul> |         </ul> | ||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
|  |  | ||||||
|  | @ -19,7 +19,8 @@ interface GlobalChatHistory { | ||||||
| 
 | 
 | ||||||
| let globalChatHistory: GlobalChatHistory = { | let globalChatHistory: GlobalChatHistory = { | ||||||
|     chats: [ |     chats: [ | ||||||
|         { name: "Chat 1", messages: [], timestamp: 4 } |         { name: "Chat 1", messages: [{role:"system",content:"you are a helpful assistant"},{role:"assistant",content:"how can i help you"}], timestamp: 4 }, | ||||||
|  |         { name: "Chat 2", messages: [{role:"system",content:"you are a helpful assistant"},{role:"assistant",content:"how can i help you"}], timestamp: 4 }, | ||||||
|     ], |     ], | ||||||
|     selectedIndex:0 |     selectedIndex:0 | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										139
									
								
								py/api.py
									
										
									
									
									
								
							
							
						
						
									
										139
									
								
								py/api.py
									
										
									
									
									
								
							|  | @ -26,7 +26,7 @@ class API: | ||||||
|         CORS(self.app) |         CORS(self.app) | ||||||
| 
 | 
 | ||||||
|     def run(self): |     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(): |         def create_ai(): | ||||||
|             access_token = secrets.token_urlsafe(self.crypt_size) |             access_token = secrets.token_urlsafe(self.crypt_size) | ||||||
| 
 | 
 | ||||||
|  | @ -34,112 +34,141 @@ class API: | ||||||
|                 access_token = secrets.token_urlsafe(self.crypt_size) |                 access_token = secrets.token_urlsafe(self.crypt_size) | ||||||
| 
 | 
 | ||||||
|             self.ai_response[access_token] = "" |             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(): |         def send_ai(): | ||||||
|             data = request.get_json() |             data = request.get_json() | ||||||
|             messages = data.get('messages') |             messages = data.get("messages") | ||||||
|             model_type = data.get('model_type') |             model_type = data.get("model_type") | ||||||
|             ai_model = data.get('ai_model') |             ai_model = data.get("ai_model") | ||||||
|             access_token = data.get('access_token') |             access_token = data.get("access_token") | ||||||
|             if access_token not in self.ai_response: |             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": |             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.start() | ||||||
|                 thread.join() |                 thread.join() | ||||||
|                 sleep(0.5) |                 sleep(0.5) | ||||||
|                 return jsonify({'status': 200}) |                 return jsonify({"status": 200}) | ||||||
|             elif model_type == "mistral": |             elif model_type == "mistral": | ||||||
|                 api_key = data.get('api_key') |                 api_key = data.get("api_key") | ||||||
|                 thread = threading.Thread(target=self.ai.process_mistralai, |                 thread = threading.Thread( | ||||||
|                                           args=(ai_model, messages, self, access_token, api_key)) |                     target=self.ai.process_mistralai, | ||||||
|  |                     args=(ai_model, messages, self, access_token, api_key), | ||||||
|  |                 ) | ||||||
|                 thread.start() |                 thread.start() | ||||||
|                 thread.join() |                 thread.join() | ||||||
|                 sleep(0.5) |                 sleep(0.5) | ||||||
|                 return jsonify({'status': 200}) |                 return jsonify({"status": 200}) | ||||||
|             elif model_type == "openai": |             elif model_type == "openai": | ||||||
|                 api_key = data.get('api_key') |                 api_key = data.get("api_key") | ||||||
|                 thread = threading.Thread(target=self.ai.process_openai, |                 thread = threading.Thread( | ||||||
|                                           args=(ai_model, messages, self, access_token, api_key)) |                     target=self.ai.process_openai, | ||||||
|  |                     args=(ai_model, messages, self, access_token, api_key), | ||||||
|  |                 ) | ||||||
|                 thread.start() |                 thread.start() | ||||||
|                 thread.join() |                 thread.join() | ||||||
|                 sleep(0.5) |                 sleep(0.5) | ||||||
|                 return jsonify({'status': 200}) |                 return jsonify({"status": 200}) | ||||||
|             elif model_type == "anthropic": |             elif model_type == "anthropic": | ||||||
|                 api_key = data.get('api_key') |                 api_key = data.get("api_key") | ||||||
|                 thread = threading.Thread(target=self.ai.process_anthropic, |                 thread = threading.Thread( | ||||||
|                                           args=(ai_model, messages, self, access_token, api_key)) |                     target=self.ai.process_anthropic, | ||||||
|  |                     args=(ai_model, messages, self, access_token, api_key), | ||||||
|  |                 ) | ||||||
|                 thread.start() |                 thread.start() | ||||||
|                 thread.join() |                 thread.join() | ||||||
|                 sleep(0.5) |                 sleep(0.5) | ||||||
|                 return jsonify({'status': 200}) |                 return jsonify({"status": 200}) | ||||||
|             elif model_type == "google": |             elif model_type == "google": | ||||||
|                 api_key = data.get('api_key') |                 api_key = data.get("api_key") | ||||||
|                 thread = threading.Thread(target=self.ai.process_google, |                 thread = threading.Thread( | ||||||
|                                           args=(ai_model, messages, self, access_token, api_key)) |                     target=self.ai.process_google, | ||||||
|  |                     args=(ai_model, messages, self, access_token, api_key), | ||||||
|  |                 ) | ||||||
|                 thread.start() |                 thread.start() | ||||||
|                 thread.join() |                 thread.join() | ||||||
|                 sleep(0.5) |                 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(): |         def get_ai(): | ||||||
|             data = request.args.get('access_token') |             data = request.args.get("access_token") | ||||||
|             if data not in self.ai_response: |             if data not in self.ai_response: | ||||||
|                 return jsonify({'status': 401, 'error': 'Invalid access token'}) |                 return jsonify({"status": 401, "error": "Invalid access token"}) | ||||||
|             return jsonify({'status': 200, 'response': self.ai_response[data]}) |             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(): |         def db_manipulate(): | ||||||
|             sent_data = request.get_json() |             sent_data = request.get_json() | ||||||
|             print(sent_data) |             print(sent_data) | ||||||
|             action = sent_data.get('action') |             action = sent_data.get("action") | ||||||
|             if action == "create_account": |             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": |             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": |             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": |             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": |             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": |             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": |             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": |             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": |             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": |             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(): |         def voice_recognition(): | ||||||
|             audio = request.files.get('audio') |             audio = request.files.get("audio") | ||||||
|             text = self.voice.recognition(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(): |         def get_weather(): | ||||||
|             unit_type = request.args.get('unit_type') |             unit_type = request.args.get("unit_type") | ||||||
|             city = request.args.get('city') |             city = request.args.get("city") | ||||||
|             return jsonify({'status': 200, 'response': self.weather.getweather(unit_type, 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(): |         def tts(): | ||||||
|             text = request.args.get('text') |             text = request.args.get("text") | ||||||
|             return jsonify({'status': 200, 'response': self.tts.gen_tts(text)}) |             return jsonify({"status": 200, "response": self.tts.gen_tts(text)}) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| api = API() | api = API() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue