Skip to content

Commit 1c5325c

Browse files
authored
Merge pull request #3 from tddworks/kotlin-2.2.21
2 parents 92bbe61 + f5b4518 commit 1c5325c

34 files changed

Lines changed: 440 additions & 436 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
![CI](https://github.com/tddworks/openai-kotlin/actions/workflows/main.yml/badge.svg)
44
[![codecov](https://codecov.io/gh/tddworks/openai-kotlin/graph/badge.svg?token=ZHqC4RjnCf)](https://codecov.io/gh/tddworks/openai-kotlin)
55
[![Maven Central](https://img.shields.io/maven-central/v/com.tddworks/openai-client-core?label=Maven%20Central)](https://central.sonatype.com/artifact/com.tddworks/openai-client-core)
6-
[![Kotlin](https://img.shields.io/badge/kotlin-2.2.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
6+
[![Kotlin](https://img.shields.io/badge/kotlin-2.2.21-blue.svg?logo=kotlin)](http://kotlinlang.org)
77
[![KMP](https://img.shields.io/badge/Kotlin-Multiplatform-blue.svg?logo=kotlin)](https://kotlinlang.org/docs/multiplatform.html)
8-
[![Ktor](https://img.shields.io/badge/ktor-3.2.3-blue.svg?logo=ktor)](https://ktor.io)
8+
[![Ktor](https://img.shields.io/badge/ktor-3.3.3-blue.svg?logo=ktor)](https://ktor.io)
99
[![License](https://img.shields.io/github/license/tddworks/openai-kotlin?color=blue)](LICENSE)
1010
[![GitHub Release](https://img.shields.io/github/v/release/tddworks/openai-kotlin?include_prereleases&label=Latest%20Release)](https://github.com/tddworks/openai-kotlin/releases)
1111
[![Issues](https://img.shields.io/github/issues/tddworks/openai-kotlin?color=blue)](https://github.com/tddworks/openai-kotlin/issues)

anthropic-client/anthropic-client-core/src/commonMain/kotlin/com/tddworks/anthropic/api/messages/api/Message.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,5 @@ sealed interface BlockMessageContent {
6060
)
6161
}
6262

63-
@Serializable
64-
@SerialName("text")
65-
data class TextContent(val text: String) : BlockMessageContent
63+
@Serializable @SerialName("text") data class TextContent(val text: String) : BlockMessageContent
6664
}

anthropic-client/anthropic-client-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/ContentTest.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ class ContentTest {
3838
// Then
3939
JSONAssert.assertEquals(
4040
"""
41-
[
42-
{
43-
"source": {
44-
"data": "image1_data",
45-
"media_type": "image1_media_type",
46-
"type": "base64"
47-
},
48-
"type": "image"
49-
},
50-
{
51-
"text": "some-text",
52-
"type": "text"
53-
}
54-
]
41+
[
42+
{
43+
"source": {
44+
"data": "image1_data",
45+
"media_type": "image1_media_type",
46+
"type": "base64"
47+
},
48+
"type": "image"
49+
},
50+
{
51+
"text": "some-text",
52+
"type": "text"
53+
}
54+
]
5555
"""
5656
.trimIndent(),
5757
result,

anthropic-client/anthropic-client-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/CreateMessageRequestTest.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ class CreateMessageRequestTest {
1919
fun `should convert request to correct json with multiple messages`() {
2020
val json =
2121
"""
22-
{
23-
"messages": [{
24-
"role": "user",
25-
"content": [{
26-
"type": "image",
27-
"source": {
28-
"type": "base64",
29-
"media_type": "123",
30-
"data": "23"
22+
{
23+
"messages": [{
24+
"role": "user",
25+
"content": [{
26+
"type": "image",
27+
"source": {
28+
"type": "base64",
29+
"media_type": "123",
30+
"data": "23"
31+
}
32+
},
33+
{
34+
"type": "text",
35+
"text": "Describe this image."
3136
}
32-
},
33-
{
34-
"type": "text",
35-
"text": "Describe this image."
36-
}
37-
]
38-
}],
39-
"system": null,
40-
"max_tokens": 1024,
41-
"model": "claude-3-haiku-20240307",
42-
"stream": null
43-
}
44-
"""
37+
]
38+
}],
39+
"system": null,
40+
"max_tokens": 1024,
41+
"model": "claude-3-haiku-20240307",
42+
"stream": null
43+
}
44+
"""
4545
.trimIndent()
4646

4747
val request =
@@ -95,7 +95,7 @@ class CreateMessageRequestTest {
9595
"model": "claude-3-haiku-20240307",
9696
"stream": null
9797
}
98-
"""
98+
"""
9999
.trimIndent()
100100

101101
val request =

anthropic-client/anthropic-client-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/internal/DefaultMessagesApiTest.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -295,25 +295,25 @@ class DefaultMessagesApiTest : KoinTest {
295295
httpClient =
296296
mockHttpClient(
297297
"""
298-
{
299-
"content": [
300-
{
301-
"text": "Hi! My name is Claude.",
302-
"type": "text"
303-
}
304-
],
305-
"id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
306-
"model": "claude-3-opus-20240229",
307-
"role": "assistant",
308-
"stop_reason": "end_turn",
309-
"stop_sequence": null,
310-
"type": "message",
311-
"usage": {
312-
"input_tokens": 10,
313-
"output_tokens": 25
314-
}
315-
}
316-
"""
298+
{
299+
"content": [
300+
{
301+
"text": "Hi! My name is Claude.",
302+
"type": "text"
303+
}
304+
],
305+
"id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
306+
"model": "claude-3-opus-20240229",
307+
"role": "assistant",
308+
"stop_reason": "end_turn",
309+
"stop_sequence": null,
310+
"type": "message",
311+
"usage": {
312+
"input_tokens": 10,
313+
"output_tokens": 25
314+
}
315+
}
316+
"""
317317
.trimIndent()
318318
)
319319
)

anthropic-client/anthropic-client-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/internal/TestKoinCoroutineExtension.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import org.junit.jupiter.api.extension.ExtensionContext
1212
class TestKoinCoroutineExtension(
1313
private val testDispatcher: TestDispatcher = StandardTestDispatcher()
1414
) : BeforeEachCallback, AfterEachCallback {
15-
override fun beforeEach(context: ExtensionContext?) {
15+
override fun beforeEach(context: ExtensionContext) {
1616
Dispatchers.setMain(testDispatcher)
1717
}
1818

19-
override fun afterEach(context: ExtensionContext?) {
19+
override fun afterEach(context: ExtensionContext) {
2020
Dispatchers.resetMain()
2121
}
2222
}

anthropic-client/anthropic-client-core/src/jvmTest/kotlin/com/tddworks/anthropic/api/messages/api/internal/json/StreamMessageResponseTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class StreamMessageResponseTest {
1515
{
1616
"type": "null"
1717
}
18-
"""
18+
"""
1919
.trimIndent()
2020

2121
val e =
@@ -33,7 +33,7 @@ class StreamMessageResponseTest {
3333
{
3434
"type": {}
3535
}
36-
"""
36+
"""
3737
.trimIndent()
3838

3939
val e =
@@ -54,7 +54,7 @@ class StreamMessageResponseTest {
5454
{
5555
"type": { "not-jsonPrimitive":"" }
5656
}
57-
"""
57+
"""
5858
.trimIndent()
5959

6060
assertThrows(IllegalArgumentException::class.java) {
@@ -69,7 +69,7 @@ class StreamMessageResponseTest {
6969
{
7070
"index": 1
7171
}
72-
"""
72+
"""
7373
.trimIndent()
7474

7575
assertThrows(IllegalArgumentException::class.java) {
@@ -85,7 +85,7 @@ class StreamMessageResponseTest {
8585
"type": "content_block_stop",
8686
"index": 1
8787
}
88-
"""
88+
"""
8989
.trimIndent()
9090

9191
val contentBlockStop = Json.decodeFromString<StreamMessageResponse>(json)
@@ -102,7 +102,7 @@ class StreamMessageResponseTest {
102102
{
103103
"type": "unknown"
104104
}
105-
"""
105+
"""
106106
.trimIndent()
107107

108108
assertThrows(IllegalArgumentException::class.java) {

common/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/DefaultHttpRequesterTest.kt

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ class DefaultHttpRequesterTest : AutoCloseKoinTest() {
4343
fun `should throw RateLimitException when status code is 401`(): Unit = runBlocking {
4444
val mockResponse =
4545
"""
46-
{
47-
"error": {
48-
"code": null,
49-
"type": "server_error",
50-
"param": null,
51-
"message": "You are accessing the API from an unsupported country, region, or territory."
46+
{
47+
"error": {
48+
"code": null,
49+
"type": "server_error",
50+
"param": null,
51+
"message": "You are accessing the API from an unsupported country, region, or territory."
52+
}
5253
}
53-
}
54-
"""
54+
"""
5555
.trimIndent()
5656

5757
httpClient =
@@ -71,15 +71,15 @@ class DefaultHttpRequesterTest : AutoCloseKoinTest() {
7171
fun `should throw RateLimitException when status code is 40x`(): Unit = runBlocking {
7272
val mockResponse =
7373
"""
74-
{
75-
"error": {
76-
"code": null,
77-
"type": "server_error",
78-
"param": null,
79-
"message": "You are accessing the API from an unsupported country, region, or territory."
74+
{
75+
"error": {
76+
"code": null,
77+
"type": "server_error",
78+
"param": null,
79+
"message": "You are accessing the API from an unsupported country, region, or territory."
80+
}
8081
}
81-
}
82-
"""
82+
"""
8383
.trimIndent()
8484

8585
httpClient =
@@ -99,15 +99,15 @@ class DefaultHttpRequesterTest : AutoCloseKoinTest() {
9999
fun `should throw RateLimitException when status code is unknown`(): Unit = runBlocking {
100100
val mockResponse =
101101
"""
102-
{
103-
"error": {
104-
"code": null,
105-
"type": "server_error",
106-
"param": null,
107-
"message": "You are accessing the API from an unsupported country, region, or territory."
102+
{
103+
"error": {
104+
"code": null,
105+
"type": "server_error",
106+
"param": null,
107+
"message": "You are accessing the API from an unsupported country, region, or territory."
108+
}
108109
}
109-
}
110-
"""
110+
"""
111111
.trimIndent()
112112

113113
httpClient =
@@ -127,15 +127,15 @@ class DefaultHttpRequesterTest : AutoCloseKoinTest() {
127127
fun `should throw RateLimitException when status code is 429`(): Unit = runBlocking {
128128
val mockResponse =
129129
"""
130-
{
131-
"error": {
132-
"code": null,
133-
"type": "server_error",
134-
"param": null,
135-
"message": "You are accessing the API from an unsupported country, region, or territory."
130+
{
131+
"error": {
132+
"code": null,
133+
"type": "server_error",
134+
"param": null,
135+
"message": "You are accessing the API from an unsupported country, region, or territory."
136+
}
136137
}
137-
}
138-
"""
138+
"""
139139
.trimIndent()
140140

141141
httpClient =
@@ -177,15 +177,15 @@ class DefaultHttpRequesterTest : AutoCloseKoinTest() {
177177
fun `should throw PermissionException when get 403`(): Unit = runBlocking {
178178
val mockResponse =
179179
"""
180-
{
181-
"error": {
182-
"code": null,
183-
"type": "server_error",
184-
"param": null,
185-
"message": "You are accessing the API from an unsupported country, region, or territory."
180+
{
181+
"error": {
182+
"code": null,
183+
"type": "server_error",
184+
"param": null,
185+
"message": "You are accessing the API from an unsupported country, region, or territory."
186+
}
186187
}
187-
}
188-
"""
188+
"""
189189
.trimIndent()
190190

191191
httpClient =
@@ -211,8 +211,10 @@ class DefaultHttpRequesterTest : AutoCloseKoinTest() {
211211
requester
212212
.streamRequest<StreamResponse> { url(path = "/v1/chat/completions") }
213213
.test {
214-
expectNoEvents()
215-
cancel()
214+
// - If items were emitted → you must call awaitItem() first →
215+
// awaitComplete() alone would fail
216+
// - If no items → awaitComplete() succeeds
217+
awaitComplete()
216218
}
217219
}
218220

@@ -257,7 +259,7 @@ class DefaultHttpRequesterTest : AutoCloseKoinTest() {
257259
"total_tokens": 21
258260
}
259261
}
260-
"""
262+
"""
261263
.trimIndent()
262264

263265
httpClient = mockHttpClient(mockResponse)

common/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/TestKoinCoroutineExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import org.junit.jupiter.api.extension.ExtensionContext
1212
class TestKoinCoroutineExtension(
1313
private val testDispatcher: TestDispatcher = StandardTestDispatcher()
1414
) : BeforeEachCallback, AfterEachCallback {
15-
override fun beforeEach(context: ExtensionContext?) {
15+
16+
override fun beforeEach(context: ExtensionContext) {
1617
Dispatchers.setMain(testDispatcher)
1718
}
1819

19-
override fun afterEach(context: ExtensionContext?) {
20+
override fun afterEach(context: ExtensionContext) {
2021
Dispatchers.resetMain()
2122
}
2223
}

0 commit comments

Comments
 (0)