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