Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make finish reason nullable in json marshal #449

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

yuikns
Copy link
Contributor

@yuikns yuikns commented Jul 19, 2023

Describe the change

this PR added a MarshalJSON to FinishReason.

Describe your solution

MarshalJSON implemented Marshaler interface in package encoding/json

If FinishReason is FinishReasonNull or empty string, we can render it as null instead of "null".

Tests

c := &ChatCompletionChoice{
	FinishReason: FinishReasonNull,
}
jsonBytes, _ := json.Marshal(c)
fmt.Println(string(jsonBytes)) // it will print { .... "finish_reason": null }

Since i am not sure is this PR expected, i didn't add a lot of test cases in *_test.go file in the PR. but it was test locally.

@yuikns yuikns force-pushed the master branch 3 times, most recently from cf89f4d to f7a22b5 Compare July 19, 2023 18:23
@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #449 (00f38ad) into master (1876e0c) will increase coverage by 0.02%.
Report is 1 commits behind head on master.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #449      +/-   ##
==========================================
+ Coverage   97.03%   97.05%   +0.02%     
==========================================
  Files          17       17              
  Lines         709      714       +5     
==========================================
+ Hits          688      693       +5     
  Misses         15       15              
  Partials        6        6              
Files Changed Coverage Δ
chat.go 100.00% <ø> (ø)

... and 1 file with indirect coverage changes

chat.go Show resolved Hide resolved
chat.go Outdated Show resolved Hide resolved
@yuikns yuikns force-pushed the master branch 3 times, most recently from 9555fc7 to 6b1b4d9 Compare July 27, 2023 19:04
@vvatanabe vvatanabe merged commit 62dc817 into sashabaranov:master Jul 28, 2023
3 checks passed
@vvatanabe
Copy link
Collaborator

@yuikns Thank you for patiently discussing! I merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants