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
6589464d
Commit
6589464d
authored
Jun 10, 2024
by
Timothy J. Baek
Browse files
refac
parent
e27c2640
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
41 deletions
+63
-41
src/lib/components/common/CodeEditor.svelte
src/lib/components/common/CodeEditor.svelte
+1
-7
src/lib/components/workspace/Tools/CodeEditor.svelte
src/lib/components/workspace/Tools/CodeEditor.svelte
+18
-7
src/lib/components/workspace/Tools/ToolkitEditor.svelte
src/lib/components/workspace/Tools/ToolkitEditor.svelte
+24
-9
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
+9
-1
No files found.
src/lib/components/common/CodeEditor.svelte
View file @
6589464d
...
@@ -113,14 +113,8 @@
...
@@ -113,14 +113,8 @@
const handleSave = async (e) => {
const handleSave = async (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
e.preventDefault();
e.preventDefault();
const res = await formatPythonCodeHandler().catch((error) => {
return null;
});
if (res) {
dispatch('save');
dispatch('save');
}
}
}
};
};
document.addEventListener('keydown', handleSave);
document.addEventListener('keydown', handleSave);
...
...
src/lib/components/workspace/Tools/CodeEditor.svelte
View file @
6589464d
<script lang="ts">
<script lang="ts">
import CodeEditor from '$lib/components/common/CodeEditor.svelte';
import CodeEditor from '$lib/components/common/CodeEditor.svelte';
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
export let saveHandler: Function;
export let value = '';
export let value = '';
let codeEditor;
let codeEditor;
let boilerplate = `from datetime import datetime
let boilerplate = `# Tip: Use Ctrl/Cmd + S to format the code
from datetime import datetime
import requests
import requests
import os
class Tools:
class Tools:
def __init__(self):
def __init__(self):
...
@@ -20,6 +19,18 @@ class Tools:
...
@@ -20,6 +19,18 @@ class Tools:
# Use Sphinx-style docstrings to document your tools, they will be used for generating tools specifications
# Use Sphinx-style docstrings to document your tools, they will be used for generating tools specifications
# Please refer to function_calling_filter_pipeline.py file from pipelines project for an example
# Please refer to function_calling_filter_pipeline.py file from pipelines project for an example
def get_environment_variable(self, variable_name: str) -> str:
"""
Get the value of an environment variable.
:param variable_name: The name of the environment variable.
:return: The value of the environment variable or a message if it doesn't exist.
"""
value = os.getenv(variable_name)
if value is not None:
return f"The value of the environment variable '{variable_name}' is '{value}'"
else:
return f"The environment variable '{variable_name}' does not exist."
def get_current_time(self) -> str:
def get_current_time(self) -> str:
"""
"""
Get the current time.
Get the current time.
...
@@ -60,6 +71,6 @@ class Tools:
...
@@ -60,6 +71,6 @@ class Tools:
{boilerplate}
{boilerplate}
bind:this={codeEditor}
bind:this={codeEditor}
on:save={() => {
on:save={() => {
saveHandler(
);
dispatch('save'
);
}}
}}
/>
/>
src/lib/components/workspace/Tools/ToolkitEditor.svelte
View file @
6589464d
<script>
<script>
import { getContext } from 'svelte';
import { getContext
, createEventDispatcher
} from 'svelte';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
import CodeEditor from './CodeEditor.svelte';
import CodeEditor from './CodeEditor.svelte';
import { goto } from '$app/navigation';
import { goto } from '$app/navigation';
const dispatch = createEventDispatcher();
let loading = false;
let loading = false;
let id = '';
let id = '';
...
@@ -24,8 +26,12 @@
...
@@ -24,8 +26,12 @@
const saveHandler = async () => {
const saveHandler = async () => {
loading = true;
loading = true;
// Call the API to save the toolkit
dispatch('save', {
console.log('saveHandler');
id,
name,
meta,
content
});
};
};
const submitHandler = async () => {
const submitHandler = async () => {
...
@@ -42,7 +48,12 @@
...
@@ -42,7 +48,12 @@
<div class=" flex flex-col justify-between w-full overflow-y-auto h-full">
<div class=" flex flex-col justify-between w-full overflow-y-auto h-full">
<div class="mx-auto w-full md:px-0 h-full">
<div class="mx-auto w-full md:px-0 h-full">
<div class=" flex flex-col max-h-[100dvh] h-full">
<form
class=" flex flex-col max-h-[100dvh] h-full"
on:submit|preventDefault={() => {
submitHandler();
}}
>
<div class="mb-2.5">
<div class="mb-2.5">
<button
<button
class="flex space-x-1"
class="flex space-x-1"
...
@@ -97,20 +108,24 @@
...
@@ -97,20 +108,24 @@
</div>
</div>
<div class="mb-2 flex-1 overflow-auto h-0 rounded-lg">
<div class="mb-2 flex-1 overflow-auto h-0 rounded-lg">
<CodeEditor bind:value={content} bind:this={codeEditor} {saveHandler} />
<CodeEditor
bind:value={content}
bind:this={codeEditor}
on:save={() => {
// submit form
submitHandler();
}}
/>
</div>
</div>
<div class="pb-3 flex justify-end">
<div class="pb-3 flex justify-end">
<button
<button
class="px-3 py-1.5 text-sm font-medium bg-emerald-600 hover:bg-emerald-700 text-gray-50 transition rounded-lg"
class="px-3 py-1.5 text-sm font-medium bg-emerald-600 hover:bg-emerald-700 text-gray-50 transition rounded-lg"
on:click={() => {
submitHandler();
}}
>
>
{$i18n.t('Save')}
{$i18n.t('Save')}
</button>
</button>
</div>
</div>
</div>
</div>
</
div
>
</
form
>
</div>
</div>
</div>
</div>
src/routes/(app)/+layout.svelte
View file @
6589464d
...
@@ -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 @
6589464d
<script>
<script>
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
import ToolkitEditor from '$lib/components/workspace/Tools/ToolkitEditor.svelte';
const saveHandler = async (data) => {
console.log(data);
};
</script>
</script>
<ToolkitEditor />
<ToolkitEditor
on:save={(e) => {
saveHandler(e.detail);
}}
/>
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