Skip to content

Commit 3fd6dfe

Browse files
committed
Audio
1 parent fe5f5cf commit 3fd6dfe

File tree

1 file changed

+12
-1
lines changed
  • openai-servant/src/OpenAI

1 file changed

+12
-1
lines changed

openai-servant/src/OpenAI/Api.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DataKinds #-}
12
-- | The API
23
module OpenAI.Api where
34

@@ -6,9 +7,19 @@ import Servant.API
67
import Servant.Auth
78
import Servant.Auth.Client
89
import Servant.Multipart.API
10+
import Data.List.NonEmpty (NonEmpty((:|)))
11+
import Data.ByteString.Lazy (ByteString)
912

1013
type OpenAIAuth = Auth '[Bearer] ()
1114

15+
data Audio
16+
17+
instance Accept Audio where
18+
contentTypes _ = "audio/mpeg" :| []
19+
20+
instance MimeUnrender Audio ByteString where
21+
mimeUnrender _ bs = Right bs
22+
1223
type OpenAIApi =
1324
"v1" :> OpenAIApiInternal
1425

@@ -46,7 +57,7 @@ type EmbeddingsApi =
4657
OpenAIAuth :> ReqBody '[JSON] EmbeddingCreate :> Post '[JSON] EmbeddingResponse
4758

4859
type AudioApi =
49-
OpenAIAuth :> "speech" :> ReqBody '[JSON] TextToSpeechRequest :> Post '[OctetStream] TextToSpeechResponse
60+
OpenAIAuth :> "speech" :> ReqBody '[JSON] TextToSpeechRequest :> Post '[Audio] TextToSpeechResponse
5061
:<|> OpenAIAuth :> "transcriptions" :> MultipartForm Tmp AudioTranscriptionRequest :> Post '[JSON] AudioResponseData
5162
:<|> OpenAIAuth :> "translations" :> MultipartForm Tmp AudioTranslationRequest :> Post '[JSON] AudioResponseData
5263

0 commit comments

Comments
 (0)