|
|
@@ -71,8 +71,14 @@ def test_chat_completion_stream(system_prompt, user_prompt, max_tokens, re_conte
|
|
|
})
|
|
|
content = ""
|
|
|
last_cmpl_id = None
|
|
|
- for data in res:
|
|
|
+ for i, data in enumerate(res):
|
|
|
choice = data["choices"][0]
|
|
|
+ if i == 0:
|
|
|
+ # Check first role message for stream=True
|
|
|
+ assert choice["delta"]["content"] == ""
|
|
|
+ assert choice["delta"]["role"] == "assistant"
|
|
|
+ else:
|
|
|
+ assert "role" not in choice["delta"]
|
|
|
assert data["system_fingerprint"].startswith("b")
|
|
|
assert "gpt-3.5" in data["model"] # DEFAULT_OAICOMPAT_MODEL, maybe changed in the future
|
|
|
if last_cmpl_id is None:
|
|
|
@@ -242,12 +248,18 @@ def test_chat_completion_with_timings_per_token():
|
|
|
"stream": True,
|
|
|
"timings_per_token": True,
|
|
|
})
|
|
|
- for data in res:
|
|
|
- assert "timings" in data
|
|
|
- assert "prompt_per_second" in data["timings"]
|
|
|
- assert "predicted_per_second" in data["timings"]
|
|
|
- assert "predicted_n" in data["timings"]
|
|
|
- assert data["timings"]["predicted_n"] <= 10
|
|
|
+ for i, data in enumerate(res):
|
|
|
+ if i == 0:
|
|
|
+ # Check first role message for stream=True
|
|
|
+ assert data["choices"][0]["delta"]["content"] == ""
|
|
|
+ assert data["choices"][0]["delta"]["role"] == "assistant"
|
|
|
+ else:
|
|
|
+ assert "role" not in data["choices"][0]["delta"]
|
|
|
+ assert "timings" in data
|
|
|
+ assert "prompt_per_second" in data["timings"]
|
|
|
+ assert "predicted_per_second" in data["timings"]
|
|
|
+ assert "predicted_n" in data["timings"]
|
|
|
+ assert data["timings"]["predicted_n"] <= 10
|
|
|
|
|
|
|
|
|
def test_logprobs():
|
|
|
@@ -295,17 +307,23 @@ def test_logprobs_stream():
|
|
|
)
|
|
|
output_text = ''
|
|
|
aggregated_text = ''
|
|
|
- for data in res:
|
|
|
+ for i, data in enumerate(res):
|
|
|
choice = data.choices[0]
|
|
|
- if choice.finish_reason is None:
|
|
|
- if choice.delta.content:
|
|
|
- output_text += choice.delta.content
|
|
|
- assert choice.logprobs is not None
|
|
|
- assert choice.logprobs.content is not None
|
|
|
- for token in choice.logprobs.content:
|
|
|
- aggregated_text += token.token
|
|
|
- assert token.logprob <= 0.0
|
|
|
- assert token.bytes is not None
|
|
|
- assert token.top_logprobs is not None
|
|
|
- assert len(token.top_logprobs) > 0
|
|
|
+ if i == 0:
|
|
|
+ # Check first role message for stream=True
|
|
|
+ assert choice.delta.content == ""
|
|
|
+ assert choice.delta.role == "assistant"
|
|
|
+ else:
|
|
|
+ assert choice.delta.role is None
|
|
|
+ if choice.finish_reason is None:
|
|
|
+ if choice.delta.content:
|
|
|
+ output_text += choice.delta.content
|
|
|
+ assert choice.logprobs is not None
|
|
|
+ assert choice.logprobs.content is not None
|
|
|
+ for token in choice.logprobs.content:
|
|
|
+ aggregated_text += token.token
|
|
|
+ assert token.logprob <= 0.0
|
|
|
+ assert token.bytes is not None
|
|
|
+ assert token.top_logprobs is not None
|
|
|
+ assert len(token.top_logprobs) > 0
|
|
|
assert aggregated_text == output_text
|