forked from epam/ai-dial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inherit all Enums from str to make JSON serialization possible (e…
- Loading branch information
Showing
3 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
from enum import Enum | ||
|
||
|
||
class FinishReason(Enum): | ||
class FinishReason(str, Enum): | ||
STOP = "stop" | ||
LENGTH = "length" | ||
FUNCTION_CALL = "function_call" | ||
TOOL_CALLS = "tool_calls" | ||
CONTENT_FILTER = "content_filter" | ||
|
||
|
||
class Status(Enum): | ||
class Status(str, Enum): | ||
COMPLETED = "completed" | ||
FAILED = "failed" |
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
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,19 @@ | ||
import json | ||
|
||
from aidial_sdk.chat_completion import Message, Role | ||
|
||
|
||
def test_message_ser(): | ||
msg_obj = Message(role=Role.SYSTEM, content="test") | ||
actual_dict = msg_obj.dict(exclude_none=True) | ||
expected_dict = {"role": "system", "content": "test"} | ||
|
||
assert json.loads(json.dumps(actual_dict)) == expected_dict | ||
|
||
|
||
def test_message_deser(): | ||
msg_dict = {"role": "system", "content": "test"} | ||
actual_obj = Message.parse_raw(json.dumps(msg_dict)) | ||
expected_obj = Message(role=Role.SYSTEM, content="test") | ||
|
||
assert actual_obj == expected_obj |