(
chatHistory: IConversation[],
payload: IPayload,
)
| 169 | }; |
| 170 | |
| 171 | export const createSystemPrompt = ( |
| 172 | chatHistory: IConversation[], |
| 173 | payload: IPayload, |
| 174 | ): string => { |
| 175 | const { user, timestamp } = payload; |
| 176 | const chatHistoryString = composeChatHistory(chatHistory); |
| 177 | console.log("chatHistoryString", chatHistoryString); |
| 178 | const commonPrompt = getCommonPromptTemplate( |
| 179 | chatHistoryString, |
| 180 | user, |
| 181 | timestamp, |
| 182 | ); |
| 183 | |
| 184 | const isStory = user.personality?.is_story; |
| 185 | if (isStory) { |
| 186 | const storyPrompt = getStoryPromptTemplate(user, chatHistoryString); |
| 187 | return storyPrompt; |
| 188 | } |
| 189 | |
| 190 | let systemPrompt: string; |
| 191 | switch (user.user_info.user_type) { |
| 192 | case "user": |
| 193 | systemPrompt = UserPromptTemplate(user); |
| 194 | break; |
| 195 | default: |
| 196 | throw new Error("Invalid user type"); |
| 197 | } |
| 198 | return commonPrompt + systemPrompt; |
| 199 | }; |
| 200 | |
| 201 | export const addConversation = async ( |
| 202 | supabase: SupabaseClient, |
no test coverage detected