Skip to content

Commit a44f235

Browse files
committed
add latestVersion to support the latest date version
1 parent ea71df3 commit a44f235

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

openai-java-core/src/main/kotlin/com/openai/azure/AzureOpenAIServiceVersion.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package com.openai.azure
22

3+
import java.time.LocalDate
4+
import java.time.format.DateTimeFormatter
35
import java.util.concurrent.ConcurrentHashMap
46

57
class AzureOpenAIServiceVersion private constructor(@get:JvmName("value") val value: String) {
68

79
companion object {
810
private val values: ConcurrentHashMap<String, AzureOpenAIServiceVersion> =
911
ConcurrentHashMap()
12+
private val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
13+
14+
private fun extractDate(version: String): LocalDate {
15+
return LocalDate.parse(version, dateFormatter)
16+
}
1017

1118
@JvmStatic
1219
fun latestStableVersion(): AzureOpenAIServiceVersion {
@@ -20,6 +27,15 @@ class AzureOpenAIServiceVersion private constructor(@get:JvmName("value") val va
2027
return V2025_01_01_PREVIEW
2128
}
2229

30+
@JvmStatic
31+
fun latestVersion(): AzureOpenAIServiceVersion {
32+
val stableVersion = latestStableVersion()
33+
val previewVersion = latestPreviewVersion()
34+
val stableDate = extractDate(stableVersion.value)
35+
val previewDate = extractDate(previewVersion.value.substring(0, 10))
36+
return if (stableDate.isAfter(previewDate)) stableVersion else previewVersion
37+
}
38+
2339
@JvmStatic
2440
fun fromString(version: String): AzureOpenAIServiceVersion =
2541
values.computeIfAbsent(version) { AzureOpenAIServiceVersion(version) }

openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private constructor(
262262
// specific a service API version in 'queryParams'.
263263
replaceQueryParams(
264264
"api-version",
265-
(azureServiceVersion ?: AzureOpenAIServiceVersion.latestStableVersion()).value
265+
(azureServiceVersion ?: AzureOpenAIServiceVersion.latestVersion()).value,
266266
)
267267
}
268268

0 commit comments

Comments
 (0)