Skip to content

Commit

Permalink
extract the summary from the content
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 11, 2024
1 parent d97a62e commit 908386f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
20 changes: 15 additions & 5 deletions app/src/lib/components/CheckFinalResponse.svelte
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
<script context="module">
const FINAL_RESPONSE_SUFFIX = 'Please click the button below to start generating the audiocast.';
export const FINAL_RESPONSE_PREFIX = 'Ok, thanks for clarifying!';
export const FINAL_RESPONSE_SUFFIX =
'Please click the button below to start generating the audiocast.';
</script>

<script lang="ts">
import { createEventDispatcher, onMount } from 'svelte';
import { Button } from './ui/button';
export let content: string;
const dispatch = createEventDispatcher<{
finalResponse: void;
generate: void;
reviewSource: void;
startNew: void;
generate: { summary: string };
}>();
let mounted = false;
$: finalResponse = content.includes(FINAL_RESPONSE_SUFFIX);
$: if (mounted && finalResponse) dispatch('finalResponse');
function ongenerate() {
const replacePrefixRegex = new RegExp(FINAL_RESPONSE_PREFIX, 'gi');
const replaceSuffixRegex = new RegExp(FINAL_RESPONSE_SUFFIX, 'gi');
const summary = content.replace(replacePrefixRegex, '').replace(replaceSuffixRegex, '').trim();
dispatch('generate', { summary });
}
onMount(() => (mounted = true));
</script>

{#if finalResponse}
<div class="animate-fade-in grid sm:grid-cols-3 gap-3">
<Button
class="bg-emerald-600 text-emerald-100 hover:bg-emerald-700"
on:click={() => dispatch('generate')}>Generate Audiocast</Button
<Button class="bg-emerald-600 text-emerald-100 hover:bg-emerald-700" on:click={ongenerate}
>Generate Audiocast</Button
>

<Button
Expand Down
28 changes: 28 additions & 0 deletions app/src/lib/components/chat-list/ChatListActionItems.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts">
import { goto } from '$app/navigation';
import type { ContentCategory } from '@/utils/types';
export let sessionId: string;
export let category: ContentCategory;
function ongenerate(summary: string) {
console.log('ongenerate', sessionId, summary, category);
fetch('/api/generate', {
method: 'POST',
body: JSON.stringify({ sessionId, summary, category }),
headers: { 'Content-Type': 'application/json' }
});
}
function onreviewSource() {
console.log('reviewSource');
}
async function onstartNew() {
return goto('/', { invalidateAll: true, replaceState: true });
}
</script>

<div>
<slot {ongenerate} {onreviewSource} {onstartNew}></slot>
</div>
23 changes: 16 additions & 7 deletions app/src/routes/chat/[sessionId=sessionId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { uuid } from '@/utils/uuid';
import { streamingResponse } from '$lib/utils/streamingResponse';
import CheckFinalResponse from '@/components/CheckFinalResponse.svelte';
import ChatListActionItems from '@/components/chat-list/ChatListActionItems.svelte';
export let data;
Expand Down Expand Up @@ -87,13 +88,21 @@
{#each sessionChats as item (item.id)}
<ChatListItem type={item.role} content={item.content} loading={item.loading} />

<CheckFinalResponse
content={item.content}
on:finalResponse={scrollChatContent}
on:generate
on:reviewSource
on:startNew
/>
<ChatListActionItems
{category}
{sessionId}
let:ongenerate
let:onreviewSource
let:onstartNew
>
<CheckFinalResponse
content={item.content}
on:finalResponse={scrollChatContent}
on:generate={({ detail }) => ongenerate(detail.summary)}
on:reviewSource={onreviewSource}
on:startNew={onstartNew}
/>
</ChatListActionItems>
{/each}
{/key}
</div>
Expand Down

0 comments on commit 908386f

Please sign in to comment.