-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Draft
samolego
wants to merge
9
commits into
ggml-org:master
Choose a base branch
from
samolego:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
acd4767
feat(server): add basic js tool call support
samolego 6236918
code abstraction for tool calling
samolego e84e819
minor changes, renames
samolego f6b1386
add tool call fields
samolego f2175cb
fix: Use structured `tool_calls` for tool handling
samolego 4698b66
fix: forward tool call info back to api
samolego 69e7119
provide tool call response in a dropdown
samolego 75fd25e
Fix UI updates after tool call chains
samolego ae32a9a
move js evaluation to sandboxed iframe, remove debug logs
samolego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!doctype html> | ||
<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 | ||
const originalConsoleLog = console.log; // Keep a reference if needed | ||
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you meant to commit this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not intended. Thanks