Skip to content
Snippets Groups Projects
Commit 5689ed6f authored by Ali Asaria's avatar Ali Asaria
Browse files

scroll api logs to bottom

parent a8ea8796
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
AccordionSummary, AccordionSummary,
Box, Box,
Sheet, Sheet,
Typography,
} from '@mui/joy'; } from '@mui/joy';
import * as chatAPI from 'renderer/lib/transformerlab-api-sdk'; import * as chatAPI from 'renderer/lib/transformerlab-api-sdk';
...@@ -21,6 +22,24 @@ function objectMinusPrompt(obj) { ...@@ -21,6 +22,24 @@ function objectMinusPrompt(obj) {
return rest; return rest;
} }
function isToday(someDateString) {
const someDate = new Date(someDateString);
const today = new Date();
const t =
someDate.getDate() === today.getDate() &&
someDate.getMonth() === today.getMonth() &&
someDate.getFullYear() === today.getFullYear();
console.log(t);
console.log(someDate + ' - ' + today);
return (
someDate.getDate() === today.getDate() &&
someDate.getMonth() === today.getMonth() &&
someDate.getFullYear() === today.getFullYear()
);
}
function renderJSONLinesLog(logs) { function renderJSONLinesLog(logs) {
return logs?.split('\n').map((line, i) => { return logs?.split('\n').map((line, i) => {
try { try {
...@@ -30,7 +49,11 @@ function renderJSONLinesLog(logs) { ...@@ -30,7 +49,11 @@ function renderJSONLinesLog(logs) {
{/* {i}:{' '} */} {/* {i}:{' '} */}
<Accordion key={i} color="primary" variant="soft"> <Accordion key={i} color="primary" variant="soft">
<AccordionSummary> <AccordionSummary>
{line_object.date} - {line_object?.log?.model} <Typography
color={isToday(line_object.date) ? 'black' : 'neutral'}
>
{line_object.date} - {line_object?.log?.model}
</Typography>
</AccordionSummary> </AccordionSummary>
<AccordionDetails> <AccordionDetails>
<pre style={{ whiteSpace: 'pre-wrap' }}> <pre style={{ whiteSpace: 'pre-wrap' }}>
...@@ -46,8 +69,8 @@ function renderJSONLinesLog(logs) { ...@@ -46,8 +69,8 @@ function renderJSONLinesLog(logs) {
} catch (e) { } catch (e) {
return ( return (
<> <>
{/* {i}: {e.message} - {line} */} {/* {i}: {e.message} - {line}
<br /> <br /> */}
</> </>
); );
} }
...@@ -56,10 +79,25 @@ function renderJSONLinesLog(logs) { ...@@ -56,10 +79,25 @@ function renderJSONLinesLog(logs) {
export default function Logs({}) { export default function Logs({}) {
const { data } = useSWR(chatAPI.Endpoints.Global.PromptLog, fetcher); const { data } = useSWR(chatAPI.Endpoints.Global.PromptLog, fetcher);
React.useEffect(() => {
// Scroll to bottom
const ae = document.getElementById('logs_accordion');
ae.scrollTop = ae.scrollHeight;
});
return ( return (
<Sheet style={{ display: 'flex', flexDirection: 'column', height: '100%' }}> <Sheet
style={{
display: 'flex',
flexDirection: 'column',
height: '100%',
paddingBottom: '1rem',
}}
>
<h1>Prompt Log</h1> <h1>Prompt Log</h1>
<Box <Box
id="logs_accordion"
style={{ style={{
overflow: 'auto', overflow: 'auto',
height: '100%', height: '100%',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment