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: know when goose is asking for input #352

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 2 deletions ui/desktop/src/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ function ChatContent({
setWorking(Working.Idle);

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. 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 + "\nYou must provide a response strictly limited to one of the following three words: QUESTION, OPTIONS, READY. No other words, phrases, or explanations are allowed.",
"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,
"You are a simple classifier that takes content and decides if it is asking for input from a person before continuing, or not. If it is a question very clearly, return QUESTION, otherwise READY. ### Message Content:\n" + message.content + "\nYou must provide a response strictly limited to one of the following two words: QUESTION, READY. No other words, phrases, or explanations are allowed. Response:",
"You are a simple classifier that takes content and decides if it a list of options or plans to choose from, or not a list of options to choose from It is IMPORTANT that you really know this is a choice, just not numbered steps. If it is a list of options and you are 95% sure, return OPTIONS, otherwise return NO. ### Message Content:\n" + message.content + "\nYou must provide a response strictly limited to one of the following two words:OPTIONS, NO. No other words, phrases, or explanations are allowed. Response:",
"If the content is 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 + "\n\nYou must provide a response strictly as json in the format descriribed. No other words, phrases, or explanations are allowed. Response:",
];

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

{/* TODO - Re-enable once detection logic for when to show is correct */}
{false && metadata && (
{/* append false && to turn this off */}
{metadata && (
<div className="flex mb-[16px]">
<GooseResponseForm
message={message.content}
Expand Down
31 changes: 21 additions & 10 deletions ui/desktop/src/components/GooseResponseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,33 @@ export default function GooseResponseForm({ message, metadata, append }: GooseRe
const [selectedOption, setSelectedOption] = useState(null);
const prevStatusRef = useRef(null);

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

if (metadata) {
isReady = metadata[0] === "READY";
window.electron.logInfo('metadata:'+ JSON.stringify(metadata, null, 2));
}



if (metadata) {
isQuestion = metadata[0] === "QUESTION";
isOptions = metadata[0] === "OPTIONS";
isOptions = metadata[1] === "OPTIONS";

if (isOptions && metadata[1]) {
if (isQuestion && isOptions && metadata[2]) {
try {
let optionsData = metadata[1];
if (optionsData.startsWith('```json')) {
optionsData = optionsData.replace(/```json/g, '').replace(/```/g, '');
}
let optionsData = metadata[2];
// Use a regular expression to extract the JSON block
const jsonBlockMatch = optionsData.match(/```json([\s\S]*?)```/);

// If a JSON block is found, extract and clean it
if (jsonBlockMatch) {
optionsData = jsonBlockMatch[1].trim(); // Extract the content inside the block
} else {
// Optionally, handle the case where there is no explicit ```json block
console.warn("No JSON block found in the provided string.");
}
options = JSON.parse(optionsData);
options = options.filter(
(opt) =>
Expand Down Expand Up @@ -88,7 +99,7 @@ export default function GooseResponseForm({ message, metadata, append }: GooseRe

return (
<div className="space-y-4">
{isQuestion && (
{isQuestion && !isOptions && (
<div className="flex items-center gap-4 p-4 rounded-lg bg-tool-card border">
<Button
onClick={handleAccept}
Expand All @@ -108,7 +119,7 @@ export default function GooseResponseForm({ message, metadata, append }: GooseRe
</Button>
</div>
)}
{isOptions && options.length > 0 && (
{isQuestion && isOptions && options.length > 0 && (
<div className="space-y-4">
{options.map((opt, index) => (
<div
Expand Down
Loading