Skip to content

Commit 48773dc

Browse files
author
Robert Winkler
committed
Add Spring Boot starter
1 parent af4b4ad commit 48773dc

File tree

20 files changed

+263
-249
lines changed

20 files changed

+263
-249
lines changed

.github/workflows/gradle-publish.yml

Lines changed: 0 additions & 125 deletions
This file was deleted.

.github/workflows/gradle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ name: Java CI with Gradle
1313

1414
on:
1515
push:
16-
branches: [ "main" ]
16+
branches: [ "master" ]
1717
pull_request:
18-
branches: [ "main" ]
18+
branches: [ "master" ]
1919

2020
jobs:
2121
validation:

kotlin-wot-binding-http/src/main/kotlin/http/HttpProtocolServer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ open class HttpProtocolServer(
6060
// Stop the server
6161
override suspend fun stop() {
6262
if (!started) throw ProtocolServerException("Server has not started yet")
63-
log.info("Stopping on '{}' port '{}'", bindHost, bindPort)
63+
log.info("Stopping HttpProtocolServer")
6464
server?.stop(1000, 2000)
6565
started = false
6666
}
@@ -69,7 +69,7 @@ open class HttpProtocolServer(
6969
override suspend fun expose(thing: ExposedThing) {
7070
if (!started) throw ProtocolServerException("Server has not started yet")
7171

72-
log.info("Exposing thing '{}'", thing.id)
72+
log.info("Exposing thing '{}' on HttpProtocolServer", thing.id)
7373
things[thing.id] = thing
7474

7575
for (address in actualAddresses) {

kotlin-wot-binding-mqtt/src/main/kotlin/mqtt/MqttClientConfig.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ data class MqttClientConfig(val host: String,
66
val port: Int,
77
val clientId: String = UUID.randomUUID().toString(),
88
private val username: String? = null,
9-
private val password: String? = null) {
10-
}
9+
private val password: String? = null)
1110

kotlin-wot-binding-mqtt/src/main/kotlin/mqtt/MqttProtocolServer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class MqttProtocolServer(
5656
if (!started) throw ProtocolServerException("Server has not started yet")
5757

5858
val baseUrl = createUrl()
59-
log.info("MqttServer exposes '{}' at '{}{}/*'", thing.id, baseUrl, thing.id)
59+
log.debug("MqttServer exposes '{}' at '{}{}/*'", thing.id, baseUrl, thing.id)
6060

6161
things[thing.id] = thing
6262
exposeProperties(thing, baseUrl)

kotlin-wot-integration-tests/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ dependencies {
99
api(project(":kotlin-wot-binding-http"))
1010
api(project(":kotlin-wot-binding-mqtt"))
1111
api(project(":kotlin-wot-reflection"))
12-
implementation("ai.ancf.lmos:arc-agents:0.111.0")
13-
//implementation("ai.ancf.lmos:arc-langchain4j-client:0.111.0")
14-
implementation("org.springframework.boot:spring-boot-starter")
15-
implementation("org.springframework.boot:spring-boot-starter-logging")
16-
12+
api(project(":kotlin-wot-spring-boot-starter"))
1713
implementation("ai.ancf.lmos:arc-azure-client:0.111.0")
18-
implementation("ai.ancf.lmos:arc-spring-boot-starter:0.111.0")
1914

2015
//implementation("dev.langchain4j:langchain4j-azure-open-ai:0.35.0")
2116
//implementation("dev.langchain4j:langchain4j:0.35.0")
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ai.ancf.lmos.wot.integration
22

33
import ai.ancf.lmos.arc.spring.Agents
4-
import ai.ancf.lmos.wot.Wot
54
import org.springframework.context.annotation.Bean
65
import org.springframework.context.annotation.Configuration
76

@@ -15,12 +14,4 @@ class AgentConfiguration {
1514
prompt { "you are a helpful weather agent." }
1615
model = { "GPT-4o" }
1716
}
18-
19-
@Bean
20-
fun servient() = createServient("HTTP")
21-
22-
@Bean
23-
fun wot() = Wot.create(servient())
24-
25-
2617
}
Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,15 @@
11
package ai.ancf.lmos.wot.integration
22

3-
import ai.ancf.lmos.wot.Servient
4-
import ai.ancf.lmos.wot.Wot
5-
import ai.ancf.lmos.wot.reflection.ExposedThingBuilder
6-
import ai.ancf.lmos.wot.thing.schema.WoTExposedThing
7-
import jakarta.annotation.PreDestroy
8-
import kotlinx.coroutines.Job
9-
import kotlinx.coroutines.runBlocking
10-
import org.slf4j.Logger
11-
import org.slf4j.LoggerFactory
12-
import org.springframework.beans.factory.annotation.Autowired
13-
import org.springframework.boot.CommandLineRunner
143
import org.springframework.boot.autoconfigure.SpringBootApplication
154
import org.springframework.boot.runApplication
5+
import spring.ThingRuntime
166

177

188
fun main(args: Array<String>) {
199
runApplication<ThingAgentApplication>(*args)
2010
}
2111

2212
@SpringBootApplication
23-
class ThingAgentApplication : CommandLineRunner {
13+
class ThingAgentApplication : ThingRuntime() {
2414

25-
@Autowired
26-
private lateinit var servient: Servient
27-
28-
@Autowired
29-
private lateinit var wot: Wot
30-
31-
@Autowired
32-
private lateinit var agent: ThingAgent
33-
34-
companion object {
35-
private val log: Logger = LoggerFactory.getLogger(ThingAgentApplication::class.java)
36-
}
37-
38-
@PreDestroy
39-
fun onExit() {
40-
// Register a shutdown hook
41-
log.debug("Application is shutting down. Performing cleanup...")
42-
runBlocking { servient.shutdown() }
43-
}
44-
45-
override fun run(vararg args: String?) = runBlocking {
46-
47-
// Protocol can be "HTTP" or "MQTT"
48-
val servient = createServient("HTTP")
49-
50-
val wot = Wot.create(servient)
51-
val exposedThing = ExposedThingBuilder.createExposedThing(wot, agent, ThingAgent::class)
52-
53-
// Start `servient` in a separate coroutine
54-
servient.start()
55-
// Add and expose the thing after `start()` has had time to begin
56-
servient.addThing(exposedThing as WoTExposedThing)
57-
servient.expose("agent")
58-
59-
println("Exposed Agent on HTTP Server")
60-
Job().join()
61-
}
6215
}
63-

kotlin-wot-integration-tests/src/main/kotlin/integration/ThingAgent.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package ai.ancf.lmos.wot.integration
22

33
import ai.ancf.lmos.arc.agents.AgentProvider
44
import ai.ancf.lmos.arc.agents.ChatAgent
5-
import ai.ancf.lmos.arc.agents.User
65
import ai.ancf.lmos.arc.agents.conversation.AssistantMessage
6+
import ai.ancf.lmos.arc.agents.conversation.Conversation
77
import ai.ancf.lmos.arc.agents.conversation.latest
8-
import ai.ancf.lmos.arc.agents.conversation.toConversation
98
import ai.ancf.lmos.arc.agents.getAgentByName
109
import ai.ancf.lmos.arc.core.getOrThrow
1110
import ai.ancf.lmos.wot.reflection.annotations.*
@@ -19,11 +18,12 @@ import org.springframework.stereotype.Component
1918
description= "A simple agent.")
2019
@VersionInfo(instance = "1.0.0")
2120
@Component
22-
class ThingAgent(val agentProvider: AgentProvider, @Property(name = "modelTemperature", readOnly = true)
21+
class ThingAgent(agentProvider: AgentProvider, @Property(name = "modelTemperature", readOnly = true)
2322
val modelConfiguration: ModelConfiguration = ModelConfiguration(0.5, 50)) {
2423

2524
private val messageFlow = MutableSharedFlow<String>(replay = 1) // Replay last emitted value
2625

26+
val agent = agentProvider.getAgentByName("My Agent") as ChatAgent
2727

2828
/*
2929
private val model: AzureOpenAiChatModel = AzureOpenAiChatModel.builder()
@@ -38,9 +38,7 @@ class ThingAgent(val agentProvider: AgentProvider, @Property(name = "modelTemper
3838
val observableProperty : MutableStateFlow<String> = MutableStateFlow("Hello World")
3939

4040
@Action(name = "ask", title = "Ask", description = "Ask the agent a question.")
41-
suspend fun ask(message : String) : String {
42-
val agent = agentProvider.getAgentByName("My Agent") as ChatAgent? ?: error("Agent not found!")
43-
val conversation = message.toConversation(User("anonymous"))
41+
suspend fun ask(conversation : Conversation) : String {
4442
val assistantMessage = agent.execute(conversation).getOrThrow().latest<AssistantMessage>() ?:
4543
throw RuntimeException("No Assistant response")
4644
messageFlow.emit(assistantMessage.content)
Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package ai.ancf.lmos.wot.integration
22

33
import ai.ancf.lmos.wot.Servient
4-
import ai.ancf.lmos.wot.Wot
54
import ai.ancf.lmos.wot.binding.http.HttpProtocolClientFactory
65
import ai.ancf.lmos.wot.binding.http.HttpProtocolServer
76
import ai.ancf.lmos.wot.binding.mqtt.MqttClientConfig
87
import ai.ancf.lmos.wot.binding.mqtt.MqttProtocolServer
9-
import ai.ancf.lmos.wot.thing.ExposedThing
10-
import ai.ancf.lmos.wot.thing.Type
11-
import ai.ancf.lmos.wot.thing.schema.*
128

139
private const val PROPERTY_NAME = "property1"
1410
private const val PROPERTY_NAME_2 = "property2"
@@ -32,40 +28,3 @@ fun createServient(protocol: String): Servient {
3228
else -> throw IllegalArgumentException("Unsupported protocol: $protocol")
3329
}
3430
}
35-
36-
fun createExposedThing(wot: Wot, agent: ThingAgent): ExposedThing {
37-
return wot.produce {
38-
id = "agent"
39-
title = "Agent"
40-
objectType = Type("Agent")
41-
intProperty(PROPERTY_NAME) { observable = true }
42-
intProperty(PROPERTY_NAME_2) { observable = true }
43-
action<String, Map<*, *>>(ACTION_NAME) {
44-
title = ACTION_NAME
45-
description = "Ask a question to the agent"
46-
input = stringSchema {
47-
title = "Action Input"
48-
description = "Question"
49-
minLength = 10
50-
default = "test"
51-
}
52-
output = objectSchema {
53-
stringProperty("response") {
54-
description = "Answer of the agent"
55-
}
56-
}
57-
}
58-
event<String, Nothing, Nothing>(EVENT_NAME) { data = StringSchema() }
59-
}.apply {
60-
setPropertyReadHandler(PROPERTY_NAME) { 10.toInteractionInputValue() }
61-
setPropertyReadHandler(PROPERTY_NAME_2) { 5.toInteractionInputValue() }
62-
setPropertyWriteHandler(PROPERTY_NAME) { input, _ ->
63-
val inputInt = input.value() as DataSchemaValue.IntegerValue
64-
inputInt.value.toInteractionInputValue()
65-
}
66-
setActionHandler(ACTION_NAME) { input, _ ->
67-
val inputString = input.value() as DataSchemaValue.StringValue
68-
agent.ask(inputString.value).toInteractionInputValue()
69-
}
70-
}
71-
}

0 commit comments

Comments
 (0)