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
  • Loading branch information
Alex Hancock committed Nov 26, 2024
1 parent 89da1fa commit dd1c660
Show file tree
Hide file tree
Showing 4 changed files with 42 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
77 changes: 41 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,50 @@ interface ToolResultProps {
}

function ToolResult({ result }: ToolResultProps) {
if (!result || !result.result) return null
if (!result || !result.result) return null;

return (
// Filter results to only show items where user is in the audience
const filteredResults = Array.isArray(result.result)
? result.result.filter((item: ResultItem) => item.audience?.includes('user'))
: result.result.audience?.includes('user') ? [result.result] : [];

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 dd1c660

Please sign in to comment.