Skip to content

Commit d3340f4

Browse files
author
Robert Winkler
committed
Reflection
1 parent f592b08 commit d3340f4

File tree

26 files changed

+1915
-42
lines changed

26 files changed

+1915
-42
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ dependencies {
22
api(project(":kotlin-wot"))
33
api(project(":kotlin-wot-binding-http"))
44
api(project(":kotlin-wot-binding-mqtt"))
5+
api(project(":kotlin-wot-reflection"))
56
api("ch.qos.logback:logback-classic:1.5.12")
67
implementation("ai.ancf.lmos:arc-agents:0.98.0")
78
implementation("ai.ancf.lmos:arc-langchain4j-client:0.98.0")

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package ai.ancf.lmos.wot.integration
22

33
import ai.ancf.lmos.wot.Wot
4-
import kotlinx.coroutines.Dispatchers
4+
import ai.ancf.lmos.wot.reflection.annotations.ThingAgent
55
import kotlinx.coroutines.Job
66
import kotlinx.coroutines.launch
77
import kotlinx.coroutines.runBlocking
88

99

1010
fun main(): Unit = runBlocking {
1111

12-
val agent = Agent()
12+
val agent = ThingAgent()
1313

1414
// Protocol can be "HTTP" or "MQTT"
1515
val servient = createServient("HTTP")

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package ai.ancf.lmos.wot.integration
22

33
import ai.ancf.lmos.wot.Wot
4-
import kotlinx.coroutines.*
4+
import ai.ancf.lmos.wot.reflection.annotations.ThingAgent
5+
import kotlinx.coroutines.Job
6+
import kotlinx.coroutines.launch
7+
import kotlinx.coroutines.runBlocking
58

69

710
fun main(): Unit = runBlocking {
8-
val agent = Agent()
11+
val agent = ThingAgent()
912

1013
// Protocol can be "HTTP" or "MQTT"
1114
val servient = createServient("MQTT")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ai.ancf.lmos.wot.reflection.annotations
2+
3+
import dev.langchain4j.model.azure.AzureOpenAiChatModel
4+
5+
6+
@Thing(id= "agent", title="Agent",
7+
description= "A simple agent.")
8+
class ThingAgent() {
9+
10+
private val model: AzureOpenAiChatModel = AzureOpenAiChatModel.builder()
11+
.apiKey("af12dab9c046453e82dcf4b24af90bca")
12+
.deploymentName("GPT35T-1106")
13+
.endpoint("https://gpt4-uk.openai.azure.com/")
14+
.build();
15+
16+
@Property(name = "modelTemperature", readOnly = true)
17+
var modelTemperature: ModelConfiguration = ModelConfiguration(0.5, 50)
18+
19+
@Action(name = "ask")
20+
fun ask(message : String) : String {
21+
return model.generate(message)
22+
}
23+
}
24+
25+
data class ModelConfiguration(val modelTemperature: Double, val maxTokens: Int)
26+

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ai.ancf.lmos.wot.binding.http.HttpProtocolClientFactory
66
import ai.ancf.lmos.wot.binding.http.HttpProtocolServer
77
import ai.ancf.lmos.wot.binding.mqtt.MqttClientConfig
88
import ai.ancf.lmos.wot.binding.mqtt.MqttProtocolServer
9+
import ai.ancf.lmos.wot.reflection.annotations.ThingAgent
910
import ai.ancf.lmos.wot.thing.ExposedThing
1011
import ai.ancf.lmos.wot.thing.Type
1112
import ai.ancf.lmos.wot.thing.schema.*
@@ -33,7 +34,7 @@ fun createServient(protocol: String): Servient {
3334
}
3435
}
3536

36-
fun createExposedThing(wot: Wot, agent: Agent): ExposedThing {
37+
fun createExposedThing(wot: Wot, agent: ThingAgent): ExposedThing {
3738
return wot.produce {
3839
id = "agent"
3940
title = "Agent"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package integration
2+
3+
4+
import ai.ancf.lmos.wot.Servient
5+
import ai.ancf.lmos.wot.Wot
6+
import ai.ancf.lmos.wot.binding.http.HttpProtocolClientFactory
7+
import ai.ancf.lmos.wot.binding.http.HttpProtocolServer
8+
import ai.ancf.lmos.wot.reflection.annotations.ThingAgent
9+
import ai.ancf.lmos.wot.reflection.annotations.ThingBuilder
10+
import ai.ancf.lmos.wot.thing.schema.WoTExposedThing
11+
import ai.ancf.lmos.wot.thing.schema.toInteractionInputValue
12+
import kotlinx.coroutines.test.runTest
13+
import kotlin.test.Test
14+
15+
class AgentBuilderTest {
16+
17+
@Test
18+
fun `Should create thing description from class`() = runTest {
19+
20+
val servient = Servient(
21+
servers = listOf(HttpProtocolServer()),
22+
clientFactories = listOf(
23+
HttpProtocolClientFactory()
24+
)
25+
)
26+
servient.start()
27+
28+
val wot = Wot.create(servient)
29+
val exposedThing = ThingBuilder()
30+
.createThingDescription(wot, ThingAgent(), ThingAgent::class)
31+
if(exposedThing != null){
32+
33+
34+
servient.addThing(exposedThing as WoTExposedThing)
35+
servient.expose("agent")
36+
37+
38+
println("Thing:${exposedThing.toJson()}")
39+
40+
val httpAgentTD = wot
41+
.requestThingDescription("http://localhost:8080/agent")
42+
val httpAgent = wot.consume(httpAgentTD)
43+
val output = httpAgent.invokeAction("ask",
44+
"What is Paris?".toInteractionInputValue())
45+
println(output.value())
46+
}
47+
48+
}
49+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dependencies {
2+
api(project(":kotlin-wot"))
3+
implementation("ch.qos.logback:logback-classic:1.5.12")
4+
implementation("org.jetbrains.kotlin:kotlin-reflect")
5+
testImplementation("io.mockk:mockk:1.13.13")
6+
testImplementation(project(":kotlin-wot-binding-http"))
7+
}

0 commit comments

Comments
 (0)