Skip to content

Commit 92f8bb0

Browse files
committed
updates to config and available tools map
1 parent 798946e commit 92f8bb0

File tree

8 files changed

+40
-39
lines changed

8 files changed

+40
-39
lines changed

tools/server/webui/src/Config.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import daisyuiThemes from 'daisyui/theme/object';
22
import { isNumeric } from './utils/misc';
3-
import { AVAILABLE_TOOLS } from './utils/tool_calling/register_tools';
4-
import { AgentTool } from './utils/tool_calling/agent_tool';
53

64
export const isDev = import.meta.env.MODE === 'development';
75

@@ -43,13 +41,7 @@ export const CONFIG_DEFAULT = {
4341
custom: '', // custom json-stringified object
4442
// experimental features
4543
pyIntepreterEnabled: false,
46-
// Fields for tool calling
47-
...Object.fromEntries(
48-
Array.from(AVAILABLE_TOOLS.values()).map((tool: AgentTool) => [
49-
`tool_${tool.id}_enabled`,
50-
false,
51-
])
52-
),
44+
toolJsReplEnabled: false,
5345
};
5446
export const CONFIG_INFO: Record<string, string> = {
5547
apiKey: 'Set the API Key if you are using --api-key option for the server.',

tools/server/webui/src/components/SettingDialog.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import {
1414
WrenchScrewdriverIcon,
1515
} from '@heroicons/react/24/outline';
1616
import { OpenInNewTab } from '../utils/common';
17-
import { AVAILABLE_TOOLS } from '../utils/tool_calling/register_tools';
18-
import { AgentTool } from '../utils/tool_calling/agent_tool';
1917

2018
type SettKey = keyof typeof CONFIG_DEFAULT;
2119

@@ -180,24 +178,21 @@ const SETTING_SECTIONS: SettingSection[] = [
180178
</>
181179
),
182180
fields: [
183-
...Array.from(AVAILABLE_TOOLS.values()).map(
184-
(tool: AgentTool) =>
185-
({
186-
type: SettingInputType.CHECKBOX,
187-
label: (
188-
<>
189-
<span className="font-semibold">{tool.name || tool.id}</span>
190-
{tool.toolDescription && (
191-
<small className="text-xs block mt-1 opacity-70">
192-
<strong>Agent tool description: </strong>
193-
{tool.toolDescription}
194-
</small>
195-
)}
196-
</>
197-
),
198-
key: `tool_${tool.id}_enabled` as SettKey,
199-
}) as SettingFieldInput
200-
),
181+
{
182+
type: SettingInputType.CHECKBOX,
183+
label: (
184+
<>
185+
<span className="font-semibold">JavaScript Interpreter</span>
186+
<small className="text-xs block mt-1 opacity-70">
187+
<strong>Agent tool description: </strong>
188+
Executes JavaScript code in a sandboxed iframe. The code should be
189+
self-contained valid javascript. Only console.log(variable) and
190+
final result are included in response content.
191+
</small>
192+
</>
193+
),
194+
key: 'toolJsReplEnabled',
195+
},
201196
],
202197
},
203198
{
@@ -559,13 +554,11 @@ function SettingsModalCheckbox({
559554
value,
560555
onChange,
561556
label,
562-
disabled,
563557
}: {
564558
configKey: SettKey;
565559
value: boolean;
566560
onChange: (value: boolean) => void;
567-
label: React.ReactElement | string;
568-
disabled?: boolean;
561+
label: string;
569562
}) {
570563
return (
571564
<div className="flex flex-row items-center mb-2">
@@ -574,7 +567,6 @@ function SettingsModalCheckbox({
574567
className="toggle"
575568
checked={value}
576569
onChange={(e) => onChange(e.target.checked)}
577-
disabled={disabled}
578570
/>
579571
<span className="ml-4">{label || configKey}</span>
580572
</div>

tools/server/webui/src/components/tool_calling/ToolCallArgsDisplay.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@ export const ToolCallArgsDisplay = ({
77
toolCall: ToolCallRequest;
88
baseClassName?: string;
99
}) => {
10+
let parsedArgs = toolCall.function.arguments;
11+
try {
12+
parsedArgs = JSON.stringify(JSON.parse(parsedArgs), null, 2);
13+
} catch (e) {
14+
// Might still be generating
15+
}
1016
return (
1117
<details className={baseClassName} open={false}>
1218
<summary className="collapse-title">
1319
<b>Tool call:</b> {toolCall.function.name}
1420
</summary>
1521
<div className="collapse-content">
16-
<div className="font-bold mb-1">Arguments:</div>
22+
<div className="mb-1">Arguments:</div>
1723
<pre className="whitespace-pre-wrap bg-base-300 p-2 rounded">
18-
{toolCall.function.arguments}
24+
{parsedArgs}
1925
</pre>
2026
</div>
2127
</details>

tools/server/webui/src/utils/app.context.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { createContext, useContext, useEffect, useState } from 'react';
22
import {
33
APIMessage,
4+
AvailableToolId,
45
CanvasData,
56
Conversation,
67
LlamaCppServerProps,
@@ -312,7 +313,7 @@ export const AppContextProvider = ({
312313

313314
// Process tool call
314315
const toolResult = await AVAILABLE_TOOLS.get(
315-
toolCall.function.name
316+
toolCall.function.name as AvailableToolId
316317
)?.processCall(toolCall);
317318

318319
const toolMsg: PendingMessage = {

tools/server/webui/src/utils/tool_calling/agent_tool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import {
33
ToolCallOutput,
44
ToolCallParameters,
55
ToolCallSpec,
6+
AvailableToolId,
67
} from '../types';
78

89
export abstract class AgentTool {
910
constructor(
10-
public readonly id: string,
11+
public readonly id: AvailableToolId,
1112
public readonly name: string,
1213
public readonly toolDescription: string,
1314
public readonly parameters: ToolCallParameters,

tools/server/webui/src/utils/tool_calling/js_repl_tool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AgentTool } from './agent_tool';
33

44
// Import the HTML content as a raw string
55
import iframeHTMLContent from '../../assets/iframe_sandbox.html?raw';
6+
import StorageUtils from '../storage';
67

78
interface IframeMessage {
89
call_id: string;
@@ -39,7 +40,7 @@ export class JSReplAgentTool extends AgentTool {
3940
},
4041
required: ['code'],
4142
} as ToolCallParameters,
42-
() => true
43+
() => StorageUtils.getConfig().toolJsReplEnabled
4344
);
4445
this.initIframe();
4546
}

tools/server/webui/src/utils/tool_calling/register_tools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { AvailableToolId } from '../types';
12
import { AgentTool } from './agent_tool';
23
import { JSReplAgentTool } from './js_repl_tool';
34

45
/**
56
* Map of available tools for function calling.
67
* Note that these tools are not necessarily enabled by the user.
78
*/
8-
export const AVAILABLE_TOOLS = new Map<string, AgentTool>();
9+
export const AVAILABLE_TOOLS = new Map<AvailableToolId, AgentTool>();
910

1011
function registerTool<T extends AgentTool>(tool: T): T {
1112
AVAILABLE_TOOLS.set(tool.id, tool);

tools/server/webui/src/utils/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export interface CanvasPyInterpreter {
115115

116116
export type CanvasData = CanvasPyInterpreter;
117117

118+
// The request for a tool call, which is received from the model.
118119
export interface ToolCallRequest {
119120
id: string;
120121
type: 'function';
@@ -125,6 +126,7 @@ export interface ToolCallRequest {
125126
};
126127
}
127128

129+
// The specification of a tool call, which is sent to the model.
128130
export interface ToolCallSpec {
129131
type: 'function';
130132
function: {
@@ -134,18 +136,23 @@ export interface ToolCallSpec {
134136
};
135137
}
136138

139+
// The parameters for a tool call, which defines the structure of the arguments.
137140
export interface ToolCallParameters {
138141
type: 'object';
139142
properties: object;
140143
required: string[];
141144
}
142145

146+
// The output of a tool call, which is returned to the model.
143147
export interface ToolCallOutput {
144148
type: 'function_call_output';
145149
call_id: string;
146150
output: string;
147151
}
148152

153+
// A list of available builtin tool IDs.
154+
export type AvailableToolId = 'javascript_interpreter';
155+
149156
// a non-complete list of props, only contains the ones we need
150157
export interface LlamaCppServerProps {
151158
build_info: string;

0 commit comments

Comments
 (0)