diff options
| author | Dhravya Shah <[email protected]> | 2024-07-25 17:35:15 -0500 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2024-07-25 17:35:15 -0500 |
| commit | c57719446ae95c2bbd432d7b2b6648a23b35c351 (patch) | |
| tree | c6f7aca777c7f4748cc6dc335fe56fba8725af02 /apps/web/lib | |
| parent | add try catch in api/add for better error handling (diff) | |
| parent | ughh, regenerated migrations. my bad. (diff) | |
| download | supermemory-kush/experimental-thread.tar.xz supermemory-kush/experimental-thread.zip | |
solve merge conflictskush/experimental-thread
Diffstat (limited to 'apps/web/lib')
| -rw-r--r-- | apps/web/lib/searchParams.ts | 1 | ||||
| -rw-r--r-- | apps/web/lib/utils.ts | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/apps/web/lib/searchParams.ts b/apps/web/lib/searchParams.ts index 2e8b1633..b90b560c 100644 --- a/apps/web/lib/searchParams.ts +++ b/apps/web/lib/searchParams.ts @@ -32,4 +32,5 @@ export const chatSearchParamsCache = createSearchParamsCache({ return valid.data; }), + proMode: parseAsBoolean.withDefault(false), }); diff --git a/apps/web/lib/utils.ts b/apps/web/lib/utils.ts new file mode 100644 index 00000000..98ec6e98 --- /dev/null +++ b/apps/web/lib/utils.ts @@ -0,0 +1,23 @@ +export function getRandomSentences(fullQuery: string): string { + // Split the fullQuery into sentences + const sentences = fullQuery.match(/[^.!?]+[.!?]+/g) || []; + + // Function to get a random integer between min and max + function getRandomInt(min: number, max: number): number { + return Math.floor(Math.random() * (max - min)) + min; + } + + let selectedSentences = ""; + let totalCharacters = 0; + + // Select random sentences until totalCharacters is at least 1000 + while (totalCharacters < 1000 && sentences.length > 0) { + const randomIndex = getRandomInt(0, sentences.length); + const sentence = sentences[randomIndex]; + selectedSentences += sentence; + totalCharacters += sentence?.length || 0; + sentences.splice(randomIndex, 1); // Remove the selected sentence from the array + } + + return selectedSentences; +} |