Skip to content

Commit

Permalink
fix non streaming response
Browse files Browse the repository at this point in the history
Signed-off-by: pandyamarut <[email protected]>
  • Loading branch information
pandyamarut committed Nov 6, 2024
1 parent fd227ce commit 250fe41
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ async def async_handler(job):
openai_url = f"{engine.base_url}" + openai_route
headers = {"Content-Type": "application/json"}

response = requests.post(openai_url, headers=headers, json=openai_input, stream=True)
response = requests.post(openai_url, headers=headers, json=openai_input)
# Process the streamed response
for formated_chunk in process_response(response):
yield formated_chunk
if openai_input.get("stream", False):
for formated_chunk in process_response(response):
yield formated_chunk
else:
for chunk in response.iter_lines():
if chunk:
decoded_chunk = chunk.decode('utf-8')
yield decoded_chunk
else:
generate_url = f"{engine.base_url}/generate"
headers = {"Content-Type": "application/json"}
Expand Down

0 comments on commit 250fe41

Please sign in to comment.