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
0ae57b5a
Commit
0ae57b5a
authored
Dec 26, 2023
by
Timothy J. Baek
Browse files
fix: cors & #281
parent
0c30a085
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
49 deletions
+20
-49
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+9
-0
backend/dev.sh
backend/dev.sh
+1
-1
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+2
-6
src/lib/constants.ts
src/lib/constants.ts
+7
-6
src/routes/(app)/c/[id]/+page.svelte
src/routes/(app)/c/[id]/+page.svelte
+1
-36
No files found.
backend/apps/ollama/main.py
View file @
0ae57b5a
...
@@ -61,6 +61,13 @@ def proxy(path):
...
@@ -61,6 +61,13 @@ def proxy(path):
r
=
None
r
=
None
del
headers
[
"Host"
]
del
headers
[
"Authorization"
]
del
headers
[
"Origin"
]
del
headers
[
"Referer"
]
print
(
headers
)
try
:
try
:
# Make a request to the target server
# Make a request to the target server
r
=
requests
.
request
(
r
=
requests
.
request
(
...
@@ -86,8 +93,10 @@ def proxy(path):
...
@@ -86,8 +93,10 @@ def proxy(path):
return
response
return
response
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
error_detail
=
"Ollama WebUI: Server Connection Error"
error_detail
=
"Ollama WebUI: Server Connection Error"
if
r
!=
None
:
if
r
!=
None
:
print
(
r
.
text
)
res
=
r
.
json
()
res
=
r
.
json
()
if
"error"
in
res
:
if
"error"
in
res
:
error_detail
=
f
"Ollama:
{
res
[
'error'
]
}
"
error_detail
=
f
"Ollama:
{
res
[
'error'
]
}
"
...
...
backend/dev.sh
View file @
0ae57b5a
uvicorn main:app
--port
8080
--reload
uvicorn main:app
--port
8080
--host
0.0.0.0
--reload
\ No newline at end of file
\ No newline at end of file
src/lib/components/chat/Messages.svelte
View file @
0ae57b5a
...
@@ -83,7 +83,7 @@
...
@@ -83,7 +83,7 @@
blocks
.
forEach
((
block
)
=>
{
blocks
.
forEach
((
block
)
=>
{
// only add button if browser supports Clipboard API
// only add button if browser supports Clipboard API
if
(
navigator
.
clipboard
&&
block
.
childNodes
.
length
<
2
&&
block
.
id
!==
'
user-message
'
)
{
if
(
block
.
childNodes
.
length
<
2
&&
block
.
id
!==
'
user-message
'
)
{
let
code
=
block
.
querySelector
(
'
code
'
);
let
code
=
block
.
querySelector
(
'
code
'
);
code
.
style
.
borderTopRightRadius
=
0
;
code
.
style
.
borderTopRightRadius
=
0
;
code
.
style
.
borderTopLeftRadius
=
0
;
code
.
style
.
borderTopLeftRadius
=
0
;
...
@@ -121,10 +121,6 @@
...
@@ -121,10 +121,6 @@
topBarDiv
.
appendChild
(
button
);
topBarDiv
.
appendChild
(
button
);
block
.
prepend
(
topBarDiv
);
block
.
prepend
(
topBarDiv
);
// button.addEventListener('click', async () => {
// await copyCode(block, button);
// });
}
}
});
});
...
@@ -132,7 +128,7 @@
...
@@ -132,7 +128,7 @@
let
code
=
block
.
querySelector
(
'
code
'
);
let
code
=
block
.
querySelector
(
'
code
'
);
let
text
=
code
.
innerText
;
let
text
=
code
.
innerText
;
await
navigator
.
clipboard
.
writeText
(
text
);
await
copyToClipboard
(
text
);
// visual feedback that task is completed
// visual feedback that task is completed
button
.
innerText
=
'
Copied!
'
;
button
.
innerText
=
'
Copied!
'
;
...
...
src/lib/constants.ts
View file @
0ae57b5a
import
{
dev
,
browser
}
from
'
$app/environment
'
;
import
{
dev
,
browser
}
from
'
$app/environment
'
;
import
{
PUBLIC_API_BASE_URL
}
from
'
$env/static/public
'
;
import
{
PUBLIC_API_BASE_URL
}
from
'
$env/static/public
'
;
export
const
OLLAMA_API_BASE_URL
=
export
const
OLLAMA_API_BASE_URL
=
dev
PUBLIC_API_BASE_URL
===
''
?
`http://
${
location
.
hostname
}
:8080/ollama/api`
?
browser
:
PUBLIC_API_BASE_URL
===
''
?
`http://
${
location
.
hostname
}
:11434/api`
?
browser
:
`http://localhost:11434/api`
?
`http://
${
location
.
hostname
}
:11434/api`
:
PUBLIC_API_BASE_URL
;
:
`http://localhost:11434/api`
:
PUBLIC_API_BASE_URL
;
export
const
WEBUI_BASE_URL
=
dev
?
`http://
${
location
.
hostname
}
:8080`
:
``
;
export
const
WEBUI_BASE_URL
=
dev
?
`http://
${
location
.
hostname
}
:8080`
:
``
;
export
const
WEBUI_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/api/v1`
;
export
const
WEBUI_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/api/v1`
;
...
...
src/routes/(app)/c/[id]/+page.svelte
View file @
0ae57b5a
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { onMount, tick } from 'svelte';
import { onMount, tick } from 'svelte';
import { convertMessagesToHistory, splitStream } from '$lib/utils';
import { convertMessagesToHistory,
copyToClipboard,
splitStream } from '$lib/utils';
import { goto } from '$app/navigation';
import { goto } from '$app/navigation';
import { config, models, modelfiles, user, settings, db, chats, chatId } from '$lib/stores';
import { config, models, modelfiles, user, settings, db, chats, chatId } from '$lib/stores';
...
@@ -113,41 +113,6 @@
...
@@ -113,41 +113,6 @@
}
}
};
};
const copyToClipboard = (text) => {
if (!navigator.clipboard) {
var textArea = document.createElement('textarea');
textArea.value = text;
// Avoid scrolling to bottom
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.position = 'fixed';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Fallback: Copying text command was ' + msg);
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
return;
}
navigator.clipboard.writeText(text).then(
function () {
console.log('Async: Copying to clipboard was successful!');
},
function (err) {
console.error('Async: Could not copy text: ', err);
}
);
};
//////////////////////////
//////////////////////////
// Ollama functions
// Ollama functions
//////////////////////////
//////////////////////////
...
...
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