From 646a46b911c2c73df5213c59727bbb0fc15276bb Mon Sep 17 00:00:00 2001 From: akdeb Date: Wed, 4 Jun 2025 20:10:07 +0100 Subject: [PATCH] cleanup --- server-deno/main.ts | 1 - server-deno/supabase.ts | 91 +---------------------------------------- 2 files changed, 2 insertions(+), 90 deletions(-) diff --git a/server-deno/main.ts b/server-deno/main.ts index 42f3dab..47eac4b 100644 --- a/server-deno/main.ts +++ b/server-deno/main.ts @@ -16,7 +16,6 @@ import { createSystemPrompt, getChatHistory, getDeviceInfo, - getOpenAiApiKey, getSupabaseClient, updateUserSessionTime, } from "./supabase.ts"; diff --git a/server-deno/supabase.ts b/server-deno/supabase.ts index 38f6ce2..1897f2c 100644 --- a/server-deno/supabase.ts +++ b/server-deno/supabase.ts @@ -101,52 +101,6 @@ Your physical form is in the form of a physical object or a toy. A person interacts with you by pressing a button, sends you instructions and you must respond in a concise conversational style. `; -const getDoctorGuidanceHistory = ( - data: IConversation[], -): string => { - return data?.map((chat: IConversation) => { - const timestamp = chat.created_at - ? new Date(chat.created_at).toLocaleString() - : ""; - return `${chat.role} [${timestamp}]: ${chat.content}`; - }).join("") ?? ""; -}; - -const DoctorGuidelinesPrompt = (chatHistory: IConversation[]) => { - const doctorGuidanceHistory = getDoctorGuidanceHistory(chatHistory); - return ` -Through their phone, the doctor has given you the following instructions: -${doctorGuidanceHistory} - -You must follow these instructions while you interact with the child patient. - `; -}; - -const DoctorPromptTemplate = (user: IUser, chatHistory: IConversation[]) => { - const userMetadata = user.user_info.user_metadata as IDoctorMetadata; - const doctorName = userMetadata.doctor_name || "Doctor"; - const hospitalName = userMetadata.hospital_name || "An amazing hospital"; - const specialization = userMetadata.specialization || "general medicine"; - const favoritePhrases = userMetadata.favorite_phrases || - "You're doing an amazing job"; - const doctorGuidelinesPrompt = DoctorGuidelinesPrompt(chatHistory); - - return ` -You are speaking to a child patient under the care of doctor ${doctorName} from hospital or clinic ${hospitalName}. The child may be undergoing procedures such as ${specialization}. -You are a friendly, compassionate toy designed to offer comfort and care. You specialize in calming children and answering any questions with simple, concise and calming explanations. - -Doctor's recent guidelines: -${doctorGuidelinesPrompt} - -Conversation Guidelines: -- You should engage with the child in a fun and engaging way rather than asking open-ended questions. -- Gamify it, add fun riddles or games to keep the child engaged. -- Use the doctor's observations from the chat history to make the conversation more engaging and interesting. -- Keep the conversation light, fun and engaging. -- Add in the doctor's favorite phrases ${favoritePhrases} to make the child feel comfortable and at ease. -`; -}; - const getStoryPromptTemplate = (user: IUser, chatHistory: string) => { const childName = user.supervisee_name; const childAge = user.supervisee_age; @@ -208,49 +162,11 @@ export const createFirstMessage = ( ): string => { const { timestamp, user } = payload; - // If no chat history, return null (let the system handle a brand new conversation) - if (!chatHistory || chatHistory.length === 0) { - return ""; - } - const firstMessagePrompt = user.personality?.first_message_prompt ? `Always start the conversation following these instructions from the user: ${user.personality?.first_message_prompt}` - : ""; + : "Say hello to the user"; - // Get the most recent conversation timestamp - const lastMessageTime = new Date(chatHistory[0].created_at); - const currentTime = new Date(timestamp); - - // Calculate time difference in minutes - const timeDiffMinutes = - (currentTime.getTime() - lastMessageTime.getTime()) / (1000 * 60); - - let systemFirstMessage: string; - - if (timeDiffMinutes < 2) { - // If less than 5 minutes, likely an accidental disconnection - systemFirstMessage = - `The previous conversation was interrupted just moments ago. Please continue where you left off, maintaining the same context and tone.`; - } else if (timeDiffMinutes < 60) { - // If less than an hour - systemFirstMessage = `It's been about ${ - Math.round(timeDiffMinutes) - } minutes since your last conversation. You may continue from where you left off or start something new.`; - } else if (timeDiffMinutes < 60 * 24) { - // If less than a day - const hours = Math.round(timeDiffMinutes / 60); - systemFirstMessage = `It's been about ${hours} hour${ - hours > 1 ? "s" : "" - } since your last conversation. The user just started a new conversation!`; - } else { - // If more than a day - const days = Math.round(timeDiffMinutes / (60 * 24)); - systemFirstMessage = `Welcome the user back after ${days} day${ - days > 1 ? "s" : "" - }! It's been a while since your last conversation.`; - } - - return systemFirstMessage + firstMessagePrompt; + return firstMessagePrompt; }; export const createSystemPrompt = ( @@ -277,9 +193,6 @@ export const createSystemPrompt = ( case "user": systemPrompt = UserPromptTemplate(user); break; - case "doctor": - systemPrompt = DoctorPromptTemplate(user, chatHistory); - break; default: throw new Error("Invalid user type"); }