Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Chat Log Viewer for 0.3.x</title>
- <style>
- body {
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- margin: 0;
- padding: 20px;
- background-color: #0a0a0a; /* Darker background */
- color: #e0e0e0; /* Lighter text color */
- }
- h3 {
- color: #ffffff; /* Header color */
- text-align: center; /* Centered header */
- }
- .container {
- width: 60%; /* Default container width */
- margin: auto; /* Center the container */
- transition: width 0.3s; /* Smooth transition for width change */
- }
- .header-container {
- display: flex;
- justify-content: space-between; /* Space between items */
- align-items: center;
- margin-bottom: 20px;
- padding: 10px;
- background-color: #1c1c1c; /* Header background */
- border-radius: 8px;
- }
- .dropdown-container {
- display: flex;
- align-items: center; /* Align elements */
- gap: 15px; /* Space between elements */
- }
- .dropdown-left {
- margin-right: auto; /* Pushes this dropdown to the left */
- }
- #chat {
- background-color: #1b1b26;
- border: 1px solid #444;
- border-radius: 8px;
- padding: 20px;
- max-height: 1000px;
- overflow-y: auto;
- margin-top: 20px;
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
- }
- .message {
- margin: 15px 0;
- padding: 15px;
- border-radius: 10px;
- color: #ECECEC;
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
- }
- .user {
- background-color: #1E1D1F; /* User message background */
- }
- .assistant {
- background-color: #152031; /* Assistant message background */
- }
- .message-content {
- margin-left: 10px;
- }
- #model-name, #system-prompt, #file-name {
- color: #bbb;
- margin-top: 10px;
- background-color: #1b1b26;
- padding: 10px;
- border-radius: 5px;
- text-align: center; /* Center text */
- }
- select {
- padding: 5px;
- border-radius: 5px;
- background-color: #333; /* Dropdown background */
- color: #fff; /* Dropdown text color */
- border: 1px solid #444; /* Dropdown border color */
- }
- input[type="text"] {
- padding: 5px;
- border-radius: 5px;
- border: 1px solid #444; /* Input border color */
- background-color: #333; /* Input background */
- color: #fff; /* Input text color */
- display: none; /* Hidden by default */
- }
- </style>
- </head>
- <body>
- <div class="container" id="container">
- <h3>Chat Log Viewer</h3>
- <div class="header-container">
- <div class="dropdown-container">
- <label for="width-select">Width:</label>
- <select id="width-select">
- <option value="30">30%</option>
- <option value="40">40%</option>
- <option value="50">50%</option>
- <option value="60" selected>60%</option>
- <option value="70">70%</option>
- <option value="80">80%</option>
- <option value="90">90%</option>
- <option value="100">100%</option>
- </select>
- </div>
- <div class="dropdown-container">
- <label for="user-select">User:</label>
- <select id="user-select" onchange="toggleUserInput()">
- <option value="YourName" selected>YourName</option>
- <option value="Human">Human</option>
- <option value="User">User</option>
- <option value="Other">Other</option>
- </select>
- <input type="text" id="user-input" placeholder="Enter custom name" oninput="updateUserName()" />
- <label for="assistant-select">Assistant:</label>
- <select id="assistant-select" onchange="toggleAssistantInput()">
- <option value="Assistant">Assistant</option>
- <option value="Robot" selected>Robot</option>
- <option value="Teacher">Teacher</option>
- <option value="Other">Other</option>
- </select>
- <input type="text" id="assistant-input" placeholder="Enter custom name" oninput="updateAssistantName()" />
- </div>
- <input type="file" id="file-input" accept=".json" />
- </div>
- <div id="file-name"></div> <!-- New div for the name from JSON -->
- <div id="model-name"></div>
- <div id="system-prompt"></div>
- <div id="chat"></div>
- </div>
- <script>
- function convertNewLinesToHTML(text) {
- let formattedText = text.replace(/\n{2,}/g, '<br><br>');
- formattedText = formattedText.replace(/\n/g, '<br>');
- return formattedText;
- }
- document.getElementById('file-input').addEventListener('change', (event) => {
- const file = event.target.files[0];
- if (!file) {
- alert("Please select a JSON file.");
- return;
- }
- const reader = new FileReader();
- reader.onload = function(event) {
- try {
- const chatData = JSON.parse(event.target.result);
- displayChat(chatData.messages);
- // Extracting name from JSON
- const fileName = chatData.name || "No Name Found";
- document.getElementById('file-name').innerText = `File Name: ${fileName}`; // Display the name
- const lastMessage = chatData.messages[chatData.messages.length - 1];
- const modelName = lastMessage.versions[0].steps[0].genInfo?.indexedModelIdentifier || "Unknown Model";
- const fields = chatData.perChatPredictionConfig?.fields;
- const systemPromptField = fields?.find(field => field.key === "llm.prediction.systemPrompt");
- const systemPrompt = systemPromptField ? systemPromptField.value : "No System Prompt Found";
- displayModelInfo(modelName, systemPrompt);
- } catch (error) {
- alert("Error parsing JSON: " + error.message);
- }
- };
- reader.readAsText(file);
- });
- function displayChat(messages) {
- const chatContainer = document.getElementById('chat');
- chatContainer.innerHTML = ''; // Clear previous messages
- const userName = document.getElementById('user-select').value === 'Other'
- ? document.getElementById('user-input').value
- : document.getElementById('user-select').value;
- const assistantName = document.getElementById('assistant-select').value === 'Other'
- ? document.getElementById('assistant-input').value
- : document.getElementById('assistant-select').value;
- messages.forEach(messageObj => {
- const message = messageObj.versions[0]; // Get the first version
- const role = message.role; // Get the role (user/assistant)
- let content = '';
- if (role === 'user' && message.content) {
- content = message.content.map(item => item.text).join(' ');
- } else if (role === 'assistant' && message.steps) {
- content = message.steps.map(step =>
- step.content ? step.content.map(item => item.text).join(' ') : ''
- ).join(' ').trim();
- }
- if (content) {
- const messageDiv = document.createElement('div');
- messageDiv.className = `message ${role}`;
- const displayName = role === 'user' ? userName : assistantName;
- messageDiv.innerHTML = `<strong>${displayName}:</strong> <span class="message-content">${convertNewLinesToHTML(content)}</span>`;
- chatContainer.appendChild(messageDiv);
- }
- });
- }
- function displayModelInfo(modelName, systemPrompt) {
- document.getElementById('model-name').innerText = `Model Name: ${modelName}`;
- document.getElementById('system-prompt').innerText = `System Prompt: ${systemPrompt}`;
- }
- // Event listener for width selection
- document.getElementById('width-select').addEventListener('change', (event) => {
- const width = event.target.value;
- document.getElementById('container').style.width = `${width}%`;
- });
- // Toggle User input visibility
- function toggleUserInput() {
- const userSelect = document.getElementById('user-select');
- const userInput = document.getElementById('user-input');
- userInput.style.display = userSelect.value === 'Other' ? 'block' : 'none';
- }
- // Toggle Assistant input visibility
- function toggleAssistantInput() {
- const assistantSelect = document.getElementById('assistant-select');
- const assistantInput = document.getElementById('assistant-input');
- assistantInput.style.display = assistantSelect.value === 'Other' ? 'block' : 'none';
- }
- // Update User name when typing in input
- function updateUserName() {
- const userInput = document.getElementById('user-input');
- if (userInput.style.display === 'block') {
- document.getElementById('user-select').value = 'Other'; // Ensure dropdown reflects manual entry
- }
- }
- // Update Assistant name when typing in input
- function updateAssistantName() {
- const assistantInput = document.getElementById('assistant-input');
- if (assistantInput.style.display === 'block') {
- document.getElementById('assistant-select').value = 'Other'; // Ensure dropdown reflects manual entry
- }
- }
- // Update chat display when dropdown changes
- document.getElementById('user-select').addEventListener('change', () => {
- document.getElementById('chat').innerHTML = ''; // Clear previous messages
- loadChatData(); // Reload chat data
- toggleUserInput(); // Show/hide user input
- });
- document.getElementById('assistant-select').addEventListener('change', () => {
- document.getElementById('chat').innerHTML = ''; // Clear previous messages
- loadChatData(); // Reload chat data
- toggleAssistantInput(); // Show/hide assistant input
- });
- function loadChatData() {
- const fileInput = document.getElementById('file-input');
- const file = fileInput.files[0];
- if (file) {
- const reader = new FileReader();
- reader.onload = function(event) {
- try {
- const chatData = JSON.parse(event.target.result);
- displayChat(chatData.messages);
- } catch (error) {
- alert("Error parsing JSON: " + error.message);
- }
- };
- reader.readAsText(file);
- }
- }
- // Update chat display on Enter key press
- document.getElementById('user-input').addEventListener('keydown', function(event) {
- if (event.key === 'Enter') {
- updateUserName(); // Update the user name
- document.getElementById('chat').innerHTML = ''; // Clear previous messages
- loadChatData(); // Reload chat data to reflect new name
- }
- });
- document.getElementById('assistant-input').addEventListener('keydown', function(event) {
- if (event.key === 'Enter') {
- updateAssistantName(); // Update the assistant name
- document.getElementById('chat').innerHTML = ''; // Clear previous messages
- loadChatData(); // Reload chat data to reflect new name
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment