Skip to content

Commit 573b6a5

Browse files
committed
refactor: Code Formatting with Spotless and update to latest version
1 parent a33ba61 commit 573b6a5

File tree

220 files changed

+3749
-4493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+3749
-4493
lines changed
Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,82 @@
1-
name: build and publish a release to Central Sonatype
1+
name: Release to Central Sonatype
22

3-
#on:
4-
# release:
5-
# types: [published]
3+
# Release workflow for publishing OpenAI Kotlin SDK to Maven Central via Sonatype Portal
4+
#
5+
# Triggers:
6+
# - Manual trigger with version input (e.g., 1.0.0, 1.1.0-beta.1)
7+
# - Automatically creates git tag and GitHub release
8+
# - Publishes to Maven Central via Central Sonatype Portal
9+
#
10+
# Process:
11+
# 1. Validate version format (semantic versioning)
12+
# 2. Build and test with specified version
13+
# 3. Create git tag and GitHub release
14+
# 4. Publish to Maven Central via Sonatype Portal
615

716
on:
817
workflow_dispatch:
18+
inputs:
19+
version:
20+
description: 'Release version (e.g., 1.0.0, 1.1.0-beta.1)'
21+
required: true
22+
type: string
923

1024
jobs:
11-
build:
25+
# Build, test and publish the SDK to Maven Central
26+
release:
1227
runs-on: macOS-latest
13-
env:
14-
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
15-
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
16-
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
17-
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
28+
permissions:
29+
contents: write
30+
actions: read
1831
steps:
1932
- name: Checkout sources
2033
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
2137
- name: Setup Java
2238
uses: actions/setup-java@v4
2339
with:
24-
distribution: zulu
40+
distribution: 'temurin'
2541
java-version: 17
42+
2643
- name: Setup Gradle
27-
uses: gradle/gradle-build-action@v3
28-
- name: Release to Central Sonatype with Gradle
29-
run: ./gradlew build publishAggregationPublicationsToSonatypePortalRepository
44+
uses: gradle/actions/setup-gradle@v4
45+
46+
- name: Validate version format
47+
run: |
48+
if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
49+
echo "❌ Invalid version format. Use semantic versioning (e.g., 1.0.0, 1.1.0-beta.1)"
50+
exit 1
51+
fi
52+
echo "✅ Version format is valid: ${{ inputs.version }}"
53+
54+
- name: Build and test with release version
55+
run: ./gradlew clean build koverVerify -PLIBRARY_VERSION=${{ inputs.version }}
56+
57+
- name: Code quality checks
58+
run: ./gradlew spotlessCheck buildHealth -PLIBRARY_VERSION=${{ inputs.version }}
59+
60+
- name: Create git tag
61+
run: |
62+
git config user.name "github-actions[bot]"
63+
git config user.email "github-actions[bot]@users.noreply.github.com"
64+
git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}"
65+
git push origin "v${{ inputs.version }}"
66+
67+
- name: Create GitHub Release
68+
uses: softprops/action-gh-release@v1
69+
with:
70+
tag_name: v${{ inputs.version }}
71+
name: v${{ inputs.version }}
72+
draft: false
73+
prerelease: ${{ contains(inputs.version, '-') }}
74+
generate_release_notes: true
75+
76+
- name: Publish to Maven Central via Sonatype Portal
77+
run: ./gradlew publishToCentral -PLIBRARY_VERSION=${{ inputs.version }}
78+
env:
79+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
80+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
81+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
82+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}

anthropic-client/anthropic-client-core/build.gradle.kts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ kotlin {
2121
api(projects.common)
2222
}
2323

24-
macosMain.dependencies {
25-
api(libs.ktor.client.darwin)
26-
}
24+
macosMain.dependencies { api(libs.ktor.client.darwin) }
2725

28-
jvmMain.dependencies {
29-
api(libs.ktor.client.cio)
30-
}
26+
jvmMain.dependencies { api(libs.ktor.client.cio) }
3127

3228
jvmTest.dependencies {
3329
implementation(project.dependencies.platform(libs.junit.bom))
@@ -44,8 +40,4 @@ kotlin {
4440
}
4541
}
4642

47-
tasks {
48-
named<Test>("jvmTest") {
49-
useJUnitPlatform()
50-
}
51-
}
43+
tasks { named<Test>("jvmTest") { useJUnitPlatform() } }

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,32 @@ import com.tddworks.anthropic.api.messages.api.internal.JsonLenient
77
import com.tddworks.common.network.api.ktor.api.HttpRequester
88
import com.tddworks.common.network.api.ktor.internal.*
99

10-
/**
11-
* Interface for interacting with the Anthropic API.
12-
*/
10+
/** Interface for interacting with the Anthropic API. */
1311
interface Anthropic : Messages {
1412

15-
/**
16-
* Companion object containing a constant variable for the base URL of the API.
17-
*/
13+
/** Companion object containing a constant variable for the base URL of the API. */
1814
companion object {
1915
const val BASE_URL = "https://api.anthropic.com"
2016
const val ANTHROPIC_VERSION = "2023-06-01"
2117

2218
/**
2319
* Creates an instance of Anthropic API with the provided configurations.
20+
*
2421
* @return an instance of Anthropic API configured with the provided settings.
2522
*/
2623
fun create(anthropicConfig: AnthropicConfig): Anthropic {
2724

28-
val requester = HttpRequester.default(
29-
createHttpClient(
30-
connectionConfig = UrlBasedConnectionConfig(anthropicConfig.baseUrl),
31-
authConfig = AuthConfig(anthropicConfig.apiKey),
32-
// get from commonModule
33-
features = ClientFeatures(json = JsonLenient)
25+
val requester =
26+
HttpRequester.default(
27+
createHttpClient(
28+
connectionConfig = UrlBasedConnectionConfig(anthropicConfig.baseUrl),
29+
authConfig = AuthConfig(anthropicConfig.apiKey),
30+
// get from commonModule
31+
features = ClientFeatures(json = JsonLenient),
32+
)
3433
)
35-
)
36-
val messages = DefaultMessagesApi(
37-
anthropicConfig = anthropicConfig,
38-
requester = requester
39-
)
34+
val messages =
35+
DefaultMessagesApi(anthropicConfig = anthropicConfig, requester = requester)
4036

4137
return AnthropicApi(anthropicConfig = anthropicConfig, messages = messages)
4238
}
@@ -57,11 +53,10 @@ interface Anthropic : Messages {
5753
fun baseUrl(): String
5854

5955
/**
60-
* Returns the anthropic version of the provided class.
61-
* The anthropic version is a String representation of the class name with "Anthropic"
62-
* prefixed to it.
56+
* Returns the anthropic version of the provided class. The anthropic version is a String
57+
* representation of the class name with "Anthropic" prefixed to it.
6358
*
6459
* @return The anthropic version of the class as a String.
6560
*/
6661
fun anthropicVersion(): String
67-
}
62+
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package com.tddworks.anthropic.api
33
import org.koin.core.component.KoinComponent
44

55
/**
6-
* @param apiKey a function that returns the API key to be used for authentication. Defaults to "CONFIGURE_ME" if not provided.
7-
* @param baseUrl a function that returns the base URL of the API. Defaults to the value specified in the Anthropic companion object if not provided.
8-
* @param anthropicVersion a function that returns the version of the Anthropic API to be used. Defaults to "2023-06-01" if not provided.
6+
* @param apiKey a function that returns the API key to be used for authentication. Defaults to
7+
* "CONFIGURE_ME" if not provided.
8+
* @param baseUrl a function that returns the base URL of the API. Defaults to the value specified
9+
* in the Anthropic companion object if not provided.
10+
* @param anthropicVersion a function that returns the version of the Anthropic API to be used.
11+
* Defaults to "2023-06-01" if not provided.
912
*/
1013
data class AnthropicConfig(
1114
val apiKey: () -> String = { "CONFIG_API_KEY" },
1215
val baseUrl: () -> String = { Anthropic.BASE_URL },
1316
val anthropicVersion: () -> String = { Anthropic.ANTHROPIC_VERSION },
1417
) : KoinComponent
15-
16-
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
package com.tddworks.anthropic.api
22

3-
import kotlinx.serialization.Serializable
43
import kotlin.jvm.JvmInline
4+
import kotlinx.serialization.Serializable
55

66
/**
77
* https://docs.anthropic.com/claude/docs/models-overview
8-
* https://docs.anthropic.com/en/docs/about-claude/models
9-
* Claude is a family of state-of-the-art large language models developed by Anthropic. Our models are designed to provide you with the best possible experience when interacting with AI, offering a range of capabilities and performance levels to suit your needs and make it easy to deploy high performing, safe, and steerable models. In this guide, we'll introduce you to our latest and greatest models, the Claude 3 family, as well as our legacy models, which are still available for those who need them.
8+
* https://docs.anthropic.com/en/docs/about-claude/models Claude is a family of state-of-the-art
9+
* large language models developed by Anthropic. Our models are designed to provide you with the
10+
* best possible experience when interacting with AI, offering a range of capabilities and
11+
* performance levels to suit your needs and make it easy to deploy high performing, safe, and
12+
* steerable models. In this guide, we'll introduce you to our latest and greatest models, the
13+
* Claude 3 family, as well as our legacy models, which are still available for those who need them.
1014
*/
1115
@Serializable
1216
@JvmInline
1317
value class AnthropicModel(val value: String) {
1418
companion object {
1519
/**
16-
* Most powerful model for highly complex tasks
17-
* Max output length: 4096 tokens
18-
* Cost (Input / Output per MTok^) $15.00 / $75.00
20+
* Most powerful model for highly complex tasks Max output length: 4096 tokens Cost (Input /
21+
* Output per MTok^) $15.00 / $75.00
1922
*/
2023
val CLAUDE_3_OPUS = AnthropicModel("claude-3-opus-20240229")
2124

2225
/**
23-
* Ideal balance of intelligence and speed for enterprise workloads
24-
* Max output length: 4096 tokens
25-
* Cost (Input / Output per MTok^) $3.00 / $15.00
26+
* Ideal balance of intelligence and speed for enterprise workloads Max output length: 4096
27+
* tokens Cost (Input / Output per MTok^) $3.00 / $15.00
2628
*/
2729
val CLAUDE_3_Sonnet = AnthropicModel("claude-3-sonnet-20240229")
2830

2931
/**
30-
* Most intelligent model
31-
* The model costs $3 per million input tokens and $15 per million output tokens, with a 200K token context window.
32-
* Cost (Input / Output per MTok^) $3.00 / $15.00
33-
* Training data cut-off: Apr 2024
32+
* Most intelligent model The model costs $3 per million input tokens and $15 per million
33+
* output tokens, with a 200K token context window. Cost (Input / Output per MTok^) $3.00 /
34+
* $15.00 Training data cut-off: Apr 2024
3435
*/
3536
val CLAUDE_3_5_Sonnet = AnthropicModel("claude-3-5-sonnet-20240620")
3637

3738
/**
38-
* Fastest and most compact model for near-instant responsiveness
39-
* Max output length: 4096 tokens
40-
* Cost (Input / Output per MTok^) $0.25 / $1.25
39+
* Fastest and most compact model for near-instant responsiveness Max output length: 4096
40+
* tokens Cost (Input / Output per MTok^) $0.25 / $1.25
4141
*/
4242
val CLAUDE_3_HAIKU = AnthropicModel("claude-3-haiku-20240307")
4343

4444
val availableModels =
4545
listOf(CLAUDE_3_OPUS, CLAUDE_3_Sonnet, CLAUDE_3_HAIKU, CLAUDE_3_5_Sonnet)
4646
}
47-
}
47+
}

anthropic-client/anthropic-client-core/src/commonMain/kotlin/com/tddworks/anthropic/api/internal/AnthropicApi.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import com.tddworks.anthropic.api.AnthropicConfig
55
import com.tddworks.anthropic.api.messages.api.Messages
66
import com.tddworks.di.getInstance
77

8-
98
/**
10-
* The Anthropic API class encapsulates the necessary properties and methods to interact with the Anthropic API.
9+
* The Anthropic API class encapsulates the necessary properties and methods to interact with the
10+
* Anthropic API.
1111
*
1212
* @property apiKey the unique identifier for your Anthropic API account
1313
* @property apiURL the base URL for making API requests to the Anthropic API
1414
* @property anthropicVersion the version of the Anthropics library being used
1515
*/
1616
class AnthropicApi(
1717
private val anthropicConfig: AnthropicConfig,
18-
private val messages: Messages = getInstance()
18+
private val messages: Messages = getInstance(),
1919
) : Anthropic, Messages by messages {
2020
/**
2121
* Gets the API key.
@@ -43,13 +43,11 @@ class AnthropicApi(
4343
override fun anthropicVersion(): String {
4444
return anthropicConfig.anthropicVersion()
4545
}
46-
4746
}
4847

4948
fun Anthropic.Companion.create(
50-
anthropicConfig: AnthropicConfig, messages: Messages = getInstance()
49+
anthropicConfig: AnthropicConfig,
50+
messages: Messages = getInstance(),
5151
): Anthropic {
52-
return AnthropicApi(
53-
anthropicConfig = anthropicConfig, messages = messages
54-
)
55-
}
52+
return AnthropicApi(anthropicConfig = anthropicConfig, messages = messages)
53+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ package com.tddworks.anthropic.api.messages.api
22

33
import kotlinx.serialization.Serializable
44

5-
@Serializable
6-
data class ContentMessage(val text: String, val type: String)
5+
@Serializable data class ContentMessage(val text: String, val type: String)

0 commit comments

Comments
 (0)