main #38
					 3 changed files with 21 additions and 8 deletions
				
			
		|  | @ -3,7 +3,9 @@ import React, { useEffect, useRef, useState } from "react"; | |||
| import ConversationFrontend from "../components/ConversationFrontend"; | ||||
| import InputFrontend from "../components/InputFrontend"; | ||||
| import axios from "axios"; | ||||
| import { log } from 'console'; | ||||
| 
 | ||||
| 
 | ||||
| let sendable = true | ||||
| 
 | ||||
| const InputOutputBackend: React.FC = () => { | ||||
|   type Message = { | ||||
|  | @ -37,8 +39,10 @@ const InputOutputBackend: React.FC = () => { | |||
|     postWorkerRef.current.onmessage = (event) => { | ||||
|       const status = event.data.status | ||||
|       if (status == 200) { | ||||
|         sendable = true | ||||
|         endGetWorker() | ||||
|       } else if (status == 500) { | ||||
|         sendable = true | ||||
|         if (getWorkerRef.current) { | ||||
|           addMessage("assistant", "There was an Error with the AI response") | ||||
|           getWorkerRef.current.postMessage("terminate") | ||||
|  | @ -86,11 +90,15 @@ const InputOutputBackend: React.FC = () => { | |||
|     if (getWorkerRef.current) { | ||||
|       getWorkerRef.current.postMessage({action:"terminate"}) | ||||
|       getWorkerRef.current.terminate() | ||||
|       getWorkerRef.current = null | ||||
|       console.log(messages); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   const editLastMessage = (newContent: string) => { | ||||
|     if (newContent == "") { | ||||
|       newContent = "Loading..." | ||||
|     } | ||||
|   setMessages((prevMessages) => { | ||||
|     const updatedMessages = prevMessages.slice(); // Create a shallow copy of the current messages
 | ||||
|     if (updatedMessages.length > 0) { | ||||
|  | @ -109,6 +117,9 @@ const InputOutputBackend: React.FC = () => { | |||
|     setMessages(previous => [...previous,{role,content}]) | ||||
|   }   | ||||
|   const handleSendClick = (inputValue: string) => { | ||||
|     if (inputValue != "") { | ||||
|       if (sendable) { | ||||
|         sendable=false | ||||
|         if (postWorkerRef.current) { | ||||
|           addMessage("user", inputValue) | ||||
|           console.log("input:",inputValue); | ||||
|  | @ -116,6 +127,8 @@ const InputOutputBackend: React.FC = () => { | |||
|           startGetWorker() | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   const handleMicClick = () => { | ||||
|     // do stuff
 | ||||
|  |  | |||
|  | @ -29,6 +29,6 @@ const fetchData = () => { | |||
|         .catch(error => { | ||||
|             console.log('Error fetching data:', error); | ||||
|             postMessage({error:"failed fetching data"}) | ||||
|          | ||||
|             setTimeout(() => fetchData(),1000) | ||||
|     }) | ||||
| } | ||||
|  | @ -2,7 +2,7 @@ import axios from "axios"; | |||
| 
 | ||||
| onmessage = (e) => { | ||||
|     const { messages = [{ role: "assistant", content: "Hello! How can I help you?" }], ai_model = "phi3.5", access_token } = e.data | ||||
|     messages.unshift({ role: "system", content: "You are a Helpful assistant" }) | ||||
|     messages.unshift({ role: "system", content: "You are a Helpful assistant. you give short answers" }) | ||||
| 
 | ||||
|     const Message = { | ||||
|         messages: messages, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue