Add name property to Message type
This commit is contained in:
38
src/hooks/useDynamicTextareaSize.tsx
Normal file
38
src/hooks/useDynamicTextareaSize.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
// copied from https://gist.github.com/KristofferEriksson/87ea5b8195339577151a236a9e9b46ff
|
||||
/**
|
||||
* Custom hook for dynamically resizing a textarea to fit its content.
|
||||
* @param {React.RefObject<HTMLTextAreaElement>} textareaRef - Reference to the textarea element.
|
||||
* @param {string} textContent - Current text content of the textarea.
|
||||
* @param {number} maxHeight - Optional: maxHeight of the textarea in pixels.
|
||||
*/
|
||||
|
||||
import { useEffect } from "react";
|
||||
const useDynamicTextareaSize = (
|
||||
textareaRef: React.RefObject<HTMLTextAreaElement>,
|
||||
textContent: string,
|
||||
// optional maximum height after which textarea becomes scrollable
|
||||
maxHeight?: number
|
||||
): void => {
|
||||
useEffect(() => {
|
||||
const currentTextarea = textareaRef.current;
|
||||
if (currentTextarea) {
|
||||
// Temporarily collapse the textarea to calculate the required height
|
||||
currentTextarea.style.height = "0px";
|
||||
const contentHeight = currentTextarea.scrollHeight;
|
||||
|
||||
if (maxHeight) {
|
||||
|
||||
// Set max-height and adjust overflow behavior if maxHeight is provided
|
||||
currentTextarea.style.maxHeight = `${maxHeight}px`;
|
||||
currentTextarea.style.overflowY = contentHeight > maxHeight ? "scroll" : "hidden";
|
||||
currentTextarea.style.height = `${Math.min(contentHeight, maxHeight)}px`;
|
||||
} else {
|
||||
|
||||
// Adjust height without max height constraint
|
||||
currentTextarea.style.height = `${contentHeight}px`;
|
||||
}
|
||||
}
|
||||
}, [textareaRef, textContent, maxHeight]);
|
||||
};
|
||||
|
||||
export default useDynamicTextareaSize;
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from "react"
|
||||
import { cleanUrl } from "~libs/clean-url"
|
||||
import { getOllamaURL, isOllamaRunning } from "~services/ollama"
|
||||
import { useStoreMessage, type ChatHistory } from "~store"
|
||||
import { getOllamaURL, systemPromptForNonRag } from "~services/ollama"
|
||||
import { useStoreMessage, type ChatHistory, type Message } from "~store"
|
||||
import { ChatOllama } from "@langchain/community/chat_models/ollama"
|
||||
import { HumanMessage, AIMessage } from "@langchain/core/messages"
|
||||
|
||||
@@ -88,15 +88,17 @@ export const useMessage = () => {
|
||||
baseUrl: cleanUrl(url)
|
||||
})
|
||||
|
||||
let newMessage = [
|
||||
let newMessage: Message[] = [
|
||||
...messages,
|
||||
{
|
||||
isBot: false,
|
||||
name: "You",
|
||||
message,
|
||||
sources: []
|
||||
},
|
||||
{
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: []
|
||||
}
|
||||
@@ -106,8 +108,15 @@ export const useMessage = () => {
|
||||
setMessages(newMessage)
|
||||
|
||||
try {
|
||||
const prompt = await systemPromptForNonRag()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const chunks = await ollama.stream(
|
||||
[
|
||||
|
||||
...generateHistory(history),
|
||||
new HumanMessage({
|
||||
content: [
|
||||
@@ -165,6 +174,7 @@ export const useMessage = () => {
|
||||
...messages,
|
||||
{
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: `Something went wrong. Check out the following logs:
|
||||
\`\`\`
|
||||
${e?.message}
|
||||
|
||||
Reference in New Issue
Block a user