Skip to content

Commit

Permalink
[azopenai] Implement UnmarshalJSON method for custom types (#22133)
Browse files Browse the repository at this point in the history
A UnmarshalJSON method has been added to the ChatCompletionsToolChoice and ChatRequestUserMessageContent structs. These implementations allow the structs to satisfy the json.Unmarshaller interface, enabling them to decode JSON directly into their respective types.
  • Loading branch information
zjy282 authored Jan 17, 2024
1 parent 18bb6a3 commit 176ab71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/ai/azopenai/custom_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,8 @@ func NewChatRequestUserMessageContent[T string | []ChatCompletionRequestMessageC
func (c ChatRequestUserMessageContent) MarshalJSON() ([]byte, error) {
return json.Marshal(c.value)
}

// UnmarshalJSON implements the json.Unmarshaller interface for type ChatRequestUserMessageContent.
func (c *ChatRequestUserMessageContent) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &c.value)
}
5 changes: 5 additions & 0 deletions sdk/ai/azopenai/custom_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@ func (tf ChatCompletionsToolChoiceFunction) MarshalJSON() ([]byte, error) {
func (tc ChatCompletionsToolChoice) MarshalJSON() ([]byte, error) {
return json.Marshal(tc.value)
}

// UnmarshalJSON implements the json.Unmarshaller interface for type ChatCompletionsToolChoice.
func (tc *ChatCompletionsToolChoice) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &tc.value)
}

0 comments on commit 176ab71

Please sign in to comment.