Support stream=True in v1/completions (#49)

This commit is contained in:
Cody Yu
2024-01-18 17:00:56 -08:00
committed by GitHub
parent 98a3e8ef78
commit 61d4c93962
7 changed files with 233 additions and 39 deletions

View File

@@ -25,7 +25,7 @@ if __name__ == "__main__":
"text": "The capital of France is",
"sampling_params": {
"temperature": 0,
"max_new_tokens": 1024,
"max_new_tokens": 512,
},
"stream": True,
},
@@ -33,9 +33,12 @@ if __name__ == "__main__":
)
prev = 0
for chunk in response.iter_lines(decode_unicode=False, delimiter=b"\0"):
if chunk:
data = json.loads(chunk.decode())
for chunk in response.iter_lines(decode_unicode=False):
chunk = chunk.decode("utf-8")
if chunk and chunk.startswith("data:"):
if chunk == "data: [DONE]":
break
data = json.loads(chunk[5:].strip("\n"))
output = data["text"].strip()
print(output[prev:], end="", flush=True)
prev = len(output)