Skip to content

Commit e84e819

Browse files
committed
minor changes, renames
1 parent 6236918 commit e84e819

File tree

7 files changed

+75
-53
lines changed

7 files changed

+75
-53
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export default function ChatMessage({
8181

8282
// Process <tool> tags (after thoughts are processed)
8383
const toolParts = currentContent.split('<tool>');
84-
console.log(toolParts);
8584
currentContent = toolParts[0];
8685
if (toolParts.length > 1) {
8786
const tempToolOutputArray: string[] = [];

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from './misc';
1717
import { BASE_URL, CONFIG_DEFAULT, isDev } from '../Config';
1818
import { matchPath, useLocation, useNavigate } from 'react-router';
19-
import { AVAILABLE_TOOLS } from './tool_calling/available_tools';
19+
import { AVAILABLE_TOOLS } from './tool_calling/register_tools';
2020

2121
interface AppContextValue {
2222
// conversations and messages
@@ -212,9 +212,9 @@ export const AppContextProvider = ({
212212
max_tokens: config.max_tokens,
213213
timings_per_token: !!config.showTokensPerSecond,
214214
tools: config.jsInterpreterToolUse
215-
? Array.from(AVAILABLE_TOOLS, ([_name, tool], _index) => tool).filter(
216-
(tool) => tool.enabled()
217-
)
215+
? Array.from(AVAILABLE_TOOLS, ([_name, tool], _index) => tool)
216+
.filter((tool) => tool.enabled())
217+
.map((tool) => tool.specs())
218218
: undefined,
219219
...(config.custom.length ? JSON.parse(config.custom) : {}),
220220
};

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export async function* getSSEStreamAsync(fetchResponse: Response) {
2222
.pipeThrough(new TextLineStream());
2323
// @ts-expect-error asyncIterator complains about type, but it should work
2424
for await (const line of asyncIterator(lines)) {
25-
//if (isDev) console.log({ line });
2625
if (line.startsWith('data:') && !line.endsWith('[DONE]')) {
2726
const data = JSON.parse(line.slice(5));
2827
yield data;

tools/server/webui/src/utils/tool_calling/available_tools.ts renamed to tools/server/webui/src/utils/tool_calling/agent_tool.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
import { ToolCall, ToolCallOutput, ToolCallSpec } from '../types';
2-
3-
/**
4-
* Map of available tools for function calling.
5-
* Note that these tools are not necessarily enabled by the user.
6-
*/
7-
export const AVAILABLE_TOOLS = new Map<string, AgentTool>();
1+
import {
2+
ToolCall,
3+
ToolCallOutput,
4+
ToolCallParameters,
5+
ToolCallSpec,
6+
} from '../types';
87

98
export abstract class AgentTool {
109
id: string;
1110
isEnabled: () => boolean;
11+
toolDescription: string;
12+
parameters: ToolCallParameters;
1213

13-
constructor(id: string, enabled: () => boolean) {
14+
constructor(
15+
id: string,
16+
enabled: () => boolean,
17+
toolDescription: string,
18+
parameters: ToolCallParameters
19+
) {
1420
this.id = id;
1521
this.isEnabled = enabled;
16-
AVAILABLE_TOOLS.set(id, this);
22+
this.toolDescription = toolDescription;
23+
this.parameters = parameters;
1724
}
1825

1926
/**
@@ -43,7 +50,16 @@ export abstract class AgentTool {
4350
* https://github.com/ggml-org/llama.cpp/blob/master/docs/function-calling.md
4451
* https://platform.openai.com/docs/guides/function-calling?api-mode=responses#defining-functions
4552
*/
46-
public abstract specs(): ToolCallSpec;
53+
public specs(): ToolCallSpec {
54+
return {
55+
type: 'function',
56+
function: {
57+
name: this.id,
58+
description: this.toolDescription,
59+
parameters: this.parameters,
60+
},
61+
};
62+
}
4763

4864
/**
4965
* The actual tool call processing logic.

tools/server/webui/src/utils/tool_calling/js_tool_call.ts renamed to tools/server/webui/src/utils/tool_calling/js_repl_tool.ts

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
import StorageUtils from '../storage';
2-
import { ToolCall, ToolCallOutput, ToolCallSpec } from '../types';
3-
import { AgentTool } from './available_tools';
2+
import { ToolCall, ToolCallOutput, ToolCallParameters } from '../types';
3+
import { AgentTool } from './agent_tool';
44

5-
class JSReplAgentTool extends AgentTool {
5+
export class JSReplAgentTool extends AgentTool {
66
private static readonly id = 'javascript_interpreter';
77
private fakeLogger: FakeConsoleLog;
88

99
constructor() {
1010
super(
1111
JSReplAgentTool.id,
12-
() => StorageUtils.getConfig().jsInterpreterToolUse
12+
() => StorageUtils.getConfig().jsInterpreterToolUse,
13+
'Executes JavaScript code in the browser console. The code should be self-contained valid javascript. You can use console.log(variable) to print out intermediate values..',
14+
{
15+
type: 'object',
16+
properties: {
17+
code: {
18+
type: 'string',
19+
description: 'Valid JavaScript code to execute.',
20+
},
21+
},
22+
required: ['code'],
23+
} as ToolCallParameters
1324
);
1425
this.fakeLogger = new FakeConsoleLog();
1526
}
1627

1728
_process(tc: ToolCall): ToolCallOutput {
1829
const args = JSON.parse(tc.function.arguments);
19-
console.log('Arguments for tool call:');
20-
console.log(args);
2130

2231
// Redirect console.log which agent will use to
2332
// the fake logger so that later we can get the content
@@ -30,40 +39,16 @@ class JSReplAgentTool extends AgentTool {
3039
result = eval(args.code);
3140
} catch (err) {
3241
result = String(err);
33-
} finally {
34-
// Ensure original console.log is restored even if eval throws
35-
console.log = originalConsoleLog;
3642
}
3743

44+
console.log = originalConsoleLog;
3845
result = this.fakeLogger.content + result;
3946

4047
this.fakeLogger.clear();
4148

4249
return { call_id: tc.call_id, output: result } as ToolCallOutput;
4350
}
44-
45-
public specs(): ToolCallSpec {
46-
return {
47-
type: 'function',
48-
function: {
49-
name: this.id,
50-
description:
51-
'Executes JavaScript code in the browser console. The code should be self-contained valid javascript. You can use console.log(variable) to print out intermediate values..',
52-
parameters: {
53-
type: 'object',
54-
properties: {
55-
code: {
56-
type: 'string',
57-
description: 'Valid JavaScript code to execute.',
58-
},
59-
},
60-
required: ['code'],
61-
},
62-
},
63-
};
64-
}
6551
}
66-
export const jsAgentTool = new JSReplAgentTool();
6752

6853
class FakeConsoleLog {
6954
private _content: string = '';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { isDev } from '../../Config';
2+
import { AgentTool } from './agent_tool';
3+
import { JSReplAgentTool } from './js_repl_tool';
4+
5+
/**
6+
* Map of available tools for function calling.
7+
* Note that these tools are not necessarily enabled by the user.
8+
*/
9+
export const AVAILABLE_TOOLS = new Map<string, AgentTool>();
10+
11+
function registerTool(tool: AgentTool): AgentTool {
12+
AVAILABLE_TOOLS.set(tool.id, tool);
13+
if (isDev)
14+
console.log(
15+
`Successfully registered tool: ${tool.id}, enabled: ${tool.isEnabled()}`
16+
);
17+
return tool;
18+
}
19+
20+
// Available agent tools
21+
export const jsReplTool = registerTool(new JSReplAgentTool());

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface Message {
3939
convId: string;
4040
type: 'text' | 'root';
4141
timestamp: number; // timestamp from Date.now()
42-
role: 'user' | 'assistant' | 'system';
42+
role: 'user' | 'assistant' | 'system' | 'tool';
4343
content: string;
4444
timings?: TimingReport;
4545
extra?: MessageExtra[];
@@ -105,14 +105,16 @@ export interface ToolCallSpec {
105105
function: {
106106
name: string;
107107
description: string;
108-
parameters: {
109-
type: 'object';
110-
properties: object;
111-
required: string[];
112-
};
108+
parameters: ToolCallParameters;
113109
};
114110
}
115111

112+
export interface ToolCallParameters {
113+
type: 'object';
114+
properties: object;
115+
required: string[];
116+
}
117+
116118
export interface ToolCallOutput {
117119
type: 'function_call_output';
118120
call_id: string;

0 commit comments

Comments
 (0)