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

audio: add items to AudioResponseFormat enum #382

Merged
merged 2 commits into from
Jun 16, 2023

Conversation

romazu
Copy link
Contributor

@romazu romazu commented Jun 16, 2023

Added "text" and "verbose_json" output formats.

See reference:
https://platform.openai.com/docs/api-reference/audio/create

@codecov
Copy link

codecov bot commented Jun 16, 2023

Codecov Report

Merging #382 (2f9c083) into master (0bd14f9) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #382   +/-   ##
=======================================
  Coverage   95.22%   95.22%           
=======================================
  Files          17       17           
  Lines         670      670           
=======================================
  Hits          638      638           
  Misses         22       22           
  Partials       10       10           
Impacted Files Coverage Δ
audio.go 88.31% <100.00%> (ø)

AudioResponseFormatJSON AudioResponseFormat = "json"
AudioResponseFormatText AudioResponseFormat = "text"
AudioResponseFormatSRT AudioResponseFormat = "srt"
AudioResponseFormatVerboseJSON AudioResponseFormat = "verbose_json"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@romazu What format is verbose_json? If it is json, you may need to add it to the conditions of the function below.

// HasJSONResponse returns true if the response format is JSON.
func (r AudioRequest) HasJSONResponse() bool {
	return r.Format == "" || r.Format == AudioResponseFormatJSON
}

Refs:
https://github.com/sashabaranov/go-openai/blob/master/audio.go#L97-L100

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right, it's a json in the following format:

{
  "task": "transcribe",
  "language": "english",
  "duration": 10.0,
  "segments": [
    {
      "id": 0,
      "seek": 0,
      "start": 0.0,
      "end": 10.16,
      "text": " Chapter 1 Looming",
      "tokens": [
        50364,
        18874,
        502,
        6130,
        10539,
        50872
      ],
      "temperature": 0.0,
      "avg_logprob": -0.6817335401262555,
      "compression_ratio": 0.68,
      "no_speech_prob": 0.01032273843884468,
      "transient": false
    }
  ],
  "text": "Chapter 1 Looming"
}

I also expanded AudioResponse struct to accommodate for this.

Copy link
Owner

@sashabaranov sashabaranov left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! 🙌🏻

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.

3 participants