What programming language is this: <code fileName="ChatInterface.js"…
- User
User: What programming language is this: // src/components/ChatInterface.js import React, { useState, useContext, useRef, useEffect } from "react"; import { ChatContext } from "../context/ChatContext"; import Message from "./Message"; import CodeModal from "./CodeModal"; import InlineCodeEditor from "./InlineCodeEditor"; import { escapeHtml } from "../utils/escapeHtml";
function ChatInterface() { const { chats, currentChatId, addMessage, updateChat, selectedModelId, models, } = useContext(ChatContext); const currentChat = chats.find((chat) => chat.id === currentChatId); const [message, setMessage] = useState(""); const [isTyping, setIsTyping] = useState(false); const messagesEndRef = useRef(null); const [isCodeModalOpen, setIsCodeModalOpen] = useState(false); const [currentEditingCode, setCurrentEditingCode] = useState(null); const [isSystemPromptOpen, setIsSystemPromptOpen] = useState(false); const [codeAttachments, setCodeAttachments] = useState([]);
const addCodeAttachment = ({ codeContent, fileName, notes }) => { const escapedCode = escapeHtml(codeContent); const escapedFileName = escapeHtml(fileName || "untitled"); const escapedNotes = escapeHtml(notes || ""); const codeTag =
<code fileName="${escapedFileName}" notes="${escapedNotes}">${escapedCode}</code>; setMessage((prev) => prev + codeTag); };const handleAttachCode = (codeSegment) => { setCurrentEditingCode(codeSegment); setIsCodeModalOpen(true); };
const handleCodeSave = (updatedCode) => { if (currentEditingCode) { // Update existing code const escapedCode = escapeHtml(updatedCode.codeContent); const escapedFileName = escapeHtml(updatedCode.fileName || "untitled"); const escapedNotes = escapeHtml(updatedCode.notes || "");
// Improved regex to handle multi-line and special characters const regex = new RegExp( `<code\\s+fileName="${currentEditingCode.fileName}"\\s+notes="${currentEditingCode.notes}">([\\s\\S]*?)<\\/code>` ); const updatedMessage = message.replace( regex, `<code fileName="${escapedFileName}" notes="${escapedNotes}">${escapedCode}</code>` ); setMessage(updatedMessage); } else { // Add new code addCodeAttachment(updatedCode); } setIsCodeModalOpen(false); setCurrentEditingCode(null);};
const handleSend = async () => { if (!message.trim() || !currentChatId || !selectedModelId) return;
// Retrieve the system prompt from the current chat const systemPrompt = currentChat.systemPrompt || ""; // Combine the system prompt with the user message // Ensure there's a separator (like a newline) for clarity const fullMessage = systemPrompt ? `${systemPrompt}\n${message}` : message; const userMessage = { sender: "user", text: message }; addMessage(currentChatId, userMessage); setMessage(""); scrollToBottom(); // Set typing indicator setIsTyping(true); try { const response = await fetch("http://localhost:8000/api/chat", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: fullMessage, model_id: selectedModelId, // Ensure this is correctly set }), }); if (!response.ok) { const errorData = await response.json(); throw new Error( errorData.detail || "Failed to get response from the server." ); } const data = await response.json(); const responseText = data.response; const responseModelId = data.model_id; // Extract model_id from response const botMessage = { sender: "bot", text: responseText, model_id: responseModelId, // Include model_id }; addMessage(currentChatId, botMessage); scrollToBottom(); } catch (error) { console.error("Error:", error); const errorMessage = { sender: "bot", text: "Sorry, something went wrong. Please try again.", }; addMessage(currentChatId, errorMessage); scrollToBottom(); } finally { // Remove typing indicator setIsTyping(false); } - Assistant