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
f6efda9e
Commit
f6efda9e
authored
Jun 30, 2024
by
Timothy J. Baek
Browse files
refac: ollama non stream response
parent
bb53282c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+20
-8
No files found.
backend/apps/ollama/main.py
View file @
f6efda9e
...
...
@@ -153,7 +153,7 @@ async def cleanup_response(
await
session
.
close
()
async
def
post_streaming_url
(
url
:
str
,
payload
:
str
):
async
def
post_streaming_url
(
url
:
str
,
payload
:
str
,
stream
:
bool
=
True
):
r
=
None
try
:
session
=
aiohttp
.
ClientSession
(
...
...
@@ -162,12 +162,20 @@ async def post_streaming_url(url: str, payload: str):
r
=
await
session
.
post
(
url
,
data
=
payload
)
r
.
raise_for_status
()
if
stream
:
return
StreamingResponse
(
r
.
content
,
status_code
=
r
.
status
,
headers
=
dict
(
r
.
headers
),
background
=
BackgroundTask
(
cleanup_response
,
response
=
r
,
session
=
session
),
background
=
BackgroundTask
(
cleanup_response
,
response
=
r
,
session
=
session
),
)
else
:
res
=
await
r
.
json
()
await
cleanup_response
(
r
,
session
)
return
res
except
Exception
as
e
:
error_detail
=
"Open WebUI: Server Connection Error"
if
r
is
not
None
:
...
...
@@ -963,7 +971,11 @@ async def generate_openai_chat_completion(
url
=
app
.
state
.
config
.
OLLAMA_BASE_URLS
[
url_idx
]
log
.
info
(
f
"url:
{
url
}
"
)
return
await
post_streaming_url
(
f
"
{
url
}
/v1/chat/completions"
,
json
.
dumps
(
payload
))
return
await
post_streaming_url
(
f
"
{
url
}
/v1/chat/completions"
,
json
.
dumps
(
payload
),
stream
=
payload
.
get
(
"stream"
,
False
),
)
@
app
.
get
(
"/v1/models"
)
...
...
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