Skip to content

Commit

Permalink
make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
WqyJh committed Nov 20, 2024
1 parent 8be2fdd commit 3e53589
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 13 deletions.
9 changes: 6 additions & 3 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ func (m *ChatCompletionMessage) UnmarshalJSON(bs []byte) error {
type ChatCompletionAudio struct {
// Unique identifier for this audio response.
ID string `json:"id"`
// The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
// The Unix timestamp (in seconds) for when this audio response will no longer
// be accessible on the server for use in multi-turn conversations.
ExpiresAt int64 `json:"expires_at"`
// Base64 encoded audio bytes generated by the model, in the format specified in the request.
Data string `json:"data"`
Expand Down Expand Up @@ -308,8 +309,10 @@ type ChatCompletionRequest struct {
Store bool `json:"store,omitempty"`
// Metadata to store with the completion.
Metadata map[string]string `json:"metadata,omitempty"`
// Output types that you would like the model to generate for this request. Most models are capable of generating text, which is the default: ["text"]
// The gpt-4o-audio-preview model can also be used to generate audio. To request that this model generate both text and audio responses, you can use: ["text", "audio"]
// Output types that you would like the model to generate for this request.
// Most models are capable of generating text, which is the default: ["text"]
// The gpt-4o-audio-preview model can also be used to generate audio.
// To request that this model generate both text and audio responses, you can use: ["text", "audio"]
Modalities []Modality `json:"modalities,omitempty"`
// Parameters for audio output. Required when audio output is requested with modalities: ["audio"]
Audio *AudioOutput `json:"audio,omitempty"`
Expand Down
104 changes: 97 additions & 7 deletions chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,23 @@ func TestChatCompletionRequestAudio(t *testing.T) {
},
},
},
want: `{"model":"gpt-4o-audio-preview","modalities":["text","audio"],"audio":{"voice":"alloy","format":"pcm16"},"messages":[{"role":"user","content":"Is a golden retriever a good family dog?"}]}`,
want: `{
"model": "gpt-4o-audio-preview",
"modalities": [
"text",
"audio"
],
"audio": {
"voice": "alloy",
"format": "pcm16"
},
"messages": [
{
"role": "user",
"content": "Is a golden retriever a good family dog?"
}
]
}`,
},
}

Expand Down Expand Up @@ -820,7 +836,7 @@ func TestChatCompletionResponseAudio(t *testing.T) {
ID: "audio_6731c23369048190aee358c51e0373d2",
Data: "base64 encoded data",
ExpiresAt: 1731317827,
Transcript: "Yes, golden retrievers are known to be excellent family dogs. They are friendly, gentle, and great with children. Golden retrievers are also intelligent and eager to please, making them easy to train. They tend to get along well with other pets and are known for their loyalty and protective nature.",
Transcript: "Yes, golden retrievers are known to be excellent family dogs. They are friendly, gentle, and great with children. Golden retrievers are also intelligent and eager to please, making them easy to train. They tend to get along well with other pets and are known for their loyalty and protective nature.", //nolint:lll
},
},
FinishReason: openai.FinishReasonStop,
Expand All @@ -846,7 +862,7 @@ func TestChatCompletionResponseAudio(t *testing.T) {
},
SystemFingerprint: "fp_49254d0e9b",
},
want: `{"id":"chatcmpl-ASKCthZk3MUOqqRh64CbUbeTmZ6xl","object":"chat.completion","created":1731314223,"model":"gpt-4o-audio-preview-2024-10-01","choices":[{"index":0,"message":{"role":"assistant","content":null,"refusal":null,"audio":{"id":"audio_6731c23369048190aee358c51e0373d2","data":"base64 encoded data","expires_at":1731317827,"transcript":"Yes, golden retrievers are known to be excellent family dogs. They are friendly, gentle, and great with children. Golden retrievers are also intelligent and eager to please, making them easy to train. They tend to get along well with other pets and are known for their loyalty and protective nature."}},"finish_reason":"stop"}],"usage":{"prompt_tokens":17,"completion_tokens":483,"total_tokens":500,"prompt_tokens_details":{"cached_tokens":0,"audio_tokens":0,"text_tokens":17,"image_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":398,"text_tokens":85,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}},"system_fingerprint":"fp_49254d0e9b"}`,
want: `{"id":"chatcmpl-ASKCthZk3MUOqqRh64CbUbeTmZ6xl","object":"chat.completion","created":1731314223,"model":"gpt-4o-audio-preview-2024-10-01","choices":[{"index":0,"message":{"role":"assistant","content":null,"refusal":null,"audio":{"id":"audio_6731c23369048190aee358c51e0373d2","data":"base64 encoded data","expires_at":1731317827,"transcript":"Yes, golden retrievers are known to be excellent family dogs. They are friendly, gentle, and great with children. Golden retrievers are also intelligent and eager to please, making them easy to train. They tend to get along well with other pets and are known for their loyalty and protective nature."}},"finish_reason":"stop"}],"usage":{"prompt_tokens":17,"completion_tokens":483,"total_tokens":500,"prompt_tokens_details":{"cached_tokens":0,"audio_tokens":0,"text_tokens":17,"image_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":398,"text_tokens":85,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}},"system_fingerprint":"fp_49254d0e9b"}`, //nolint:lll
},
}

Expand Down Expand Up @@ -882,7 +898,26 @@ func TestChatCompletionStreamResponseAudio(t *testing.T) {
},
},
},
want: `{"id":"chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p","object":"chat.completion.chunk","created":1731313962,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_49254d0e9b","choices":[{"index":0,"delta":{"content":null,"audio":{"id":"audio_6731c12b1c148190bb8db8af1330221a","transcript":"Yes"}},"finish_reason":null}]}`,
want: `{
"id": "chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p",
"object": "chat.completion.chunk",
"created": 1731313962,
"model": "gpt-4o-audio-preview-2024-10-01",
"system_fingerprint": "fp_49254d0e9b",
"choices": [
{
"index": 0,
"delta": {
"content": null,
"audio": {
"id": "audio_6731c12b1c148190bb8db8af1330221a",
"transcript": "Yes"
}
},
"finish_reason": null
}
]
}`,
},
{
response: openai.ChatCompletionStreamResponse{
Expand All @@ -902,7 +937,24 @@ func TestChatCompletionStreamResponseAudio(t *testing.T) {
},
},
},
want: `{"id":"chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p","object":"chat.completion.chunk","created":1731313962,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_49254d0e9b","choices":[{"index":0,"delta":{"audio":{"transcript":","}},"finish_reason":null}]}`,
want: `{
"id": "chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p",
"object": "chat.completion.chunk",
"created": 1731313962,
"model": "gpt-4o-audio-preview-2024-10-01",
"system_fingerprint": "fp_49254d0e9b",
"choices": [
{
"index": 0,
"delta": {
"audio": {
"transcript": ","
}
},
"finish_reason": null
}
]
}`,
},
{
response: openai.ChatCompletionStreamResponse{
Expand All @@ -924,7 +976,28 @@ func TestChatCompletionStreamResponseAudio(t *testing.T) {
},
},
},
want: `{"id":"chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p","object":"chat.completion.chunk","created":1731313962,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_49254d0e9b","choices":[{"index":0,"delta":{"role":"assistant","content":null,"refusal":null,"audio":{"id":"audio_6731c12b1c148190bb8db8af1330221a","data":"base64 encoded data"}},"finish_reason":null}]}`,
want: `{
"id": "chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p",
"object": "chat.completion.chunk",
"created": 1731313962,
"model": "gpt-4o-audio-preview-2024-10-01",
"system_fingerprint": "fp_49254d0e9b",
"choices": [
{
"index": 0,
"delta": {
"role": "assistant",
"content": null,
"refusal": null,
"audio": {
"id": "audio_6731c12b1c148190bb8db8af1330221a",
"data": "base64 encoded data"
}
},
"finish_reason": null
}
]
}`,
},
{
response: openai.ChatCompletionStreamResponse{
Expand All @@ -944,7 +1017,24 @@ func TestChatCompletionStreamResponseAudio(t *testing.T) {
},
},
},
want: `{"id":"chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p","object":"chat.completion.chunk","created":1731313962,"model":"gpt-4o-audio-preview-2024-10-01","system_fingerprint":"fp_49254d0e9b","choices":[{"index":0,"delta":{"audio":{"data":"base64 encoded data"}},"finish_reason":null}]}`,
want: `{
"id": "chatcmpl-ASK8gd4isaVFw7qClLmtrcwWvka7p",
"object": "chat.completion.chunk",
"created": 1731313962,
"model": "gpt-4o-audio-preview-2024-10-01",
"system_fingerprint": "fp_49254d0e9b",
"choices": [
{
"index": 0,
"delta": {
"audio": {
"data": "base64 encoded data"
}
},
"finish_reason": null
}
]
}`,
},
}

Expand Down
6 changes: 3 additions & 3 deletions internal/test/checks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type tHelper interface {
// Pointer variable equality is determined based on the equality of the
// referenced values (as opposed to the memory addresses). Function equality
// cannot be determined and will always fail.
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
func Equal(t TestingT, expected, actual interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
Expand All @@ -93,7 +93,7 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})
// JSONEq asserts that two JSON strings are equivalent.
//
// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool {
func JSONEq(t TestingT, expected string, actual string) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
Expand All @@ -107,7 +107,7 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{
t.Fatalf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error())
}

return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...)
return Equal(t, expectedJSONAsInterface, actualJSONAsInterface)
}

// validateEqualArgs checks whether provided arguments can be safely used in the
Expand Down

0 comments on commit 3e53589

Please sign in to comment.