mirror of
https://github.com/open-webui/open-webui
synced 2024-11-17 22:12:51 +00:00
feat: default tools template
This commit is contained in:
parent
f2bd3fdf19
commit
dd423f43de
@ -11,6 +11,7 @@
|
||||
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
export let boilerplate = '';
|
||||
export let value = '';
|
||||
|
||||
let codeEditor;
|
||||
@ -38,7 +39,7 @@
|
||||
// python code editor, highlight python code
|
||||
codeEditor = new EditorView({
|
||||
state: EditorState.create({
|
||||
doc: '',
|
||||
doc: boilerplate,
|
||||
extensions: extensions
|
||||
}),
|
||||
parent: document.getElementById('code-textarea')
|
||||
|
34
src/lib/components/workspace/Tools.svelte
Normal file
34
src/lib/components/workspace/Tools.svelte
Normal file
@ -0,0 +1,34 @@
|
||||
<script>
|
||||
import { getContext } from 'svelte';
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import CodeEditor from './Tools/CodeEditor.svelte';
|
||||
|
||||
let loading = false;
|
||||
|
||||
const submitHandler = async () => {
|
||||
loading = true;
|
||||
// Call the API to submit the code
|
||||
};
|
||||
</script>
|
||||
|
||||
<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=" flex flex-col max-h-[100dvh] h-full">
|
||||
<div class="mb-2.5 flex-1 overflow-auto h-0">
|
||||
<CodeEditor />
|
||||
</div>
|
||||
<div class="pb-3">
|
||||
<button
|
||||
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')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
44
src/lib/components/workspace/Tools/CodeEditor.svelte
Normal file
44
src/lib/components/workspace/Tools/CodeEditor.svelte
Normal file
@ -0,0 +1,44 @@
|
||||
<script>
|
||||
import CodeEditor from '$lib/components/common/CodeEditor.svelte';
|
||||
|
||||
export let value = '';
|
||||
|
||||
let boilerplate = `# Add your custom tools using pure Python code here, make sure to add type hints
|
||||
# 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
|
||||
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
class Tools:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def get_current_time(self) -> str:
|
||||
"""
|
||||
Get the current time.
|
||||
:return: The current time.
|
||||
"""
|
||||
|
||||
now = datetime.now()
|
||||
current_time = now.strftime("%H:%M:%S")
|
||||
return f"Current Time = {current_time}"
|
||||
|
||||
def calculator(self, equation: str) -> str:
|
||||
"""
|
||||
Calculate the result of an equation.
|
||||
:param equation: The equation to calculate.
|
||||
"""
|
||||
|
||||
# Avoid using eval in production code
|
||||
# https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
|
||||
try:
|
||||
result = eval(equation)
|
||||
return f"{equation} = {result}"
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return "Invalid equation"
|
||||
`;
|
||||
</script>
|
||||
|
||||
<CodeEditor bind:value {boilerplate} />
|
@ -14,7 +14,11 @@
|
||||
</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class=" flex flex-col w-full min-h-screen max-h-screen">
|
||||
<div
|
||||
class=" flex flex-col w-full min-h-screen max-h-screen {$showSidebar
|
||||
? 'md:max-w-[calc(100%-260px)]'
|
||||
: ''}"
|
||||
>
|
||||
<div class=" px-4 pt-3 mt-0.5 mb-1">
|
||||
<div class=" flex items-center gap-1">
|
||||
<div class="{$showSidebar ? 'md:hidden' : ''} mr-1 self-start flex flex-none items-center">
|
||||
|
@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import CodeEditor from '$lib/components/common/CodeEditor.svelte';
|
||||
import Tools from '$lib/components/workspace/Tools.svelte';
|
||||
</script>
|
||||
|
||||
<CodeEditor />
|
||||
<Tools />
|
||||
|
Loading…
Reference in New Issue
Block a user