-
Notifications
You must be signed in to change notification settings - Fork 12k
feat(server): Add tool call support to WebUI (LLama Server) #13501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 18 commits
acd4767
6236918
e84e819
f6b1386
f2175cb
4698b66
69e7119
75fd25e
ae32a9a
00d911d
d99808f
0b34d53
0480054
7fa0043
b128ca5
c203815
cf110f9
4e7da1b
031e673
c9ec6fa
3f76cac
c98baef
22a951b
798946e
92f8bb0
5c898ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import daisyuiThemes from 'daisyui/theme/object'; | ||
import { isNumeric } from './utils/misc'; | ||
import { AVAILABLE_TOOLS } from './utils/tool_calling/register_tools'; | ||
import { AgentTool } from './utils/tool_calling/agent_tool'; | ||
|
||
export const isDev = import.meta.env.MODE === 'development'; | ||
|
||
|
@@ -41,6 +43,14 @@ export const CONFIG_DEFAULT = { | |
custom: '', // custom json-stringified object | ||
// experimental features | ||
pyIntepreterEnabled: false, | ||
// Fields for tool calling | ||
streamResponse: true, | ||
...Object.fromEntries( | ||
Array.from(AVAILABLE_TOOLS.values()).map((tool: AgentTool) => [ | ||
`tool_${tool.id}_enabled`, | ||
false, // Default value for tool enabled state (e.g., false for opt-in) | ||
]) | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be kept simple for now, by simply listing the list of tools here (we don't have many, right?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, sure can, but I think we will need to readd it in the future? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're saying that we will have user-provided tool, then I think this is not the correct approach. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok! |
||
}; | ||
export const CONFIG_INFO: Record<string, string> = { | ||
apiKey: 'Set the API Key if you are using --api-key option for the server.', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<!doctype html> | ||
ngxson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<html> | ||
<head> | ||
<title>JS Sandbox</title> | ||
<script> | ||
// Capture console.log output within the iframe | ||
const iframeConsole = { | ||
_buffer: [], | ||
log: function (...args) { | ||
this._buffer.push(args.map(String).join(' ')); | ||
}, | ||
getOutput: function () { | ||
const output = this._buffer.join('\n'); | ||
this._buffer = []; | ||
return output; | ||
}, | ||
clear: function () { | ||
this._buffer = []; | ||
}, | ||
}; | ||
// Redirect the iframe's console.log | ||
console.log = iframeConsole.log.bind(iframeConsole); | ||
|
||
window.addEventListener('message', (event) => { | ||
if (!event.data || !event.source || !event.source.postMessage) { | ||
return; | ||
} | ||
|
||
if (event.data.command === 'executeCode') { | ||
const { code, call_id } = event.data; | ||
let result = ''; | ||
let error = null; | ||
iframeConsole.clear(); | ||
|
||
try { | ||
result = eval(code); | ||
if (result !== undefined && result !== null) { | ||
try { | ||
result = JSON.stringify(result, null, 2); | ||
} catch (e) { | ||
result = String(result); | ||
} | ||
} else { | ||
result = ''; | ||
} | ||
} catch (e) { | ||
error = e.message || String(e); | ||
} | ||
|
||
const consoleOutput = iframeConsole.getOutput(); | ||
const finalOutput = consoleOutput | ||
? consoleOutput + (result && consoleOutput ? '\n' : '') + result | ||
: result; | ||
|
||
event.source.postMessage( | ||
{ | ||
call_id: call_id, | ||
output: finalOutput, | ||
error: error, | ||
}, | ||
event.origin === 'null' ? '*' : event.origin | ||
); | ||
} | ||
}); | ||
|
||
if (window.parent && window.parent !== window) { | ||
window.parent.postMessage( | ||
{ command: 'iframeReady', call_id: 'initial_ready' }, | ||
'*' | ||
); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<p>JavaScript Execution Sandbox</p> | ||
</body> | ||
</html> |
Uh oh!
There was an error while loading. Please reload this page.