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
5cd28c04
"server/git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "ccb7eb81357c6612705c6b67306616e2bc57acf7"
Commit
5cd28c04
authored
Jun 11, 2024
by
Timothy J. Baek
Browse files
feat: model tools assignment
parent
c3ce4d7f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
16 deletions
+116
-16
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+10
-11
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+13
-3
src/lib/components/workspace/Models/ToolsSelector.svelte
src/lib/components/workspace/Models/ToolsSelector.svelte
+57
-0
src/routes/(app)/workspace/models/create/+page.svelte
src/routes/(app)/workspace/models/create/+page.svelte
+17
-1
src/routes/(app)/workspace/models/edit/+page.svelte
src/routes/(app)/workspace/models/edit/+page.svelte
+19
-1
No files found.
src/lib/components/chat/Chat.svelte
View file @
5cd28c04
...
@@ -74,6 +74,9 @@
...
@@ -74,6 +74,9 @@
let selectedModels = [''];
let selectedModels = [''];
let atSelectedModel: Model | undefined;
let atSelectedModel: Model | undefined;
let selectedModelIds = [];
$: selectedModelIds = atSelectedModel !== undefined ? [atSelectedModel.id] : selectedModels;
let selectedToolIds = [];
let selectedToolIds = [];
let webSearchEnabled = false;
let webSearchEnabled = false;
...
@@ -1281,17 +1284,13 @@
...
@@ -1281,17 +1284,13 @@
bind:selectedToolIds
bind:selectedToolIds
bind:webSearchEnabled
bind:webSearchEnabled
bind:atSelectedModel
bind:atSelectedModel
availableTools={$user.role === 'admin'
availableToolIds={selectedModelIds.reduce((a, e, i, arr) => {
? $tools.reduce((a, e, i, arr) => {
const model = $models.find((m) => m.id === e);
a[e.id] = {
if (model?.info?.meta?.toolIds ?? false) {
name: e.name,
return [...new Set([...a, ...model.info.meta.toolIds])];
description: e.meta.description,
}
enabled: false
return a;
};
}, [])}
return a;
}, {})
: {}}
{selectedModels}
{selectedModels}
{messages}
{messages}
{submitPrompt}
{submitPrompt}
...
...
src/lib/components/chat/MessageInput.svelte
View file @
5cd28c04
...
@@ -9,7 +9,8 @@
...
@@ -9,7 +9,8 @@
models,
models,
config,
config,
showCallOverlay,
showCallOverlay,
tools
tools,
user as _user
} from '$lib/stores';
} from '$lib/stores';
import { blobToFile, calculateSHA256, findWordIndices } from '$lib/utils';
import { blobToFile, calculateSHA256, findWordIndices } from '$lib/utils';
...
@@ -59,7 +60,7 @@
...
@@ -59,7 +60,7 @@
export let files = [];
export let files = [];
export let availableTools =
{}
;
export let availableTool
Id
s =
[]
;
export let selectedToolIds = [];
export let selectedToolIds = [];
export let webSearchEnabled = false;
export let webSearchEnabled = false;
...
@@ -657,7 +658,16 @@
...
@@ -657,7 +658,16 @@
<InputMenu
<InputMenu
bind:webSearchEnabled
bind:webSearchEnabled
bind:selectedToolIds
bind:selectedToolIds
tools={availableTools}
tools={$tools.reduce((a, e, i, arr) => {
if (availableToolIds.includes(e.id) || ($_user?.role ?? 'user') === 'admin') {
a[e.id] = {
name: e.name,
description: e.meta.description,
enabled: false
};
}
return a;
}, {})}
uploadFilesHandler={() => {
uploadFilesHandler={() => {
filesInputElement.click();
filesInputElement.click();
}}
}}
...
...
src/lib/components/workspace/Models/ToolsSelector.svelte
0 → 100644
View file @
5cd28c04
<script lang="ts">
import Checkbox from '$lib/components/common/Checkbox.svelte';
import { getContext, onMount } from 'svelte';
export let tools = [];
let _tools = {};
export let selectedToolIds = [];
const i18n = getContext('i18n');
onMount(() => {
_tools = tools.reduce((acc, tool) => {
acc[tool.id] = {
...tool,
selected: selectedToolIds.includes(tool.id)
};
return acc;
}, {});
});
</script>
<div>
<div class="flex w-full justify-between mb-1">
<div class=" self-center text-sm font-semibold">{$i18n.t('Tools')}</div>
</div>
<div class=" text-xs dark:text-gray-500">
{$i18n.t('To select toolkits here, add them to the "Tools" workspace first.')}
</div>
<div class="flex flex-col">
{#if tools.length > 0}
<div class=" flex items-center gap-2 mt-2">
{#each Object.keys(_tools) as tool, toolIdx}
<div class=" flex items-center gap-2">
<div class="self-center flex items-center">
<Checkbox
state={_tools[tool].selected ? 'checked' : 'unchecked'}
on:change={(e) => {
_tools[tool].selected = e.detail === 'checked';
selectedToolIds = Object.keys(_tools).filter((t) => _tools[t].selected);
}}
/>
</div>
<div class=" py-0.5 text-sm w-full capitalize font-medium">
{_tools[tool].name}
</div>
</div>
{/each}
</div>
{/if}
</div>
</div>
src/routes/(app)/workspace/models/create/+page.svelte
View file @
5cd28c04
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { toast } from 'svelte-sonner';
import { toast } from 'svelte-sonner';
import { goto } from '$app/navigation';
import { goto } from '$app/navigation';
import { settings, user, config, models } from '$lib/stores';
import { settings, user, config, models
, tools
} from '$lib/stores';
import { onMount, tick, getContext } from 'svelte';
import { onMount, tick, getContext } from 'svelte';
import { addNewModel, getModelById, getModelInfos } from '$lib/apis/models';
import { addNewModel, getModelById, getModelInfos } from '$lib/apis/models';
...
@@ -12,6 +12,8 @@
...
@@ -12,6 +12,8 @@
import Checkbox from '$lib/components/common/Checkbox.svelte';
import Checkbox from '$lib/components/common/Checkbox.svelte';
import Tags from '$lib/components/common/Tags.svelte';
import Tags from '$lib/components/common/Tags.svelte';
import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
import ToolsSelector from '$lib/components/workspace/Models/ToolsSelector.svelte';
import { stringify } from 'postcss';
const i18n = getContext('i18n');
const i18n = getContext('i18n');
...
@@ -54,6 +56,7 @@
...
@@ -54,6 +56,7 @@
vision: true
vision: true
};
};
let toolIds = [];
let knowledge = [];
let knowledge = [];
$: if (name) {
$: if (name) {
...
@@ -88,6 +91,14 @@
...
@@ -88,6 +91,14 @@
}
}
}
}
if (toolIds.length > 0) {
info.meta.toolIds = toolIds;
} else {
if (info.meta.toolIds) {
delete info.meta.toolIds;
}
}
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
Object.keys(info.params).forEach((key) => {
Object.keys(info.params).forEach((key) => {
if (info.params[key] === '' || info.params[key] === null) {
if (info.params[key] === '' || info.params[key] === null) {
...
@@ -154,6 +165,7 @@
...
@@ -154,6 +165,7 @@
params.stop = params?.stop ? (params?.stop ?? []).join(',') : null;
params.stop = params?.stop ? (params?.stop ?? []).join(',') : null;
capabilities = { ...capabilities, ...(model?.info?.meta?.capabilities ?? {}) };
capabilities = { ...capabilities, ...(model?.info?.meta?.capabilities ?? {}) };
toolIds = model?.info?.meta?.toolIds ?? [];
info = {
info = {
...info,
...info,
...
@@ -554,6 +566,10 @@
...
@@ -554,6 +566,10 @@
<Knowledge bind:knowledge />
<Knowledge bind:knowledge />
</div>
</div>
<div class="my-2">
<ToolsSelector bind:selectedToolIds={toolIds} tools={$tools} />
</div>
<div class="my-1">
<div class="my-1">
<div class="flex w-full justify-between mb-1">
<div class="flex w-full justify-between mb-1">
<div class=" self-center text-sm font-semibold">{$i18n.t('Capabilities')}</div>
<div class=" self-center text-sm font-semibold">{$i18n.t('Capabilities')}</div>
...
...
src/routes/(app)/workspace/models/edit/+page.svelte
View file @
5cd28c04
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
import
{
onMount
,
getContext
}
from
'svelte'
;
import
{
onMount
,
getContext
}
from
'svelte'
;
import
{
page
}
from
'$app/stores'
;
import
{
page
}
from
'$app/stores'
;
import
{
settings
,
user
,
config
,
models
}
from
'$lib/stores'
;
import
{
settings
,
user
,
config
,
models
,
tools
}
from
'$lib/stores'
;
import
{
splitStream
}
from
'$lib/utils'
;
import
{
splitStream
}
from
'$lib/utils'
;
import
{
getModelInfos
,
updateModelById
}
from
'$lib/apis/models'
;
import
{
getModelInfos
,
updateModelById
}
from
'$lib/apis/models'
;
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
Checkbox
from
'$lib/components/common/Checkbox.svelte'
;
import
Checkbox
from
'$lib/components/common/Checkbox.svelte'
;
import
Tags
from
'$lib/components/common/Tags.svelte'
;
import
Tags
from
'$lib/components/common/Tags.svelte'
;
import
Knowledge
from
'$lib/components/workspace/Models/Knowledge.svelte'
;
import
Knowledge
from
'$lib/components/workspace/Models/Knowledge.svelte'
;
import
ToolsSelector
from
'$lib/components/workspace/Models/ToolsSelector.svelte'
;
const
i18n
=
getContext
(
'i18n'
);
const
i18n
=
getContext
(
'i18n'
);
...
@@ -60,6 +61,7 @@
...
@@ -60,6 +61,7 @@
};
};
let
knowledge
=
[];
let
knowledge
=
[];
let
toolIds
=
[];
const
updateHandler
=
async
()
=>
{
const
updateHandler
=
async
()
=>
{
loading
=
true
;
loading
=
true
;
...
@@ -76,6 +78,14 @@
...
@@ -76,6 +78,14 @@
}
}
}
}
if
(
toolIds
.
length
>
0
)
{
info
.
meta
.
toolIds
=
toolIds
;
}
else
{
if
(
info
.
meta
.
toolIds
)
{
delete
info
.
meta
.
toolIds
;
}
}
info
.
params
.
stop
=
params
.
stop
?
params
.
stop
.
split
(
','
).
filter
((
s
)
=>
s
.
trim
())
:
null
;
info
.
params
.
stop
=
params
.
stop
?
params
.
stop
.
split
(
','
).
filter
((
s
)
=>
s
.
trim
())
:
null
;
Object
.
keys
(
info
.
params
).
forEach
((
key
)
=>
{
Object
.
keys
(
info
.
params
).
forEach
((
key
)
=>
{
if
(
info
.
params
[
key
]
===
''
||
info
.
params
[
key
]
===
null
)
{
if
(
info
.
params
[
key
]
===
''
||
info
.
params
[
key
]
===
null
)
{
...
@@ -133,6 +143,10 @@
...
@@ -133,6 +143,10 @@
knowledge
=
[...
model
?.
info
?.
meta
?.
knowledge
];
knowledge
=
[...
model
?.
info
?.
meta
?.
knowledge
];
}
}
if
(
model
?.
info
?.
meta
?.
toolIds
)
{
toolIds
=
[...
model
?.
info
?.
meta
?.
toolIds
];
}
if
(
model
?.
owned_by
===
'openai'
)
{
if
(
model
?.
owned_by
===
'openai'
)
{
capabilities
.
usage
=
false
;
capabilities
.
usage
=
false
;
}
}
...
@@ -515,6 +529,10 @@
...
@@ -515,6 +529,10 @@
<
Knowledge
bind
:
knowledge
/>
<
Knowledge
bind
:
knowledge
/>
</
div
>
</
div
>
<
div
class
=
"my-2"
>
<
ToolsSelector
bind
:
selectedToolIds
={
toolIds
}
tools
={$
tools
}
/>
</
div
>
<
div
class
=
"my-2"
>
<
div
class
=
"my-2"
>
<
div
class
=
"flex w-full justify-between mb-1"
>
<
div
class
=
"flex w-full justify-between mb-1"
>
<
div
class
=
" self-center text-sm font-semibold"
>{$
i18n
.
t
(
'Capabilities'
)}</
div
>
<
div
class
=
" self-center text-sm font-semibold"
>{$
i18n
.
t
(
'Capabilities'
)}</
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