Skip to content

Commit d99808f

Browse files
committed
feat: populate settings tool calling section
1 parent 00d911d commit d99808f

File tree

6 files changed

+50
-30
lines changed

6 files changed

+50
-30
lines changed

tools/server/webui/src/Config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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';
35

46
export const isDev = import.meta.env.MODE === 'development';
57

@@ -37,7 +39,11 @@ export const CONFIG_DEFAULT = {
3739
custom: '', // custom json-stringified object
3840
// experimental features
3941
pyIntepreterEnabled: false,
40-
jsInterpreterToolUse: false,
42+
// Fields for tool calling
43+
streamResponse: true,
44+
...Array.from(AVAILABLE_TOOLS.values()).map((tool: AgentTool) => {
45+
return `tool_${tool.id}_enabled`;
46+
}),
4147
};
4248
export const CONFIG_INFO: Record<string, string> = {
4349
apiKey: 'Set the API Key if you are using --api-key option for the server.',

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

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import {
1111
FunnelIcon,
1212
HandRaisedIcon,
1313
SquaresPlusIcon,
14+
WrenchScrewdriverIcon,
1415
} from '@heroicons/react/24/outline';
1516
import { OpenInNewTab } from '../utils/common';
17+
import { AVAILABLE_TOOLS } from '../utils/tool_calling/register_tools';
18+
import { AgentTool } from '../utils/tool_calling/agent_tool';
1619

1720
type SettKey = keyof typeof CONFIG_DEFAULT;
1821

@@ -159,6 +162,40 @@ const SETTING_SECTIONS: SettingSection[] = [
159162
},
160163
],
161164
},
165+
{
166+
title: (
167+
<>
168+
<WrenchScrewdriverIcon className={ICON_CLASSNAME} />
169+
Tool Calling
170+
</>
171+
),
172+
fields: [
173+
{
174+
type: SettingInputType.CHECKBOX,
175+
label: 'Enable response streaming',
176+
key: 'streamResponse',
177+
},
178+
// Fields will be dynamically generated based on AVAILABLE_TOOLS
179+
...Array.from(AVAILABLE_TOOLS.values()).map(
180+
(tool: AgentTool) =>
181+
({
182+
type: SettingInputType.CHECKBOX,
183+
label: (
184+
<>
185+
<span className="font-semibold">{tool.name || tool.id}</span>
186+
{tool.toolDescription && (
187+
<small className="text-xs block mt-1 opacity-70">
188+
<strong>Agent tool description: </strong>
189+
{tool.toolDescription}
190+
</small>
191+
)}
192+
</>
193+
),
194+
key: `tool_${tool.id}_enabled` as SettKey,
195+
}) as SettingFieldInput
196+
),
197+
],
198+
},
162199
{
163200
title: (
164201
<>
@@ -254,21 +291,6 @@ const SETTING_SECTIONS: SettingSection[] = [
254291
),
255292
key: 'pyIntepreterEnabled',
256293
},
257-
{
258-
type: SettingInputType.CHECKBOX,
259-
label: (
260-
<>
261-
<b>Enable JavaScript tool use</b>
262-
<br />
263-
<small className="text-xs">
264-
This alows LLM to use browser your browser console as tool. If
265-
model supports function calling, it can use the console to do e.g.
266-
data analysis etc. by itself.
267-
</small>
268-
</>
269-
),
270-
key: 'jsInterpreterToolUse',
271-
},
272294
],
273295
},
274296
];

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,10 @@ export const AppContextProvider = ({
191191
.filter((tool) => tool.enabled)
192192
.map((tool) => tool.specs);
193193

194-
// stream does not support tool-use (yet?)
195-
const streamResponse = enabledTools.length === 0;
196-
197194
// prepare params
198195
const params = {
199196
messages,
200-
stream: streamResponse,
197+
stream: config.streamResponse,
201198
cache_prompt: true,
202199
samplers: config.samplers,
203200
temperature: config.temperature,
@@ -246,7 +243,7 @@ export const AppContextProvider = ({
246243
let lastMsgId = pendingMsg.id;
247244
let shouldContinueChain = false;
248245

249-
if (streamResponse) {
246+
if (params.stream) {
250247
const chunks = getSSEStreamAsync(fetchResponse);
251248
for await (const chunk of chunks) {
252249
// const stop = chunk.stop;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import StorageUtils from '../storage';
12
import {
23
ToolCallRequest,
34
ToolCallOutput,
@@ -8,7 +9,7 @@ import {
89
export abstract class AgentTool {
910
constructor(
1011
public readonly id: string,
11-
private readonly isEnabledCallback: () => boolean,
12+
public readonly name: string,
1213
public readonly toolDescription: string,
1314
public readonly parameters: ToolCallParameters
1415
) {}
@@ -42,7 +43,7 @@ export abstract class AgentTool {
4243
* @returns enabled status.
4344
*/
4445
public get enabled(): boolean {
45-
return this.isEnabledCallback();
46+
return StorageUtils.getConfig()[`tool_${this.id}_enabled`] ?? false;
4647
}
4748

4849
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class JSReplAgentTool extends AgentTool {
2828
constructor() {
2929
super(
3030
JSReplAgentTool.ID,
31-
() => StorageUtils.getConfig().jsInterpreterToolUse,
31+
'Javascript interpreter',
3232
'Executes JavaScript code in a sandboxed iframe. The code should be self-contained valid javascript. You can use console.log(variable) to print out intermediate values, which will be captured.',
3333
{
3434
type: 'object',

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isDev } from '../../Config';
21
import { AgentTool } from './agent_tool';
32
import { JSReplAgentTool } from './js_repl_tool';
43

@@ -10,11 +9,6 @@ export const AVAILABLE_TOOLS = new Map<string, AgentTool>();
109

1110
function registerTool<T extends AgentTool>(tool: T): T {
1211
AVAILABLE_TOOLS.set(tool.id, tool);
13-
if (isDev) {
14-
console.log(
15-
`Successfully registered tool: ${tool.id}, enabled: ${tool.enabled}`
16-
);
17-
}
1812
return tool;
1913
}
2014

0 commit comments

Comments
 (0)