Merge pull request 'main' (#78) from YasinOnm08/interstellar_ai:main into main

Reviewed-on: https://interstellardevelopment.org/code/code/React-Group/interstellar_ai/pulls/78
This commit is contained in:
Patrick 2024-10-01 15:45:45 +02:00
commit b414fc88e4
3 changed files with 94 additions and 13 deletions

View file

@ -176,7 +176,7 @@ const InputOutputBackend: React.FC = () => {
} }
} }
setInputMessage("") setInputMessage("")
postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: localStorage.getItem('model'), model_type: type, access_token: accessToken, api_key: api_key }) postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", model_type: type, access_token: accessToken, api_key: api_key })
startGetWorker() startGetWorker()
} }
} }
@ -226,6 +226,11 @@ const InputOutputBackend: React.FC = () => {
} }
}; };
const handleStopClick = () => {
endGetWorker()
getNewToken()
}
const handleResendClick = () => { const handleResendClick = () => {
var temporary_message = messages[messages.length - 2]['content'] var temporary_message = messages[messages.length - 2]['content']
const updatedMessages = messages.slice(0, -2) const updatedMessages = messages.slice(0, -2)
@ -272,6 +277,7 @@ const InputOutputBackend: React.FC = () => {
<ConversationFrontend <ConversationFrontend
ref={conversationRef} ref={conversationRef}
messages={messages} messages={messages}
onStopClick={handleStopClick}
onResendClick={handleResendClick} onResendClick={handleResendClick}
onEditClick={handleEditClick} onEditClick={handleEditClick}
onCopyClick={handleCopyClick} onCopyClick={handleCopyClick}

View file

@ -7,6 +7,7 @@ type Message = {
interface ConversationProps { interface ConversationProps {
messages: Message[]; messages: Message[];
onStopClick: () => void;
onResendClick: () => void; onResendClick: () => void;
onEditClick: () => void; onEditClick: () => void;
onCopyClick: () => void; onCopyClick: () => void;
@ -14,10 +15,21 @@ interface ConversationProps {
} }
const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>( const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>(
({ messages, onResendClick, onEditClick, onCopyClick, isClicked }, ref: ForwardedRef<HTMLDivElement>) => { ({ messages,onStopClick, onResendClick, onEditClick, onCopyClick, isClicked }, ref: ForwardedRef<HTMLDivElement>) => {
const messagesEndRef = useRef<HTMLDivElement | null>(null) const messagesEndRef = useRef<HTMLDivElement | null>(null)
useEffect(() => {
if (messagesEndRef.current) {
const rect = messagesEndRef.current.getBoundingClientRect();
console.log('Position of the target div:');
console.log('Top:', rect.top); // Distance from the top of the viewport
console.log('Left:', rect.left); // Distance from the left of the viewport
console.log('Width:', rect.width); // Width of the element
console.log('Height:', rect.height); // Height of the element
}
}, [messages]);
useEffect(() => { useEffect(() => {
messagesEndRef.current?.scrollIntoView() messagesEndRef.current?.scrollIntoView()
}, [messages]) }, [messages])
@ -40,16 +52,30 @@ const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>
})} })}
<div className="button-container"> <div className="button-container">
<button type="button" onClick={onResendClick}> <div className="tooltip">
<img src="/img/resend.svg" alt="resend" /> <button type="button" onClick={onStopClick}>
</button> <img src="/img/resend.svg" alt="stop" />
<button type="button" onClick={onEditClick}> </button>
<img src="/img/edit.svg" alt="edit" /> <span className="tooltiptext">Stop</span>
</button> </div>
<button type="button" onClick={onCopyClick}> <div className="tooltip">
<img src="/img/copy.svg" alt="copy" /> <button type="button" onClick={onResendClick}>
</button> <img src="/img/resend.svg" alt="resend" />
<p id="copiedText" style={{ opacity: isClicked ? "1" : "0", transition: "all 0.3s ease-in-out" }}>Copied!</p> </button>
<span className="tooltiptext">Resend</span>
</div>
<div className="tooltip">
<button type="button" onClick={onEditClick}>
<img src="/img/edit.svg" alt="edit" />
</button>
<span className="tooltiptext">Edit</span>
</div>
<div className="tooltip">
<button type="button" onClick={onCopyClick}>
<img src="/img/copy.svg" alt="copy" />
</button>
<span className="tooltiptext">{isClicked?"Copied!": "Copy" }</span>
</div>
</div> </div>
<div ref={messagesEndRef} /> <div ref={messagesEndRef} />
</div> </div>

View file

@ -20,7 +20,7 @@
flex-direction: column; flex-direction: column;
padding-left: 10px; padding-left: 10px;
overflow-y: auto; overflow-y: auto;
max-height: 80vh; height: 80vh;
background-color: var(--output-background-color); background-color: var(--output-background-color);
border-radius: 10px; border-radius: 10px;
scroll-behavior: smooth; scroll-behavior: smooth;
@ -72,6 +72,55 @@
width: 20px; width: 20px;
} }
.tooltip {
position: relative;
display: inline-block;
margin: 5px;
cursor: pointer;
}
.tooltip .tooltiptext {
visibility: hidden;
background-color: var(--user-message-background-color);
color: var(--text-color);
text-align: center;
padding: 5px;
border-radius: 4px;
font-size: calc(var(--font-size)*0.8);
/* Position the tooltip */
position: absolute;
top: 125%;
/* 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;
}
.tooltip .tooltiptext::after {
content: "";
position: absolute;
bottom: 100%;
/* Arrow on top of tooltip */
left: 50%;
transform: translateX(-50%);
border-width: 5px;
border-style: solid;
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; margin-top: 1em;
cursor:default; cursor:default;