Skip to content

Commit

Permalink
[app] Only render ToolResults relevant to the user - clean up logging (
Browse files Browse the repository at this point in the history
…#348)

Co-authored-by: Alex Hancock <[email protected]>
  • Loading branch information
alexhancock and Alex Hancock authored Nov 26, 2024
1 parent 89da1fa commit 7b638bf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 54 deletions.
4 changes: 0 additions & 4 deletions ui/desktop/src/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ function ChatContent({
const fetchResponses = await askAi(promptTemplates);

setMessageMetadata((prev) => ({ ...prev, [message.id]: fetchResponses }));

console.log('All responses:', fetchResponses);
},
});

Expand Down Expand Up @@ -302,7 +300,6 @@ export default function ChatWindow() {
* Utility to ask the LLM any question to clarify without wider context.
*/
async function askAi(promptTemplates: string[]) {
console.log('askAi called...');
const responses = await Promise.all(
promptTemplates.map(async (template) => {
const response = await fetch(getApiUrl('/ask'), {
Expand All @@ -318,7 +315,6 @@ async function askAi(promptTemplates: string[]) {
}

const data = await response.json();
console.log('ask Response:', data.response);

return data.response;
})
Expand Down
2 changes: 0 additions & 2 deletions ui/desktop/src/components/GooseResponseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export default function GooseResponseForm({ message, metadata, append }: GooseRe
let isOptions = false;
let options = [];

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

if (metadata) {
isReady = metadata[0] === "READY";
isQuestion = metadata[0] === "QUESTION";
Expand Down
82 changes: 46 additions & 36 deletions ui/desktop/src/components/ToolInvocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,17 @@ function ToolCall({ call }: ToolCallProps) {


interface ResultItem {
text?: string
type: 'text' | 'image'
mimeType?: string
data?: string // Base64 encoded image data
text?: string;
type: 'text' | 'image';
mimeType?: string;
data?: string; // Base64 encoded image data
audience?: string[]; // Array of audience types
}

interface ToolResultProps {
result: {
message?: string
result?: ResultItem[] | string
result?: ResultItem[]
state?: string
toolCallId?: string
toolName?: string
Expand All @@ -83,46 +84,55 @@ interface ToolResultProps {
}

function ToolResult({ result }: ToolResultProps) {
if (!result || !result.result) return null
// If no result info, don't show anything
if (!result || !result.result) return null;

return (
// Normalize to an array
const results = Array.isArray(result.result)
? result.result
: [result.result];

// Find results where either audience is not set, or it's set to a list that contains user
const filteredResults = results
.filter((item: ResultItem) => !item.audience || item.audience?.includes('user'))

if (filteredResults.length === 0) return null;

return (
<Card className="bg-tool-card p-4 mb-[16px]">
<div className="flex items-center">
<BoxIcon size={14} />
<span className="ml-[8px]">Tool Result: {result.toolName.substring(result.toolName.lastIndexOf("__") + 2)}</span>
</div>
{Array.isArray(result.result) ? (
<div>
{result.result.map((item: ResultItem, index: number) => (
<div key={index}>
{item.type === 'text' && item.text && (
<ReactMarkdown className="text-tool-result-green whitespace-pre-wrap p-2">
{item.text}
</ReactMarkdown>
)}
{item.type === 'image' && item.data && item.mimeType && (
<img
src={`data:${item.mimeType};base64,${item.data}`}
alt="Tool result"
className="max-w-full h-auto rounded-md"
onError={(e) => {
console.error('Failed to load image: Invalid MIME-type encoded image data');
e.currentTarget.style.display = 'none';
}}
/>
)}
</div>
))}
</div>
) : (
<ReactMarkdown className="text-tool-result-green whitespace-pre-wrap p-2">
{result.result}
</ReactMarkdown>
)}
<div>
{filteredResults.map((item: ResultItem, index: number) => (
<div key={index}>
{item.type === 'text' && item.text && (
<ReactMarkdown className="text-tool-result-green whitespace-pre-wrap p-2">
{item.text}
</ReactMarkdown>
)}
{item.type === 'image' && item.data && item.mimeType && (
<img
src={`data:${item.mimeType};base64,${item.data}`}
alt="Tool result"
className="max-w-full h-auto rounded-md"
onError={(e) => {
console.error('Failed to load image: Invalid MIME-type encoded image data');
e.currentTarget.style.display = 'none';
}}
/>
)}
</div>
))}
</div>
</Card>
)
);
}




// Utils

const convertArgsToMarkdown = (args: Record<string, any>): string => {
Expand Down
13 changes: 1 addition & 12 deletions ui/desktop/src/utils/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function extractUrls(content: string, previousUrls: string[] = []): strin
const normalizedPreviousUrls = previousUrls.map(normalizeUrl);
const normalizedCurrentUrls = currentUrls.map(url => {
const normalized = normalizeUrl(url);
console.log('Normalizing URL:', { original: url, normalized });
return normalized;
});

Expand All @@ -38,18 +37,8 @@ export function extractUrls(content: string, previousUrls: string[] = []): strin
const isDuplicate = normalizedPreviousUrls.some(prevUrl =>
normalizeUrl(prevUrl) === normalized
);
console.log('URL comparison:', {
url,
normalized,
previousUrls: normalizedPreviousUrls,
isDuplicate
});
return !isDuplicate;
});

console.log('Content:', content);
console.log('Found URLs:', uniqueUrls);
console.log('Previous URLs:', previousUrls);


return uniqueUrls;
}

0 comments on commit 7b638bf

Please sign in to comment.