Skip to content

Commit 59af847

Browse files
[azopenai] Add test for different formats in chat completions streaming (#21374)
Also, updating CODEOWNERS to add @jhendrixMSFT to the ai folder.
1 parent ea9085f commit 59af847

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# PRLabel: %Azure.Identity
1919
/sdk/azidentity/ @chlowell @jhendrixMSFT @rickwinter @Azure/azure-sdk-write-identity
2020

21+
# PRLable: %OpenAI
22+
/sdk/ai @richardpark-msft @jhendrixMSFT
23+
2124
# PRLabel: %Internal
2225
/sdk/internal/ @chlowell @jhendrixMSFT @richardpark-msft @rickwinter
2326

@@ -36,6 +39,9 @@
3639
# PRLabel: %Service Bus
3740
/sdk/messaging/azservicebus/ @richardpark-msft @jhendrixMSFT
3841

42+
# PRLabel: %Event Grid
43+
/sdk/messaging/azeventgrid/ @richardpark-msft @jhendrixMSFT
44+
3945
# PRLabel: %Event Hubs
4046
/sdk/messaging/azeventhubs/ @richardpark-msft @jhendrixMSFT
4147

sdk/ai/azopenai/event_reader_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
func TestEventReader_InvalidType(t *testing.T) {
1818
data := []string{
19-
"invaliddata: {\u0022name\u0022:\u0022chatcmpl-7Z4kUpXX6HN85cWY28IXM4EwemLU3\u0022,\u0022object\u0022:\u0022chat.completion.chunk\u0022,\u0022created\u0022:1688594090,\u0022model\u0022:\u0022gpt-4-0613\u0022,\u0022choices\u0022:[{\u0022index\u0022:0,\u0022delta\u0022:{\u0022role\u0022:\u0022assistant\u0022,\u0022content\u0022:\u0022\u0022},\u0022finish_reason\u0022:null}]}\n\n",
19+
"invaliddata: {\"name\":\"chatcmpl-7Z4kUpXX6HN85cWY28IXM4EwemLU3\",\"object\":\"chat.completion.chunk\",\"created\":1688594090,\"model\":\"gpt-4-0613\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"\"},\"finish_reason\":null}]}\n\n",
2020
}
2121

2222
text := strings.NewReader(strings.Join(data, "\n"))
@@ -55,3 +55,23 @@ func TestEventReader_StreamIsClosedBeforeDone(t *testing.T) {
5555
require.Empty(t, evt)
5656
require.EqualError(t, err, "incomplete stream")
5757
}
58+
59+
func TestEventReader_SpacesAroundAreas(t *testing.T) {
60+
buff := strings.NewReader(
61+
// spaces between data
62+
"data: {\"name\":\"chatcmpl-7Z4kUpXX6HN85cWY28IXM4EwemLU3\",\"object\":\"chat.completion.chunk\",\"created\":1688594090,\"model\":\"gpt-4-0613\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"with-spaces\"},\"finish_reason\":null}]}\n" +
63+
// no spaces
64+
"data:{\"name\":\"chatcmpl-7Z4kUpXX6HN85cWY28IXM4EwemLU3\",\"object\":\"chat.completion.chunk\",\"created\":1688594090,\"model\":\"gpt-4-0613\",\"choices\":[{\"index\":0,\"delta\":{\"role\":\"assistant\",\"content\":\"without-spaces\"},\"finish_reason\":null}]}\n",
65+
)
66+
67+
eventReader := newEventReader[ChatCompletions](io.NopCloser(buff))
68+
69+
evt, err := eventReader.Read()
70+
require.NoError(t, err)
71+
require.Equal(t, "with-spaces", *evt.Choices[0].Delta.Content)
72+
73+
evt, err = eventReader.Read()
74+
require.NoError(t, err)
75+
require.NotEmpty(t, evt)
76+
require.Equal(t, "without-spaces", *evt.Choices[0].Delta.Content)
77+
}

0 commit comments

Comments
 (0)