| 46 | type NonUserMessage = FunctionMessage | AssistantMessage; |
| 47 | |
| 48 | async function saveAnalyticsToDB( |
| 49 | instructionMessage: string, |
| 50 | llmResponse: string, |
| 51 | orgId: number, |
| 52 | dbData: { conversationId: number; index: number }, |
| 53 | ) { |
| 54 | const insertRes = await supabase.from("analytics_code_snippets").insert({ |
| 55 | // The user message contents |
| 56 | instruction_message: instructionMessage, |
| 57 | output: llmResponse, |
| 58 | org_id: orgId, |
| 59 | conversation_id: dbData.conversationId, |
| 60 | conversation_index: dbData.index, |
| 61 | }); |
| 62 | if (insertRes.error) { |
| 63 | console.error( |
| 64 | "Failed to insert analytics code snippet to DB:", |
| 65 | insertRes.error, |
| 66 | ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | export async function runDataAnalysis( |
| 71 | instruction: string, |