Skip to content

Commit

Permalink
Show arguments in tool call response renderer
Browse files Browse the repository at this point in the history
fixed #14423

Signed-off-by: Jonas Helming <[email protected]>
  • Loading branch information
JonasHelming committed Nov 8, 2024
1 parent 6c76b44 commit 33cdef9
Showing 1 changed file with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ChatResponseContent, ToolCallChatResponseContent } from '@theia/ai-chat
import { ReactNode } from '@theia/core/shared/react';
import * as React from '@theia/core/shared/react';


@injectable()
export class ToolCallPartRenderer implements ChatResponsePartRenderer<ToolCallChatResponseContent> {

Expand All @@ -29,19 +30,49 @@ export class ToolCallPartRenderer implements ChatResponsePartRenderer<ToolCallCh
}
return -1;
}
render(response: ToolCallChatResponseContent): ReactNode {
return <h4 className='theia-toolCall'>
{response.finished ?
<details>
<summary>Ran {response.name}</summary>
<pre>{this.tryPrettyPrintJson(response)}</pre>

renderCollapsibleArguments(args: any): ReactNode {
return (
args && (
<details style={{ display: 'inline' }}>
<summary
style={{
display: 'inline',
cursor: 'pointer',
textDecoration: 'underline',
}}>
&gt;
</summary>
<span>{JSON.stringify(args, null, 2)}</span>
</details>
: <span><Spinner /> Running [{response.name}]</span>
}
</h4>;
)
);
}

render(response: ToolCallChatResponseContent): ReactNode {
return (
<h4 className='theia-toolCall'>
{response.finished ? (
<details>
<summary>Ran [{response.name}
{response.arguments && <>({this.renderCollapsibleArguments(response.arguments)})</>}
]</summary>
<pre>{this.tryPrettyPrintJson(response)}</pre>
{this.renderCollapsibleArguments(response.arguments)}
</details>
) : (
<span>
<Spinner /> Running [{response.name}
{response.arguments && <>({this.renderCollapsibleArguments(response.arguments)})</>}
]
</span>
)}
</h4>
);
}



private tryPrettyPrintJson(response: ToolCallChatResponseContent): string | undefined {
let responseContent = response.result;
try {
Expand Down

0 comments on commit 33cdef9

Please sign in to comment.