Skip to content
Draft
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
10 changes: 7 additions & 3 deletions frontend/src/components/message-box.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class MessageBox extends LitElement {
<h2 class="govuk-visually-hidden">AI:</h2>

${this.toolCalls.map((tool, toolIndex) => html`
<tool-info name=${tool.name} server=${tool.server} entries=${JSON.stringify(tool.args)} in-use=${toolIndex + 1 < this.toolCalls.length || this.content.length ? 'false' : 'true'} ref=${this.messageIndex + '-' + toolIndex}></tool-info>
<tool-info name=${tool.name} server=${tool.server} parameters=${JSON.stringify(tool.args)} response=${tool.response} in-use=${toolIndex + 1 < this.toolCalls.length || this.content.length ? 'false' : 'true'} ref=${this.messageIndex + '-' + toolIndex}></tool-info>
`)}

${this.content ? html`
Expand Down Expand Up @@ -125,7 +125,7 @@ export class MessageBox extends LitElement {

// parse response data
/**
* @type { {type?: 'tool' | 'content' | 'end', data?: any} }
* @type { {type?: 'tool' | 'tool-response' | 'content' | 'end', data?: any} }
*/
let response = {};
try {
Expand All @@ -135,10 +135,14 @@ export class MessageBox extends LitElement {
return;
}

// It's a tool
// It's a tool call
if (response.type === 'tool') {
this.toolCalls = [...this.toolCalls, response.data[0]];

// It's a tool response
} else if (response.type === 'tool-response') {
this.toolCalls[this.toolCalls.length - 1].response = response.data;

// It's the text response
} else if (response.type === 'content') {
this.content += response.data;
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/components/tool-info.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const ToolInfo = class extends LitElement {
static properties = {
name: { type: String, attribute: 'name' },
server: { type: String, attribute: 'server' },
entries: { type: Object, attribute: 'entries' },
parameters: { type: Object, attribute: 'parameters' },
response: { type: String, attribute: 'response' },
ref: { type: String, attribute: 'ref' },
inUse: { type: String, attribute: 'in-use' },
};
Expand All @@ -35,6 +36,7 @@ const ToolInfo = class extends LitElement {
</span>
</button>
<div class="tool-info__expandable" id="tool-${this.ref}">
<h3 class="govuk-body-xs govuk-!-font-weight-bold">Parameters</h3>
<table class="govuk-!-margin-top-2">
<thead class="govuk-visually-hidden">
<tr>
Expand All @@ -43,8 +45,8 @@ const ToolInfo = class extends LitElement {
</tr>
</thead>
<tbody>
${this.entries ? html`
${Object.entries(this.entries).map(([key, value]) => html`
${this.parameters ? html`
${Object.entries(this.parameters).map(([key, value]) => html`
<tr>
<td class="govuk-body-xs govuk-!-padding-top-2 govuk-!-padding-bottom-2">${key}:</td>
<td class="govuk-body-xs govuk-!-padding-top-2 govuk-!-padding-bottom-2">${typeof value === 'string' ? value : JSON.stringify(value)}</td>
Expand All @@ -53,6 +55,8 @@ const ToolInfo = class extends LitElement {
` : ''}
</tbody>
</table>
<h3 class="govuk-body-xs govuk-!-font-weight-bold">Response</h3>
<p class="govuk-body-xs">${this.response}</p>
</div>
`;
}
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/logic/ai3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ export const getLlmResponse = async(messages: Message[], selectedServers: FormDa
}), sessionToken);
}
}

// Tool response
if (chunk.tools?.messages) {
toolCalls[toolCalls.length - 1].response = chunk.tools.messages[0].content;
sendMessage(JSON.stringify({
type: 'tool-response',
data: chunk.tools.messages[0].content,
}), sessionToken);
}

}

return {
Expand Down