66- [ ChatCompletions] ( #chatcompletions )
77- [ ImageGenerations] ( #imagegenerations )
88- [ Edits] ( #edits )
9+ - [ AudioTranscriptions] ( #audioTranscriptions )
910
1011## ListModels
1112
8889 let result = try await yChat.completion ()
8990 .setInput (input : " Say this is a test." )
9091 .setMaxTokens (tokens : 1024 )
91- .set ... // you can set more parameters
92+ .set // you can set more parameters
9293 .execute ()
9394} catch {
9495 // catch any error that may occurs on api call.
@@ -106,7 +107,7 @@ try {
106107 val result = yChat.completion()
107108 .setInput(" Say this is a test." )
108109 .setMaxTokens(1024 )
109- .set.. . // you can set more parameters
110+ .set // you can set more parameters
110111 .execute()
111112} catch (e: exception) {
112113 // catch any error that may occurs on api call.
131132 role : " assistant" ,
132133 content : " You are a helpful assistant that only answers questions related to fitness"
133134 )
134- .set ... // you can set more parameters
135+ .set // you can set more parameters
135136 .execute (content : " What is the best exercise for building muscle?" )
136137} catch {
137138 // catch any error that may occurs on api call.
@@ -152,7 +153,7 @@ try {
152153 role = " assistant" ,
153154 content = " You are a helpful assistant that only answers questions related to fitness"
154155 )
155- .set.. . // you can set more parameters
156+ .set // you can set more parameters
156157 .execute(" What is the best exercise for building muscle?" )
157158} catch (e: exception) {
158159 // catch any error that may occurs on api call.
174175 let result = try await yChat.imageGenerations ()
175176 .setResults (results : 2 )
176177 .setSize (size : " 1024x1024" )
177- .set ... // you can set more parameters
178+ .set // you can set more parameters
178179 .execute (prompt : " ocean" )
179180} catch {
180181 // catch any error that may occurs on api call.
@@ -192,7 +193,7 @@ try {
192193 val result = yChat.imageGenerations()
193194 .setResults(2 )
194195 .setSize(" 1024x1024" )
195- .set.. . // you can set more parameters
196+ .set // you can set more parameters
196197 .execute(" ocean" )
197198} catch (e: exception) {
198199 // catch any error that may occurs on api call.
214215 let result = try await yChat.edits ()
215216 .setInput (input : " What day of the wek is it?" )
216217 .setResults (result : 1 )
217- .set ... // you can set more parameters
218+ .set // you can set more parameters
218219 .execute (instruction : " Fix the spelling mistakes" )
219220} catch {
220221 // catch any error that may occurs on api call.
@@ -232,9 +233,59 @@ try {
232233 val result = yChat.edits()
233234 .setInput(" What day of the wek is it?" )
234235 .setResults(1 )
235- .set.. . // you can set more parameters
236+ .set // you can set more parameters
236237 .execute(" Fix the spelling mistakes" )
237238} catch (e: exception) {
238239 // catch any error that may occurs on api call.
239240}
241+ ```
242+
243+ ## AudioTranscriptions
244+
245+ The audioTranscriptions api is used to transcribes audio into the input language.
246+
247+ ### Swift
248+
249+ ``` swift
250+ var yChat: YChat {
251+ YChatCompanion.shared .create (apiKey : " your-api-key" )
252+ }
253+
254+ guard let audioFileUrl = Bundle.main.url (forResource : " audio" , withExtension : " m4a" ) else {
255+ print (" Unable to find the audio file." )
256+ return
257+ }
258+
259+ let audioData = try ! Data (contentsOf : audioFileUrl)
260+
261+ do {
262+ let result = try await yChat.audioTranscriptions ()
263+ .setTemperature (temperature : 0.4 )
264+ .setResponseFormat (format : " json" )
265+ .set // you can set more parameters
266+ .execute (filename : " audio.m4a" , audioFile : audioData)
267+ } catch {
268+ // catch any error that may occurs on api call.
269+ }
270+ ```
271+
272+ ### Kotlin
273+
274+ ``` kotlin
275+ val yChat by lazy {
276+ YChat .create(" your-api-key" )
277+ }
278+
279+ val inputStream = application.resources.openRawResource(R .raw.audio)
280+ val byteArray = inputStream.readBytes()
281+
282+ try {
283+ val result = yChat.audioTranscriptions()
284+ .setTemperature(0.4 )
285+ .setResponseFormat(" json" )
286+ .set // you can set more parameters
287+ .execute(" audio.m4a" , byteArray)
288+ } catch (e: exception) {
289+ // catch any error that may occurs on api call.
290+ }
240291```
0 commit comments