Skip to content

Commit 48facea

Browse files
committed
doc: update readme
1 parent cf8a52b commit 48facea

File tree

5 files changed

+89
-9
lines changed

5 files changed

+89
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ try {
9191
- [ChatCompletions](guides/Features.md#chatcompletions)
9292
- [ImageGenerations](guides/Features.md#imagegenerations)
9393
- [Edits](guides/Features.md#edits)
94+
- [AudioTranscriptions](guides/Features.md#audioTranscriptions)
9495

9596
## ℹ️ Sample apps
9697

guides/Features.md

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [ChatCompletions](#chatcompletions)
77
- [ImageGenerations](#imagegenerations)
88
- [Edits](#edits)
9+
- [AudioTranscriptions](#audioTranscriptions)
910

1011
## ListModels
1112

@@ -88,7 +89,7 @@ do {
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.
@@ -131,7 +132,7 @@ do {
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.
@@ -174,7 +175,7 @@ do {
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.
@@ -214,7 +215,7 @@ do {
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
```

sample/jvm/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,19 @@ This endpoint retrieve the artificial intelligence model based on the given ID.
9191

9292
##### Example:
9393

94-
`GET http://localhost:8080/api/ychat/models/babbage`
94+
`GET http://localhost:8080/api/ychat/models/babbage`
95+
96+
### Audio Transcriptions Endpoint
97+
98+
This endpoint transcribes audio into the input language.
99+
100+
##### Endpoint: http://localhost:[port_number]/api/ychat/audio/transcriptions
101+
102+
##### Example:
103+
104+
```
105+
curl -X POST \
106+
-H "Content-Type: multipart/form-data" \
107+
-F "file=@/path/to/audio/file" \
108+
"http://localhost:8080/api/ychat/audio/transcriptions"
109+
```

ychat/src/commonMain/kotlin/co/yml/ychat/YChat.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ interface YChat {
138138
*/
139139
fun edits(): Edits
140140

141+
/**
142+
* The audioTranscriptions api is used to transcribes audio into the input language.
143+
*
144+
* You can configure the parameters of the edits before executing it. Example:
145+
* ```
146+
* val result = YChat.create(apiKey).audioTranscriptions()
147+
* .setTemperature(0.4)
148+
* .setResponseFormat("json")
149+
* .set...
150+
* .execute("file.mp4", byteArrayFile)
151+
* ```
152+
*/
141153
fun audioTranscriptions(): AudioTranscriptions
142154

143155
/**

ychat/src/commonTest/kotlin/co/yml/ychat/entrypoint/YChatTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class YChatTest {
159159
.setTemperature(0.0)
160160
.setModel("model-1")
161161
.setPrompt("Test")
162+
.setResponseFormat("json")
162163
.execute("file.mp4", audioFile)
163164
}
164165

0 commit comments

Comments
 (0)