Skip to content

Commit

Permalink
generate session title after final ai response
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 11, 2024
1 parent 5107dd4 commit f2d34fb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions api/src/utils/get_session_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ async def get_session_title(request: GetSessionTitleModel, background_tasks: Bac
"""
system_prompt = f"""Your task is deduce a concise, comprehensive and descriptive topic or title for the following content.
Content category: {request.summary}
High level summary: {request.category}
Content category: {request.summary}
1. Keep it succint within the length of a short phrase.
2. No preambles or unnecessary information, just the topic or title.
2. Be exhaustive as possible, capturing both the category and summary.
3. No preambles or unnecessary information, just the topic or title.
"""

session_id = request.sessionId
Expand Down
37 changes: 37 additions & 0 deletions app/src/lib/components/ChatListActionItems.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import { Button } from './ui/button';
import { getSessionContext } from '@/stores/sessionContext.svelte';
import RenderAudioSource from '@/components/RenderAudioSource.svelte';
import { streamingResponse } from '@/utils/streamingResponse';
export let sessionId: string;
export let category: ContentCategory;
export let content: string;
export let title: string;
const { session$, audioSource$, fetchingSource$, sessionId$, sessionCompleted$ } =
getSessionContext();
Expand Down Expand Up @@ -58,6 +60,41 @@
.catch((error) => toast.error(error.message))
.finally(() => ($fetchingSource$ = false));
}
$: if (title.toLowerCase() === 'untitled') getSessionTitle();
let generatingTitle = false;
async function getSessionTitle() {
if (generatingTitle) return;
generatingTitle = true;
return fetch(`${env.API_BASE_URL}/get-session-title`, {
method: 'POST',
body: JSON.stringify({
sessionId,
category,
summary: getSummary()
}),
headers: { 'Content-Type': 'application/json' }
})
.then(handleStreamingResponse)
.finally(() => (generatingTitle = false));
}
async function handleStreamingResponse(res: Response) {
if (!res.ok) return;
for await (const chunk of streamingResponse(res)) {
session$.update((session) => {
if (session) {
if (session.title.toLowerCase() === 'untitled') session.title = '';
session.title += chunk;
}
return session;
});
}
}
</script>

<div>
Expand Down

0 comments on commit f2d34fb

Please sign in to comment.