audio: add items to AudioResponseFormat enum (#382)

* audio: add items to AudioResponseFormat enum

* audio: expand AudioResponse struct to accommodate verbose json response

---------

Co-authored-by: Roman Zubov <rzubov@aintsys.com>
This commit is contained in:
romazu
2023-06-16 17:13:26 +04:00
committed by GitHub
parent ac25f318ba
commit f0770cfe1d

View File

@@ -21,7 +21,9 @@ type AudioResponseFormat string
const (
AudioResponseFormatJSON AudioResponseFormat = "json"
AudioResponseFormatText AudioResponseFormat = "text"
AudioResponseFormatSRT AudioResponseFormat = "srt"
AudioResponseFormatVerboseJSON AudioResponseFormat = "verbose_json"
AudioResponseFormatVTT AudioResponseFormat = "vtt"
)
@@ -44,6 +46,22 @@ type AudioRequest struct {
// AudioResponse represents a response structure for audio API.
type AudioResponse struct {
Task string `json:"task"`
Language string `json:"language"`
Duration float64 `json:"duration"`
Segments []struct {
ID int `json:"id"`
Seek int `json:"seek"`
Start float64 `json:"start"`
End float64 `json:"end"`
Text string `json:"text"`
Tokens []int `json:"tokens"`
Temperature float64 `json:"temperature"`
AvgLogprob float64 `json:"avg_logprob"`
CompressionRatio float64 `json:"compression_ratio"`
NoSpeechProb float64 `json:"no_speech_prob"`
Transient bool `json:"transient"`
} `json:"segments"`
Text string `json:"text"`
}
@@ -96,7 +114,7 @@ func (c *Client) callAudioAPI(
// HasJSONResponse returns true if the response format is JSON.
func (r AudioRequest) HasJSONResponse() bool {
return r.Format == "" || r.Format == AudioResponseFormatJSON
return r.Format == "" || r.Format == AudioResponseFormatJSON || r.Format == AudioResponseFormatVerboseJSON
}
// audioMultipartForm creates a form with audio file contents and the name of the model to use for