-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support continue final message (#2733)
* feat: support continue_final_message param in chat request * feat: add test for continue final message * fix: bump openapi docs * fix: remove continue_final_message chat request param * fix: remove unneeded launcher args in continue test * fix: bump test output * fix: remove accidentally included guideline from rebase * fix: remove guideline tests * fix: adjust continuation tests expected text * fix: replace expected output for continue test
- Loading branch information
Showing
4 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...models/__snapshots__/test_continue_final_message/test_llama_completion_single_prompt.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"choices": [ | ||
{ | ||
"finish_reason": "length", | ||
"index": 0, | ||
"logprobs": null, | ||
"message": { | ||
"content": "Both an elephant and a mouse are mammals. However, the differences between elephants and mice are:\n\n1", | ||
"role": "assistant" | ||
} | ||
} | ||
], | ||
"created": 1732541189, | ||
"id": "", | ||
"model": "TinyLlama/TinyLlama-1.1B-Chat-v1.0", | ||
"object": "chat.completion", | ||
"system_fingerprint": "2.4.1-dev0-native", | ||
"usage": { | ||
"completion_tokens": 30, | ||
"prompt_tokens": 49, | ||
"total_tokens": 79 | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...snapshots__/test_continue_final_message/test_llama_completion_single_prompt_continue.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"choices": [ | ||
{ | ||
"finish_reason": "length", | ||
"index": 0, | ||
"logprobs": null, | ||
"message": { | ||
"content": " the royal mouse? It is a little more slender and only weighs around 1.5 pounds for males and 1.3 pounds", | ||
"role": "assistant" | ||
} | ||
} | ||
], | ||
"created": 1732541190, | ||
"id": "", | ||
"model": "TinyLlama/TinyLlama-1.1B-Chat-v1.0", | ||
"object": "chat.completion", | ||
"system_fingerprint": "2.4.1-dev0-native", | ||
"usage": { | ||
"completion_tokens": 30, | ||
"prompt_tokens": 73, | ||
"total_tokens": 103 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import pytest | ||
import requests | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def llama_continue_final_message_handle(launcher): | ||
with launcher("TinyLlama/TinyLlama-1.1B-Chat-v1.0") as handle: | ||
yield handle | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def llama_continue_final_message(llama_continue_final_message_handle): | ||
await llama_continue_final_message_handle.health(300) | ||
return llama_continue_final_message_handle.client | ||
|
||
|
||
def test_llama_completion_single_prompt( | ||
llama_continue_final_message, response_snapshot | ||
): | ||
response = requests.post( | ||
f"{llama_continue_final_message.base_url}/v1/chat/completions", | ||
json={ | ||
"model": "tgi", | ||
"messages": [ | ||
{"role": "system", "content": "system message"}, | ||
{"role": "user", "content": "Which is bigger an elephant or a mouse?"}, | ||
], | ||
"max_tokens": 30, | ||
"stream": False, | ||
"seed": 1337, | ||
}, | ||
headers=llama_continue_final_message.headers, | ||
stream=False, | ||
) | ||
response = response.json() | ||
print(response) | ||
assert len(response["choices"]) == 1 | ||
content = response["choices"][0]["message"]["content"] | ||
assert ( | ||
content | ||
== "Both an elephant and a mouse are mammals. However, the differences between elephants and mice are:\n\n1" | ||
) | ||
assert response == response_snapshot | ||
|
||
|
||
def test_llama_completion_single_prompt_continue( | ||
llama_continue_final_message, response_snapshot | ||
): | ||
response = requests.post( | ||
f"{llama_continue_final_message.base_url}/v1/chat/completions", | ||
json={ | ||
"model": "tgi", | ||
"messages": [ | ||
{"role": "system", "content": "system message"}, | ||
{"role": "user", "content": "Which is bigger an elephant or a mouse?"}, | ||
{ | ||
"role": "assistant", | ||
"content": "the elephant, but have you heard about", | ||
}, | ||
], | ||
"max_tokens": 30, | ||
"stream": False, | ||
"seed": 1337, | ||
}, | ||
headers=llama_continue_final_message.headers, | ||
stream=False, | ||
) | ||
response = response.json() | ||
print(response) | ||
assert len(response["choices"]) == 1 | ||
content = response["choices"][0]["message"]["content"] | ||
assert ( | ||
content | ||
== " the royal mouse? It is a little more slender and only weighs around 1.5 pounds for males and 1.3 pounds" | ||
) | ||
assert response == response_snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters