Skip to content

Conversation

hoani
Copy link
Contributor

@hoani hoani commented Apr 19, 2023

Closes #143

Allows users to add a Format: argument to the request to get captions from the audio apis.

Demonstration (using the same code added for README)

Screen.Recording.2023-04-19.at.4.13.29.PM.mov

Broke decodeResponse out of client, because cyclomatic complexity got above 20 with the string response changes.

Added tests for decodeResponse to not decrease code coverage

@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Merging #267 (4509a89) into master (061c97e) will increase coverage by 0.80%.
The diff coverage is 97.14%.

@@            Coverage Diff             @@
##           master     #267      +/-   ##
==========================================
+ Coverage   91.45%   92.26%   +0.80%     
==========================================
  Files          22       22              
  Lines         620      659      +39     
==========================================
+ Hits          567      608      +41     
+ Misses         39       37       -2     
  Partials       14       14              
Impacted Files Coverage Δ
client.go 87.36% <93.33%> (+4.65%) ⬆️
audio.go 85.93% <100.00%> (+2.91%) ⬆️
image.go 92.77% <100.00%> (+0.77%) ⬆️

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@sashabaranov
Copy link
Owner

Thank you so much for the PR! 🙌🏻

audio.go Outdated
@@ -21,6 +28,7 @@ type AudioRequest struct {
Prompt string // For translation, it should be in English
Temperature float32
Language string // For translation, just do not use it. It seems "en" works, not confirmed...
Format string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maybe make typechecker work for us a little bit here?

type AudioResponseFormat string
const (
	AudioResponseFormatJSON AudioResponseFormat = "json"
	AudioResponseFormatSRT  AudioResponseFormat = "srt"
	AudioResponseFormatVTT  AudioResponseFormat = "vtt"
)

type AudioRequest struct {
...
	Format AudioResponseFormat
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done

client.go Outdated
return decodeResponse(v, *res)
}

func decodeResponse(v interface{}, res http.Response) error {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func decodeResponse(v interface{}, res http.Response) error {
func decodeResponse(v any, res http.Response) error {

Copy link
Owner

@sashabaranov sashabaranov Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also rename v to something sensible here and in sendRequest, maybe response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have:

  • Used any
  • Updated decodeResponse arguments to body io.Reader, v any
    • This ordering is a little nicer (input/output)
    • I struggled to come up with a good name for v - this is what is used in the json library to mean any value that we will decode into... so I feel like it is a better name than response which is used by http (at least in this context)

@sashabaranov sashabaranov merged commit ecdea45 into sashabaranov:master Apr 20, 2023
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.

Whisper Prompt and Response Format
2 participants