Skip to content

Commit

Permalink
[azopenai] Be more resilient to messages coming back with just conten…
Browse files Browse the repository at this point in the history
…t filtering… (#21625)

Add in better code to handle fields being optional.
  • Loading branch information
richardpark-msft authored Sep 28, 2023
1 parent 007e9cd commit 8f9adec
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion sdk/ai/azopenai/example_client_getchatcompletions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,28 @@ func ExampleClient_GetChatCompletions() {

for _, choice := range resp.Choices {
gotReply = true
fmt.Fprintf(os.Stderr, "Content[%d]: %s\n", *choice.Index, *choice.Message.Content)

if choice.ContentFilterResults != nil {
fmt.Fprintf(os.Stderr, "Content filter results\n")

if choice.ContentFilterResults.Error != nil {
fmt.Fprintf(os.Stderr, " Error:%v\n", choice.ContentFilterResults.Error)
}

fmt.Fprintf(os.Stderr, " Hate: sev: %v, filtered: %v\n", *choice.ContentFilterResults.Hate.Severity, *choice.ContentFilterResults.Hate.Filtered)
fmt.Fprintf(os.Stderr, " SelfHarm: sev: %v, filtered: %v\n", *choice.ContentFilterResults.SelfHarm.Severity, *choice.ContentFilterResults.SelfHarm.Filtered)
fmt.Fprintf(os.Stderr, " Sexual: sev: %v, filtered: %v\n", *choice.ContentFilterResults.Sexual.Severity, *choice.ContentFilterResults.Sexual.Filtered)
fmt.Fprintf(os.Stderr, " Violence: sev: %v, filtered: %v\n", *choice.ContentFilterResults.Violence.Severity, *choice.ContentFilterResults.Violence.Filtered)
}

if choice.Message != nil && choice.Message.Content != nil {
fmt.Fprintf(os.Stderr, "Content[%d]: %s\n", *choice.Index, *choice.Message.Content)
}

if choice.FinishReason != nil {
// this choice's conversation is complete.
fmt.Fprintf(os.Stderr, "Finish reason[%d]: %s\n", *choice.Index, *choice.FinishReason)
}
}

if gotReply {
Expand Down

0 comments on commit 8f9adec

Please sign in to comment.