Skip to content

Commit 5a7c83c

Browse files
committed
feat(BE-195): support darwin by kmmbridge
1 parent 149d4cc commit 5a7c83c

File tree

13 files changed

+286
-35
lines changed

13 files changed

+286
-35
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
plugins {
2+
alias(libs.plugins.kotlinx.serialization)
3+
alias(libs.plugins.touchlab.kmmbridge)
4+
alias(libs.plugins.touchlab.skie)
5+
`maven-publish`
6+
}
7+
8+
kotlin {
9+
listOf(
10+
macosArm64(),
11+
macosX64()
12+
).forEach { macosTarget ->
13+
macosTarget.binaries.framework {
14+
baseName = "anthropic-client-darwin"
15+
export(projects.anthropicClient.anthropicClientCore)
16+
isStatic = true
17+
}
18+
}
19+
20+
sourceSets {
21+
commonMain {
22+
dependencies {
23+
api(projects.anthropicClient.anthropicClientCore)
24+
implementation(libs.ktor.client.darwin)
25+
}
26+
}
27+
appleMain {}
28+
}
29+
}
30+
31+
addGithubPackagesRepository() // <- Add the GitHub Packages repo
32+
33+
kmmbridge {
34+
/**
35+
* reference: https://kmmbridge.touchlab.co/docs/artifacts/MAVEN_REPO_ARTIFACTS#github-packages
36+
* In kmmbridge, notice mavenPublishArtifacts() tells the plugin to push KMMBridge artifacts to a Maven repo. You then need to define a repo. Rather than do everything manually, you can just call addGithubPackagesRepository(), which will add the correct repo given parameters that are passed in from GitHub Actions.
37+
*/
38+
mavenPublishArtifacts() // <- Publish using a Maven repo
39+
spm(swiftToolVersion = "5.9")
40+
// spm {
41+
// swiftToolsVersion = "5.9"
42+
// platforms {
43+
// iOS("14")
44+
// macOS("13")
45+
// watchOS("7")
46+
// tvOS("14")
47+
// }
48+
// }
49+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.tddworks.anthropic.darwin.api
2+
3+
import com.tddworks.anthropic.api.Anthropic
4+
import com.tddworks.anthropic.api.AnthropicConfig
5+
import com.tddworks.anthropic.di.iniAnthropic
6+
7+
8+
/**
9+
* Object responsible for setting up and initializing the Anthropoc API client.
10+
*/
11+
object DarwinAnthropic {
12+
13+
/**
14+
* Initializes the Anthropic library with the provided configuration parameters.
15+
*
16+
* @param apiKey a lambda function that returns the API key to be used for authentication
17+
* @param baseUrl a lambda function that returns the base URL of the Anthropic API
18+
* @param anthropicVersion a lambda function that returns the version of the Anthropic API to use
19+
*/
20+
fun anthropic(
21+
apiKey: () -> String = { "CONFIG_API_KEY" },
22+
baseUrl: () -> String = { Anthropic.BASE_URL },
23+
anthropicVersion: () -> String = { Anthropic.ANTHROPIC_VERSION },
24+
) = iniAnthropic(AnthropicConfig(apiKey, baseUrl, anthropicVersion))
25+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ multiplatform-swiftpackage = "2.2.1"
2828

2929
touchlab-skie = "0.6.1"
3030

31-
touchlab-kmmbridge = "0.5.2"
31+
touchlab-kmmbridge = "0.5.4"
3232

3333
com-linecorp-build-recipe-plugin = "1.1.1"
3434

ollama-client/ollama-client-core/src/commonMain/kotlin/com/tddworks/ollama/di/Koin.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import org.koin.core.qualifier.named
1515
import org.koin.dsl.KoinAppDeclaration
1616
import org.koin.dsl.module
1717

18-
fun iniOllamaKoin(config: OllamaConfig, appDeclaration: KoinAppDeclaration = {}) =
19-
startKoin {
18+
fun iniOllama(config: OllamaConfig, appDeclaration: KoinAppDeclaration = {}): Ollama {
19+
return startKoin {
2020
appDeclaration()
2121
modules(commonModule(false) + ollamaModules(config))
22-
}
22+
}.koin.get<Ollama>()
23+
}
2324

2425
fun ollamaModules(
2526
config: OllamaConfig,

ollama-client/ollama-client-core/src/jvmTest/kotlin/com/tddworks/ollama/api/OllamaTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.tddworks.ollama.api
22

33
import com.tddworks.di.getInstance
4-
import com.tddworks.ollama.di.iniOllamaKoin
4+
import com.tddworks.ollama.di.iniOllama
55
import org.junit.jupiter.api.Assertions.assertEquals
66
import org.junit.jupiter.api.BeforeEach
77
import org.junit.jupiter.api.Test
@@ -11,7 +11,7 @@ class OllamaTestTest : AutoCloseKoinTest() {
1111

1212
@BeforeEach
1313
fun setUp() {
14-
iniOllamaKoin(
14+
iniOllama(
1515
config = OllamaConfig(
1616
baseUrl = { "127.0.0.1" },
1717
port = { 8080 },

ollama-client/ollama-client-core/src/jvmTest/kotlin/com/tddworks/ollama/api/internal/DefaultOllamaChatITest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.tddworks.ollama.api.Ollama
55
import com.tddworks.ollama.api.OllamaConfig
66
import com.tddworks.ollama.api.chat.OllamaChatMessage
77
import com.tddworks.ollama.api.chat.OllamaChatRequest
8-
import com.tddworks.ollama.di.iniOllamaKoin
8+
import com.tddworks.ollama.di.iniOllama
99
import kotlinx.coroutines.test.runTest
1010
import org.junit.jupiter.api.Assertions.assertEquals
1111
import org.junit.jupiter.api.Assertions.assertNotNull
@@ -19,7 +19,7 @@ class DefaultOllamaChatITest : AutoCloseKoinTest() {
1919

2020
@BeforeEach
2121
fun setUp() {
22-
iniOllamaKoin(
22+
iniOllama(
2323
config = OllamaConfig(
2424
protocol = { "http" },
2525
baseUrl = { "localhost" },
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
plugins {
2+
alias(libs.plugins.kotlinx.serialization)
3+
alias(libs.plugins.touchlab.kmmbridge)
4+
alias(libs.plugins.touchlab.skie)
5+
`maven-publish`
6+
}
7+
8+
kotlin {
9+
listOf(
10+
macosArm64(),
11+
macosX64()
12+
).forEach { macosTarget ->
13+
macosTarget.binaries.framework {
14+
baseName = "ollama-client-darwin"
15+
export(projects.ollamaClient.ollamaClientCore)
16+
isStatic = true
17+
}
18+
}
19+
20+
sourceSets {
21+
commonMain {
22+
dependencies {
23+
api(projects.ollamaClient.ollamaClientCore)
24+
implementation(libs.ktor.client.darwin)
25+
}
26+
}
27+
appleMain {}
28+
}
29+
}
30+
31+
addGithubPackagesRepository() // <- Add the GitHub Packages repo
32+
33+
kmmbridge {
34+
/**
35+
* reference: https://kmmbridge.touchlab.co/docs/artifacts/MAVEN_REPO_ARTIFACTS#github-packages
36+
* In kmmbridge, notice mavenPublishArtifacts() tells the plugin to push KMMBridge artifacts to a Maven repo. You then need to define a repo. Rather than do everything manually, you can just call addGithubPackagesRepository(), which will add the correct repo given parameters that are passed in from GitHub Actions.
37+
*/
38+
mavenPublishArtifacts() // <- Publish using a Maven repo
39+
spm(swiftToolVersion = "5.9")
40+
// spm {
41+
// swiftToolsVersion = "5.9"
42+
// platforms {
43+
// iOS("14")
44+
// macOS("13")
45+
// watchOS("7")
46+
// tvOS("14")
47+
// }
48+
// }
49+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.tddworks.ollama.api
2+
3+
import com.tddworks.ollama.di.iniOllama
4+
5+
6+
/**
7+
* Creates an instance of Ollama with the specified configuration options.
8+
*
9+
* @param port a function that returns the port number for the Ollama instance, defaults to Ollama.PORT
10+
* @param protocol a function that returns the protocol for the Ollama instance, defaults to Ollama.PROTOCOL
11+
* @param baseUrl a function that returns the base URL for the Ollama instance, defaults to Ollama.BASE_URL
12+
* @return an Ollama instance initialized with the provided configuration
13+
*/
14+
object DarwinOllama {
15+
16+
/**
17+
* Function to create an Ollama instance with the provided configuration.
18+
*
19+
* @param port function returning an integer representing the port, defaults to Ollama.PORT
20+
* @param protocol function returning a string representing the protocol, defaults to Ollama.PROTOCOL
21+
* @param baseUrl function returning a string representing the base URL, defaults to Ollama.BASE_URL
22+
* @return an Ollama instance created with the provided configuration
23+
*/
24+
fun ollama(
25+
port: () -> Int = { Ollama.PORT },
26+
protocol: () -> String = { Ollama.PROTOCOL },
27+
baseUrl: () -> String = { Ollama.BASE_URL },
28+
): Ollama = iniOllama(OllamaConfig(baseUrl = baseUrl, port = port, protocol = protocol))
29+
}

openai-client/openai-client-darwin/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ kmmbridge {
3636
* In kmmbridge, notice mavenPublishArtifacts() tells the plugin to push KMMBridge artifacts to a Maven repo. You then need to define a repo. Rather than do everything manually, you can just call addGithubPackagesRepository(), which will add the correct repo given parameters that are passed in from GitHub Actions.
3737
*/
3838
mavenPublishArtifacts() // <- Publish using a Maven repo
39-
// spm()
39+
spm(swiftToolVersion = "5.9")
4040
// spm {
4141
// swiftToolsVersion = "5.9"
4242
// platforms {
43-
// iOS { v("14") }
44-
// macOS { v("13") }
45-
// watchOS { v("7") }
46-
// tvOS { v("14") }
43+
// iOS("14")
44+
// macOS("13")
45+
// watchOS("7")
46+
// tvOS("14")
4747
// }
4848
// }
4949
}
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
package com.tddworks.openai.darwin.api
22

33
import com.tddworks.openai.api.OpenAI
4-
import com.tddworks.openai.api.OpenAIApi
4+
import com.tddworks.openai.api.OpenAIConfig
5+
import com.tddworks.openai.di.initOpenAI
56

7+
/**
8+
* Object for accessing OpenAI API functions
9+
*/
610
object DarwinOpenAI {
7-
/**
8-
* Create an instance of OpenAI with the Darwin engine.
9-
* @param token The API token to use for authentication.
10-
* @return An instance of OpenAI.
11-
*/
12-
fun create(token: String): OpenAI = OpenAIApi()
13-
14-
/**
15-
* Create an instance of OpenAI with the Darwin engine.
16-
* @param token A function that returns the API token to use for authentication.
17-
* @param url A function that returns the base URL of the API.
18-
* @return An instance of OpenAI.
19-
*/
20-
fun create(token: String, url: String) = OpenAIApi()
21-
2211

2312
/**
24-
* Create an instance of OpenAI with the Darwin engine.
25-
* @param token A function that returns the API token to use for authentication.
26-
* @param url A function that returns the base URL of the API.
27-
* @return An instance of OpenAI.
13+
* Function to initialize the OpenAI API client with the given API key and base URL.
14+
*
15+
* @param apiKey A lambda function that returns the API key to be used for authentication. Defaults to "CONFIG_API_KEY".
16+
* @param baseUrl A lambda function that returns the base URL of the OpenAI API. Defaults to the constant OpenAI.BASE_URL.
2817
*/
29-
fun create(token: () -> String, url: () -> String): OpenAI = OpenAIApi()
18+
fun openAI(
19+
apiKey: () -> String = { "CONFIG_API_KEY" },
20+
baseUrl: () -> String = { OpenAI.BASE_URL },
21+
) = initOpenAI(OpenAIConfig(apiKey, baseUrl))
3022
}

0 commit comments

Comments
 (0)