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
chenych
chat_demo
Commits
f0863458
Commit
f0863458
authored
Aug 05, 2024
by
chenych
Browse files
Fix stream chat
parent
a92273ba
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
llm_service/inferencer.py
llm_service/inferencer.py
+8
-4
No files found.
llm_service/inferencer.py
View file @
f0863458
...
...
@@ -240,17 +240,21 @@ def vllm_inference(bind_port, model, tokenizer, sampling_params, stream_chat):
# Streaming case
async
def
stream_results
()
->
AsyncGenerator
[
bytes
,
None
]:
final_output
=
None
async
for
request_output
in
results_generator
:
final_output
=
request_output
text_outputs
=
[
output
.
text
for
output
in
request_output
.
outputs
]
ret
=
{
"text"
:
text_outputs
}
print
(
ret
)
# yield (json.dumps(ret) + "\0").encode("utf-8")
yield
web
.
json_response
({
'text'
:
text
})
# yield web.json_response({'text': text_outputs})
return
final_output
if
stream_chat
:
logger
.
info
(
"****************** in chat stream *****************"
)
return
StreamingResponse
(
stream_results
())
# return StreamingResponse(stream_results())
output_text
=
await
stream_results
()
return
web
.
json_response
({
'text'
:
output_text
})
# Non-streaming case
logger
.
info
(
"****************** in chat ******************"
)
...
...
@@ -344,7 +348,7 @@ def main():
if
use_vllm
:
vllm_inference
(
bind_port
,
model
,
tokenizer
,
sampling_params
,
stream_chat
)
else
:
hf_inference
(
bind_port
,
model
,
tokenizer
,
sampling_params
,
stream_chat
)
hf_inference
(
bind_port
,
model
,
tokenizer
,
stream_chat
)
# infer_test(args)
...
...
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