-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Add hardcoded responses for specific questions #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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'; | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+59
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential runtime crash: SuggestionConsider refactoring this block to safely normalize the input and to use a lookup for hardcoded responses. This also simplifies the ternary and avoids repeated normalization: const normalizedInput = (typeof userInput === 'string' ? userInput : '').toLowerCase().trim();
const HARD_CODED_ANSWERS: Record<string, string> = {
'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',
'what is qcx-terra?': 'QCX-Terra is a model garden of pixel level precision geospatial foundational models for efficient land feature predictions from satellite imagery',
};
if (HARD_CODED_ANSWERS[normalizedInput]) {
const definition = HARD_CODED_ANSWERS[normalizedInput];
const content = JSON.stringify({ input: userInput ?? '' });
const type = 'input';
aiState.update({
...aiState.get(),
messages: [
...aiState.get().messages,
{ id: nanoid(), role: 'user', content, type },
],
});
const definitionStream = createStreamableValue();
definitionStream.done(definition);
uiStream.append(
<Section title="response">
<BotMessage content={definitionStream.value} />
</Section>
);
const groupId = nanoid();
const relatedQueries = { items: [] };
aiState.done({
...aiState.get(),
messages: [
...aiState.get().messages,
{ id: groupId, role: 'assistant', content: definition, type: 'response' },
{ id: groupId, role: 'assistant', content: JSON.stringify(relatedQueries), type: 'related' },
{ id: groupId, role: 'assistant', content: 'followup', type: 'followup' },
],
});
isGenerating.done(false);
uiStream.done();
return {
id: groupId,
isGenerating: isGenerating.value,
component: uiStream.value,
isCollapsed: isCollapsed.value,
};
}Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this refactor.
Comment on lines
+64
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
SuggestionPrefer stable serialization and avoid the non-null assertion: const content = JSON.stringify({ input: userInput ?? '' });
const type = 'input';Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this fix. |
||||||||||||||||
| aiState.update({ | ||||||||||||||||
| ...aiState.get(), | ||||||||||||||||
| messages: [ | ||||||||||||||||
| ...aiState.get().messages, | ||||||||||||||||
| { | ||||||||||||||||
| id: nanoid(), | ||||||||||||||||
| role: 'user', | ||||||||||||||||
| content, | ||||||||||||||||
| type, | ||||||||||||||||
| }, | ||||||||||||||||
| ], | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+64
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not persist entire FormData; store only the minimal input field Serializing - const content = JSON.stringify(Object.fromEntries(formData!));
+ // Only persist minimal structured input to avoid leaking other form fields/files
+ const content = JSON.stringify({ input: userInput });
const type = 'input';
|
||||||||||||||||
| const definitionStream = createStreamableValue(); | ||||||||||||||||
| definitionStream.done(definition); | ||||||||||||||||
|
|
||||||||||||||||
| const answerSection = ( | ||||||||||||||||
| <Section title="response"> | ||||||||||||||||
| <BotMessage content={definitionStream.value} /> | ||||||||||||||||
| </Section> | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| uiStream.append(answerSection); | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+89
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial UI parity: append Follow-up section in the early path General flow appends a Follow-up section to the stream; the early path should too for consistent UX. - uiStream.append(answerSection);
+ uiStream.append(answerSection);
+ uiStream.append(
+ <Section title="Follow-up">
+ <FollowupPanel />
+ </Section>
+ );📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| const groupeId = nanoid(); | ||||||||||||||||
| const relatedQueries = { items: [] }; | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+91
to
+93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Avoid redeclaring groupeId
- const groupeId = nanoid();
- const relatedQueries = { items: [] };
+ const relatedQueries = { items: [] };📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| 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', | ||||||||||||||||
| }, | ||||||||||||||||
| ], | ||||||||||||||||
|
Comment on lines
+99
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All three assistant messages use the same SuggestionAssign unique IDs to each message: If you prefer grouping semantics, we can add a |
||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| isGenerating.done(false); | ||||||||||||||||
| uiStream.done(); | ||||||||||||||||
|
|
||||||||||||||||
| return { | ||||||||||||||||
| id: nanoid(), | ||||||||||||||||
| isGenerating: isGenerating.value, | ||||||||||||||||
| component: uiStream.value, | ||||||||||||||||
| isCollapsed: isCollapsed.value, | ||||||||||||||||
| }; | ||||||||||||||||
|
Comment on lines
+122
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SuggestionReturn the same group id you used for the assistant messages to keep grouping consistent, e.g.: return {
id: groupeId, // or `groupId` if you rename it
isGenerating: isGenerating.value,
component: uiStream.value,
isCollapsed: isCollapsed.value,
};Reply with "@CharlieHelps yes please" if you'd like me to add a commit that wires this up consistently. |
||||||||||||||||
| } | ||||||||||||||||
| const file = !skip ? (formData?.get('file') as File) : undefined | ||||||||||||||||
|
|
||||||||||||||||
| if (!userInput && !file) { | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null-safe normalization: prevent runtime on file-only or non-text submissions
userInputcan benull/undefined(e.g., file-only requests). Calling.toLowerCase()will throw. Compute a normalized string once and guard againstskip. Also avoid repeating.toLowerCase().trim().Apply:
📝 Committable suggestion
🤖 Prompt for AI Agents