Skip to content

Commit

Permalink
Merge pull request #12 from runpod-workers/fix-nst
Browse files Browse the repository at this point in the history
fix non streaming response
  • Loading branch information
pandyamarut authored Nov 6, 2024
2 parents fd227ce + 250fe41 commit 117d7ce
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 117d7ce

Please sign in to comment.