From 635767408fce556f5b2d21ef13663790501e808b Mon Sep 17 00:00:00 2001 From: josc146 Date: Thu, 8 Jun 2023 13:30:34 +0800 Subject: [PATCH] fix UnboundLocalError: local variable 'response' referenced before assignment --- backend-python/routes/completion.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend-python/routes/completion.py b/backend-python/routes/completion.py index 22bdc96..a7c61c5 100644 --- a/backend-python/routes/completion.py +++ b/backend-python/routes/completion.py @@ -138,6 +138,7 @@ The following is a coherent verbose detailed conversation between a girl named { set_rwkv_config(model, global_var.get(global_var.Model_Config)) set_rwkv_config(model, body) if body.stream: + response = "" for response, delta in model.generate( completion_text, stop=f"\n\n{user}" if body.stop is None else body.stop, @@ -188,7 +189,7 @@ The following is a coherent verbose detailed conversation between a girl named { ) yield "[DONE]" else: - response = None + response = "" for response, delta in model.generate( completion_text, stop=f"\n\n{user}" if body.stop is None else body.stop, @@ -282,6 +283,7 @@ async def completions(body: CompletionBody, request: Request): set_rwkv_config(model, global_var.get(global_var.Model_Config)) set_rwkv_config(model, body) if body.stream: + response = "" for response, delta in model.generate(body.prompt, stop=body.stop): if await request.is_disconnected(): break @@ -329,7 +331,7 @@ async def completions(body: CompletionBody, request: Request): ) yield "[DONE]" else: - response = None + response = "" for response, delta in model.generate(body.prompt, stop=body.stop): if await request.is_disconnected(): break