From 726f2334bbc4c750c55a71b57242d85a12e1cdee Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 30 Sep 2025 17:38:43 +0000 Subject: [PATCH] feat: Add hardcoded responses for specific questions This commit introduces a new conditional block in the `submit` function within `app/actions.tsx` to handle specific user queries. When a user asks 'what is a planet computer?' or 'what is qcx-terra?', the application now provides a predefined, hardcoded response. This change bypasses the standard AI agentic workflow for these specific questions, ensuring a fast and consistent answer. The implementation involves: - Checking the user's input against the two specific questions. - If a match is found, updating the UI and AI state with the predefined answer. - Returning early to prevent further processing by the AI agents. --- app/actions.tsx | 75 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/app/actions.tsx b/app/actions.tsx index 0c536aaf..f438d4c8 100644 --- a/app/actions.tsx +++ b/app/actions.tsx @@ -52,7 +52,80 @@ async function submit(formData?: FormData, skip?: boolean) { const maxMessages = useSpecificAPI ? 5 : 10 messages.splice(0, Math.max(messages.length - maxMessages, 0)) - const userInput = skip ? `{"action": "skip"}` : formData?.get('input') as string + const userInput = skip + ? `{"action": "skip"}` + : (formData?.get('input') as string); + + if (userInput.toLowerCase().trim() === 'what is a planet computer?' || userInput.toLowerCase().trim() === 'what is qcx-terra?') { + const definition = userInput.toLowerCase().trim() === 'what is a planet computer?' + ? "A planet computer is a proprietary environment aware system that interoperates Climate forecasting, mapping and scheduling using cutting edge multi-agents to streamline automation and exploration on a planet" + : "QCX-Terra is a model garden of pixel level precision geospatial foundational models for efficient land feature predictions from satellite imagery"; + + const content = JSON.stringify(Object.fromEntries(formData!)); + const type = 'input'; + + aiState.update({ + ...aiState.get(), + messages: [ + ...aiState.get().messages, + { + id: nanoid(), + role: 'user', + content, + type, + }, + ], + }); + + const definitionStream = createStreamableValue(); + definitionStream.done(definition); + + const answerSection = ( +
+ +
+ ); + + uiStream.append(answerSection); + + const groupeId = nanoid(); + const relatedQueries = { items: [] }; + + aiState.done({ + ...aiState.get(), + messages: [ + ...aiState.get().messages, + { + id: groupeId, + role: 'assistant', + content: definition, + type: 'response', + }, + { + id: groupeId, + role: 'assistant', + content: JSON.stringify(relatedQueries), + type: 'related', + }, + { + id: groupeId, + role: 'assistant', + content: 'followup', + type: 'followup', + }, + ], + }); + + isGenerating.done(false); + uiStream.done(); + + return { + id: nanoid(), + isGenerating: isGenerating.value, + component: uiStream.value, + isCollapsed: isCollapsed.value, + }; + } const file = !skip ? (formData?.get('file') as File) : undefined if (!userInput && !file) {