Skip to content
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

fix: notification questions improvements #340

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ui/desktop/src/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ function ChatContent({
setStatus('Goose is ready');

const promptTemplates = [
"Take a look at this content, if this looks like it could be asking for a confirmation, return QUESTION. If it looks like it is a list of options or plans to choose from, return OPTIONS, otherwise return READY. \n ### Message Content:\n" + message.content,
"If the content is clearly a list of distinct options or plans of action to choose from, and not just a list of things, but clearly a list of things to choose one from from, take into account the Message Content alone, try to format it in a json array, like this JSON array of objects of the form optionTitle:string, optionDescription:string (markdown).\n If is not a list of options or plans to choose from, then return empty list.\n ### Message Content:\n" + message.content,
"If the content is a request for input from the user, taking into account the Message Content alone, try to format it in as JSON object that fields in it of the form: fieldName:{type: string, number, email or date, title:string, description:optional markdown, required: true or false}:\n If it does not match, then return empty object.\n ### Message Content:\n" + message.content,
"Take a look at this content, if this looks like it could be asking for a confirmation, return QUESTION. If it looks like it is a list of options or plans to choose from, return OPTIONS. It can't just be a list, but clearly must be asking the user to pick one or more of the plan or option alternatives, otherwise return READY. \n ### Message Content:\n" + message.content,
"If the content is clearly a list of distinct options or plans of action to choose from, and not just a list of things, but clearly a list of things to choose one from from, taking into account the Message Content alone, try to format it in a json array, like this JSON array of objects of the form optionTitle:string, optionDescription:string (markdown).\n If is not a list of options or plans to choose from, then return empty list.\n ### Message Content:\n" + message.content,
];

const fetchResponses = await askAi(promptTemplates);
Expand Down
4 changes: 1 addition & 3 deletions ui/desktop/src/components/GooseMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ export default function GooseMessage({ message, metadata, messages, append }: Go
</div>
)}

{false && metadata && (
<div className="bg-goose-bubble text-white rounded-2xl p-4 mb-[16px]">
{metadata && (
<GooseResponseForm
message={message.content}
metadata={metadata}
append={append}
/>
</div>
)}
</div>
</div>
Expand Down
32 changes: 18 additions & 14 deletions ui/desktop/src/components/GooseResponseForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { GPSIcon } from './ui/icons';
import ReactMarkdown from 'react-markdown';
import { Button } from './ui/button';
Expand All @@ -12,12 +12,15 @@ interface GooseResponseFormProps {

export default function GooseResponseForm({ message, metadata, append }: GooseResponseFormProps) {
const [selectedOption, setSelectedOption] = useState(null);
const prevStatusRef = useRef(null);

let isReady = false;
let isQuestion = false;
let isOptions = false;
let options = [];

console.log('metadata:', metadata[0]);

if (metadata) {
isReady = metadata[0] === "READY";
isQuestion = metadata[0] === "QUESTION";
Expand All @@ -42,6 +45,19 @@ export default function GooseResponseForm({ message, metadata, append }: GooseRe
}
}

useEffect(() => {
if (
(metadata && (metadata[0] === "QUESTION" || metadata[0] === "OPTIONS")) &&
prevStatusRef.current !== metadata[0]
) {
window.electron.showNotification({
title: 'Goose has a question for you',
body: `Please check with Goose to approve the plan of action`,
});
}
prevStatusRef.current = metadata ? metadata[0] : null;
}, [metadata]);

const handleOptionClick = (index) => {
setSelectedOption(index);
};
Expand Down Expand Up @@ -72,20 +88,8 @@ export default function GooseResponseForm({ message, metadata, append }: GooseRe
}
};

if (isQuestion || isOptions) {
window.electron.showNotification({
title: 'Goose has a question for you',
body: `please check with goose to approve the plan of action`,
});
}

return (
<div className="space-y-4">
{(!isOptions || options.length === 0) && (
<div className="prose prose-xs max-w-none">
<ReactMarkdown>{message}</ReactMarkdown>
</div>
)}
{isQuestion && (
<div className="flex items-center gap-4 p-4 rounded-lg bg-tool-card border">
<Button
Expand Down Expand Up @@ -138,4 +142,4 @@ export default function GooseResponseForm({ message, metadata, append }: GooseRe
)}
</div>
);
}
}
Loading