Skip to content

Commit 8f9adec

Browse files
[azopenai] Be more resilient to messages coming back with just content filtering… (Azure#21625)
Add in better code to handle fields being optional.
1 parent 007e9cd commit 8f9adec

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

sdk/ai/azopenai/example_client_getchatcompletions_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,28 @@ func ExampleClient_GetChatCompletions() {
7878

7979
for _, choice := range resp.Choices {
8080
gotReply = true
81-
fmt.Fprintf(os.Stderr, "Content[%d]: %s\n", *choice.Index, *choice.Message.Content)
81+
82+
if choice.ContentFilterResults != nil {
83+
fmt.Fprintf(os.Stderr, "Content filter results\n")
84+
85+
if choice.ContentFilterResults.Error != nil {
86+
fmt.Fprintf(os.Stderr, " Error:%v\n", choice.ContentFilterResults.Error)
87+
}
88+
89+
fmt.Fprintf(os.Stderr, " Hate: sev: %v, filtered: %v\n", *choice.ContentFilterResults.Hate.Severity, *choice.ContentFilterResults.Hate.Filtered)
90+
fmt.Fprintf(os.Stderr, " SelfHarm: sev: %v, filtered: %v\n", *choice.ContentFilterResults.SelfHarm.Severity, *choice.ContentFilterResults.SelfHarm.Filtered)
91+
fmt.Fprintf(os.Stderr, " Sexual: sev: %v, filtered: %v\n", *choice.ContentFilterResults.Sexual.Severity, *choice.ContentFilterResults.Sexual.Filtered)
92+
fmt.Fprintf(os.Stderr, " Violence: sev: %v, filtered: %v\n", *choice.ContentFilterResults.Violence.Severity, *choice.ContentFilterResults.Violence.Filtered)
93+
}
94+
95+
if choice.Message != nil && choice.Message.Content != nil {
96+
fmt.Fprintf(os.Stderr, "Content[%d]: %s\n", *choice.Index, *choice.Message.Content)
97+
}
98+
99+
if choice.FinishReason != nil {
100+
// this choice's conversation is complete.
101+
fmt.Fprintf(os.Stderr, "Finish reason[%d]: %s\n", *choice.Index, *choice.FinishReason)
102+
}
82103
}
83104

84105
if gotReply {

0 commit comments

Comments
 (0)