Skip to content

Commit 0ea3bc9

Browse files
authored
Merge pull request #28 from maschad/mc/fix/chat-completion-chunk
fix: add missing fields to chat completion chunk
2 parents 9cd3e1c + 97834ae commit 0ea3bc9

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/atoma_sdk/models/chatcompletionchunk.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ChatCompletionChunkChoice,
66
ChatCompletionChunkChoiceTypedDict,
77
)
8+
from .usage import Usage, UsageTypedDict
89
from atoma_sdk.types import BaseModel
910
from typing import List
1011
from typing_extensions import TypedDict
@@ -19,6 +20,14 @@ class ChatCompletionChunkTypedDict(TypedDict):
1920
r"""A unique identifier for the chat completion chunk."""
2021
model: str
2122
r"""The model used for the chat completion."""
23+
id: str
24+
r"""The unique identifier for the chat completion."""
25+
system_fingerprint: str | None = None
26+
r"""The system fingerprint for the chat completion."""
27+
usage: UsageTypedDict | None = None
28+
r"""The usage information for the chat completion."""
29+
service_tier: str | None = None
30+
r"""The service tier for the chat completion."""
2231

2332

2433
class ChatCompletionChunk(BaseModel):
@@ -33,3 +42,13 @@ class ChatCompletionChunk(BaseModel):
3342

3443
model: str
3544
r"""The model used for the chat completion."""
45+
46+
system_fingerprint: str | None = None
47+
r"""The system fingerprint for the chat completion."""
48+
49+
usage: Usage | None = None
50+
r"""The usage information for the chat completion."""
51+
52+
service_tier: str | None = None
53+
r"""The service tier for the chat completion."""
54+

src/atoma_sdk/models/chatcompletionresponse.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class ChatCompletionResponseTypedDict(TypedDict):
2121
system_fingerprint: NotRequired[Nullable[str]]
2222
r"""The system fingerprint for the completion, if applicable."""
2323
usage: NotRequired[Nullable[CompletionUsageTypedDict]]
24+
r"""The usage information for the chat completion."""
25+
service_tier: NotRequired[Nullable[str]]
26+
r"""The service tier for the chat completion."""
27+
object: NotRequired[Nullable[str]]
28+
r"""The object type for the chat completion."""
2429

2530

2631
class ChatCompletionResponse(BaseModel):
@@ -40,6 +45,13 @@ class ChatCompletionResponse(BaseModel):
4045
r"""The system fingerprint for the completion, if applicable."""
4146

4247
usage: OptionalNullable[CompletionUsage] = UNSET
48+
r"""The usage information for the chat completion."""
49+
50+
service_tier: OptionalNullable[str] = UNSET
51+
r"""The service tier for the chat completion."""
52+
53+
object: OptionalNullable[str] = UNSET
54+
r"""The object type for the chat completion."""
4355

4456
@model_serializer(mode="wrap")
4557
def serialize_model(self, handler):

test/test_chat_completions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_chat_completion_basic(client):
2727
)
2828

2929
print(completion.choices[0].message)
30-
30+
3131
assert completion is not None
3232
assert len(completion.choices) > 0
3333
assert completion.choices[0].message.content is not None
@@ -40,7 +40,7 @@ def test_chat_completion_with_system_message(client):
4040
{"role": "user", "content": "Hello!"}
4141
]
4242
)
43-
43+
4444
assert completion is not None
4545
assert len(completion.choices) > 0
4646
assert completion.choices[0].message.content is not None
@@ -54,7 +54,7 @@ async def test_chat_completion_async(client):
5454
{"role": "user", "content": "Hello!"}
5555
]
5656
)
57-
57+
5858
assert completion is not None
5959
assert len(completion.choices) > 0
6060
assert completion.choices[0].message.content is not None
@@ -70,15 +70,19 @@ def test_chat_completion_stream(client):
7070

7171
# Verify we get a valid stream
7272
assert completion is not None
73-
73+
7474
# Process the stream and verify chunks
7575
chunk_count = 0
7676
for chunk in completion:
7777
assert chunk is not None
7878
assert chunk.data is not None
7979
assert len(chunk.data.choices) > 0
8080
assert chunk.data.choices[0].delta is not None
81+
assert chunk.data.system_fingerprint is not None
82+
assert chunk.data.usage is not None
83+
assert chunk.data.service_tier is not None
8184
chunk_count += 1
82-
85+
8386
# Verify we got multiple chunks
8487
assert chunk_count > 0
88+

0 commit comments

Comments
 (0)