Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
1611a3aa
Commit
1611a3aa
authored
Jun 10, 2024
by
Timothy J. Baek
Browse files
feat: export tools
parent
b434ebf3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
5 deletions
+43
-5
backend/apps/webui/routers/tools.py
backend/apps/webui/routers/tools.py
+1
-1
src/lib/apis/tools/index.ts
src/lib/apis/tools/index.ts
+31
-0
src/lib/components/workspace/Tools.svelte
src/lib/components/workspace/Tools.svelte
+11
-4
No files found.
backend/apps/webui/routers/tools.py
View file @
1611a3aa
...
...
@@ -62,7 +62,7 @@ async def get_toolkits(user=Depends(get_current_user)):
@
router
.
get
(
"/export"
,
response_model
=
List
[
ToolModel
])
async
def
get_toolkits
(
user
=
Depends
(
get_
current
_user
)):
async
def
get_toolkits
(
user
=
Depends
(
get_
admin
_user
)):
toolkits
=
[
toolkit
for
toolkit
in
Tools
.
get_tools
()]
return
toolkits
...
...
src/lib/apis/tools/index.ts
View file @
1611a3aa
...
...
@@ -62,6 +62,37 @@ export const getTools = async (token: string = '') => {
return
res
;
};
export
const
exportTools
=
async
(
token
:
string
=
''
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/tools/export`
,
{
method
:
'
GET
'
,
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
authorization
:
`Bearer
${
token
}
`
}
})
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
})
.
then
((
json
)
=>
{
return
json
;
})
.
catch
((
err
)
=>
{
error
=
err
.
detail
;
console
.
log
(
err
);
return
null
;
});
if
(
error
)
{
throw
error
;
}
return
res
;
};
export
const
getToolById
=
async
(
token
:
string
,
id
:
string
)
=>
{
let
error
=
null
;
...
...
src/lib/components/workspace/Tools.svelte
View file @
1611a3aa
...
...
@@ -8,7 +8,7 @@
import { createNewPrompt, deletePromptByCommand, getPrompts } from '$lib/apis/prompts';
import { goto } from '$app/navigation';
import { deleteToolById, getTools } from '$lib/apis/tools';
import { deleteToolById,
exportTools,
getTools } from '$lib/apis/tools';
const i18n = getContext('i18n');
...
...
@@ -221,10 +221,17 @@
<button
class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
on:click={async () => {
let blob = new Blob([JSON.stringify($tools)], {
type: 'application/json'
const _tools = await exportTools(localStorage.token).catch((error) => {
toast.error(error);
return null;
});
saveAs(blob, `tools-export-${Date.now()}.json`);
if (_tools) {
let blob = new Blob([JSON.stringify(_tools)], {
type: 'application/json'
});
saveAs(blob, `tools-export-${Date.now()}.json`);
}
}}
>
<div class=" self-center mr-2 font-medium">{$i18n.t('Export Tools')}</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment