-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from polywrap/dev
merge dev
- Loading branch information
Showing
10 changed files
with
141 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import TextField from "./TextField"; | ||
import { useRouter } from "next/navigation"; | ||
import useSession from "@/hooks/useSession"; | ||
import { startRun } from "@/app/actions"; | ||
import ChatInputButton from "./ChatInputButton"; | ||
|
||
export default function NoResultsFound(props: { | ||
prompt: string; | ||
}) { | ||
const [currentPrompt, setCurrentPrompt] = useState<string>(props.prompt); | ||
const [isRegenerating, setIsRegenerating] = useState(false); | ||
const { data: session } = useSession(); | ||
const router = useRouter(); | ||
|
||
async function regenerateStrat(prompt: string) { | ||
setIsRegenerating(true); | ||
if (!session) { | ||
throw new Error("User needs to have a session"); | ||
} | ||
const response = await startRun(prompt, session.supabaseAccessToken); | ||
router.push(`/s/${response.runId}`); | ||
setIsRegenerating(false); | ||
} | ||
|
||
return ( | ||
<> | ||
<div className='flex justify-center py-10 px-6 flex-grow flex-column'> | ||
<div className='flex flex-col mx-auto max-w-wrapper w-full space-y-4'> | ||
<TextField | ||
label={`No results found for ${props.prompt}, try again...`} | ||
value={currentPrompt} | ||
onChange={(e) => setCurrentPrompt(e.target.value)} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter" && !!currentPrompt) { | ||
regenerateStrat(currentPrompt); | ||
} | ||
}} | ||
rightAdornment={ | ||
<ChatInputButton | ||
running={isRegenerating} | ||
message={currentPrompt} | ||
regenerate | ||
handleSend={async () => { | ||
if (currentPrompt) { | ||
await regenerateStrat(currentPrompt); | ||
} | ||
}} | ||
/> | ||
} | ||
/> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,56 @@ | ||
import { Tables } from "@/supabase/dbTypes"; | ||
import { COMPLETED_TEXTS } from "@/utils/logs"; | ||
import { useState, useEffect } from "react"; | ||
|
||
export function useProgressTime( | ||
stepTimes: number[], | ||
logs: Array<Tables<"logs">>, | ||
prompt: string, | ||
logs: Array<Tables<"logs">> | ||
) { | ||
const [startTime] = useState(Date.now()); | ||
const [startTime, setStartTime] = useState(Date.now()); | ||
const [progressInformation, setProgressInformation] = useState({ | ||
logs, | ||
time: 0, | ||
progress: 0, | ||
}); | ||
|
||
// Capture the start time when the hook is first called or when stepTimes or currentStep changes | ||
const totalTime = stepTimes.reduce((a, b) => a + b, 0); | ||
let currentStep = logs.findIndex( | ||
(x) => x.status === "IN_PROGRESS" | ||
); | ||
|
||
useEffect(() => { | ||
const totalTime = stepTimes.reduce((a, b) => a + b, 0); | ||
setStartTime(Date.now()) | ||
}, [currentStep]) | ||
|
||
useEffect(() => { | ||
const intervalId = setInterval(function () { | ||
const now = Date.now(); | ||
const secondsFromStart = (now - startTime) / 1000; // Convert ms to seconds | ||
let currentStep = progressInformation.logs.findIndex( | ||
(x) => x.status === "IN_PROGRESS" | ||
); | ||
const elapsedTimeSinceStart = (now - startTime) / 1000; // Convert ms to seconds | ||
|
||
if (elapsedTimeSinceStart > stepTimes[currentStep]) { | ||
return | ||
} | ||
|
||
const elapsedTimeInSteps = stepTimes | ||
.slice(0, currentStep + 1) | ||
.slice(0, currentStep) | ||
.reduce((a, b) => a + b, 0); | ||
|
||
const timeRemaining = Math.max(totalTime - secondsFromStart, 0); | ||
|
||
const progress = (secondsFromStart / totalTime) * 100; | ||
if (timeRemaining <= 1) { | ||
clearInterval(intervalId); | ||
return; | ||
} | ||
const totalElapsedTime = elapsedTimeSinceStart + elapsedTimeInSteps; | ||
|
||
if ( | ||
secondsFromStart > elapsedTimeInSteps && | ||
stepTimes.length > currentStep && | ||
currentStep !== -1 | ||
) { | ||
setProgressInformation(({ logs }) => { | ||
const newLogs = [...logs]; | ||
newLogs[currentStep].status = "COMPLETED"; | ||
newLogs[currentStep].value = COMPLETED_TEXTS[newLogs[currentStep].step_name] | ||
if (currentStep === 0) { | ||
newLogs[currentStep].value += " to " + prompt | ||
} | ||
const timeRemaining = Math.max(totalTime - totalElapsedTime, 0); // Prevent negative time | ||
const progress = (totalElapsedTime / totalTime) * 100; | ||
|
||
if (stepTimes.length > currentStep + 1) { | ||
newLogs[currentStep + 1].status = "IN_PROGRESS"; | ||
} | ||
return { | ||
time: timeRemaining, | ||
progress: progress, | ||
logs: newLogs, | ||
}; | ||
}); | ||
return; | ||
if (timeRemaining < 1) { | ||
return | ||
} | ||
|
||
setProgressInformation((i) => ({ | ||
...i, | ||
time: timeRemaining, | ||
progress: progress, | ||
})); | ||
|
||
}, 1000); | ||
return () => clearInterval(intervalId); | ||
}, [stepTimes]); | ||
}, [stepTimes, currentStep]); | ||
|
||
return progressInformation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters