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
e6fe3ada
Unverified
Commit
e6fe3ada
authored
Jun 11, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Jun 11, 2024
Browse files
Merge pull request #3006 from open-webui/tools
feat: tools
parents
d2ed99e2
35468329
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
19 deletions
+121
-19
src/routes/(app)/+layout.svelte
src/routes/(app)/+layout.svelte
+11
-17
src/routes/(app)/workspace/tools/create/+page.svelte
src/routes/(app)/workspace/tools/create/+page.svelte
+48
-1
src/routes/(app)/workspace/tools/edit/+page.svelte
src/routes/(app)/workspace/tools/edit/+page.svelte
+62
-1
No files found.
src/routes/(app)/+layout.svelte
View file @
e6fe3ada
...
@@ -8,11 +8,14 @@
...
@@ -8,11 +8,14 @@
import { goto } from '$app/navigation';
import { goto } from '$app/navigation';
import { getModels as _getModels } from '$lib/apis';
import { getModels as _getModels } from '$lib/apis';
import { getOllamaVersion } from '$lib/apis/ollama';
import { getAllChatTags } from '$lib/apis/chats';
import { getPrompts } from '$lib/apis/prompts';
import { getPrompts } from '$lib/apis/prompts';
import { getDocs } from '$lib/apis/documents';
import { getDocs } from '$lib/apis/documents';
import { getAllChatTags } from '$lib/apis/chats';
import { getTools } from '$lib/apis/tools';
import { getBanners } from '$lib/apis/configs';
import { getUserSettings } from '$lib/apis/users';
import {
import {
user,
user,
...
@@ -25,33 +28,21 @@
...
@@ -25,33 +28,21 @@
banners,
banners,
showChangelog,
showChangelog,
config,
config,
showCallOverlay
showCallOverlay,
tools
} from '$lib/stores';
} from '$lib/stores';
import { REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import { compareVersion } from '$lib/utils';
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
import Sidebar from '$lib/components/layout/Sidebar.svelte';
import Sidebar from '$lib/components/layout/Sidebar.svelte';
import ShortcutsModal from '$lib/components/chat/ShortcutsModal.svelte';
import ChangelogModal from '$lib/components/ChangelogModal.svelte';
import ChangelogModal from '$lib/components/ChangelogModal.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import { getBanners } from '$lib/apis/configs';
import { getUserSettings } from '$lib/apis/users';
import Help from '$lib/components/layout/Help.svelte';
import AccountPending from '$lib/components/layout/Overlay/AccountPending.svelte';
import AccountPending from '$lib/components/layout/Overlay/AccountPending.svelte';
import { error } from '@sveltejs/kit';
import CallOverlay from '$lib/components/chat/MessageInput/CallOverlay.svelte';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
let ollamaVersion = '';
let loaded = false;
let loaded = false;
let showShortcutsButtonElement: HTMLButtonElement;
let DB = null;
let DB = null;
let localDBChats = [];
let localDBChats = [];
let showShortcuts = false;
const getModels = async () => {
const getModels = async () => {
return _getModels(localStorage.token);
return _getModels(localStorage.token);
};
};
...
@@ -99,6 +90,9 @@
...
@@ -99,6 +90,9 @@
(async () => {
(async () => {
documents.set(await getDocs(localStorage.token));
documents.set(await getDocs(localStorage.token));
})(),
})(),
(async () => {
tools.set(await getTools(localStorage.token));
})(),
(async () => {
(async () => {
banners.set(await getBanners(localStorage.token));
banners.set(await getBanners(localStorage.token));
})(),
})(),
...
...
src/routes/(app)/workspace/tools/create/+page.svelte
View file @
e6fe3ada
<script>
<script>
import { goto } from '$app/navigation';
import { createNewTool, getTools } from '$lib/apis/tools';
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
import { tools } from '$lib/stores';
import { onMount } from 'svelte';
import { toast } from 'svelte-sonner';
let clone = false;
let tool = null;
const saveHandler = async (data) => {
console.log(data);
const res = await createNewTool(localStorage.token, {
id: data.id,
name: data.name,
meta: data.meta,
content: data.content
}).catch((error) => {
toast.error(error);
return null;
});
if (res) {
toast.success('Tool created successfully');
tools.set(await getTools(localStorage.token));
await goto('/workspace/tools');
}
};
onMount(() => {
console.log('mounted');
if (sessionStorage.tool) {
tool = JSON.parse(sessionStorage.tool);
sessionStorage.removeItem('tool');
clone = true;
}
});
</script>
</script>
<ToolkitEditor />
<ToolkitEditor
id={tool?.id ?? ''}
name={tool?.name ?? ''}
meta={tool?.meta ?? { description: '' }}
content={tool?.content ?? ''}
{clone}
on:save={(e) => {
saveHandler(e.detail);
}}
/>
src/routes/(app)/workspace/tools/edit/+page.svelte
View file @
e6fe3ada
<script>
<script>
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { getToolById, getTools, updateToolById } from '$lib/apis/tools';
import Spinner from '$lib/components/common/Spinner.svelte';
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
import { tools } from '$lib/stores';
import { onMount } from 'svelte';
import { toast } from 'svelte-sonner';
let tool = null;
const saveHandler = async (data) => {
console.log(data);
const res = await updateToolById(localStorage.token, tool.id, {
id: data.id,
name: data.name,
meta: data.meta,
content: data.content
}).catch((error) => {
toast.error(error);
return null;
});
if (res) {
toast.success('Tool updated successfully');
tools.set(await getTools(localStorage.token));
await goto('/workspace/tools');
}
};
onMount(async () => {
console.log('mounted');
const id = $page.url.searchParams.get('id');
if (id) {
tool = await getToolById(localStorage.token, id).catch((error) => {
toast.error(error);
goto('/workspace/tools');
return null;
});
console.log(tool);
}
});
</script>
</script>
<ToolkitEditor />
{#if tool}
<ToolkitEditor
edit={true}
id={tool.id}
name={tool.name}
meta={tool.meta}
content={tool.content}
on:save={(e) => {
saveHandler(e.detail);
}}
/>
{:else}
<div class="flex items-center justify-center h-full">
<div class=" pb-16">
<Spinner />
</div>
</div>
{/if}
Prev
1
2
Next
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