From 6eadc653125d9630d3e3338724f9cf63232fc1ed Mon Sep 17 00:00:00 2001 From: "patrick.whelan@telekom.de" Date: Sat, 22 Mar 2025 14:07:41 +0100 Subject: [PATCH 1/2] Add arc framework --- build.gradle.kts | 22 ++++++- .../com/github/zerubeus/aladin/arc/Agents.kt | 26 ++++++++ .../github/zerubeus/aladin/arc/ArcSetup.kt | 22 +++++++ .../aladin/arc/ChatCompleterProvider.kt | 61 +++++++++++++++++++ .../com/github/zerubeus/aladin/arc/Demo.kt | 26 ++++++++ 5 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/github/zerubeus/aladin/arc/Agents.kt create mode 100644 src/main/kotlin/com/github/zerubeus/aladin/arc/ArcSetup.kt create mode 100644 src/main/kotlin/com/github/zerubeus/aladin/arc/ChatCompleterProvider.kt create mode 100644 src/main/kotlin/com/github/zerubeus/aladin/arc/Demo.kt diff --git a/build.gradle.kts b/build.gradle.kts index 5b5fb0b..856d33c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ version = providers.gradleProperty("pluginVersion").get() // Set the JVM language level used to build the project. kotlin { - jvmToolchain(17) + jvmToolchain(21) } // Configure project's dependencies @@ -51,6 +51,26 @@ dependencies { zipSigner() testFramework(TestFrameworkType.Platform) } + + // Arc + val arcVersion = "0.121.0" + implementation("org.eclipse.lmos:arc-reader-pdf:$arcVersion") + implementation("org.eclipse.lmos:arc-reader-html:$arcVersion") + implementation("org.eclipse.lmos:arc-assistants:$arcVersion") + implementation("org.eclipse.lmos:arc-agents:$arcVersion") + implementation("org.eclipse.lmos:arc-result:$arcVersion") + implementation("org.eclipse.lmos:arc-langchain4j-client:$arcVersion") + implementation("org.eclipse.lmos:arc-azure-client:$arcVersion") + + // Azure + implementation("com.azure:azure-ai-openai:1.0.0-beta.13") + + // Langchain4j + val langchain4jVersion = "0.36.2" + implementation("dev.langchain4j:langchain4j-bedrock:$langchain4jVersion") + implementation("dev.langchain4j:langchain4j-google-ai-gemini:$langchain4jVersion") + implementation("dev.langchain4j:langchain4j-ollama:$langchain4jVersion") + implementation("dev.langchain4j:langchain4j-open-ai:$langchain4jVersion") } // Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html diff --git a/src/main/kotlin/com/github/zerubeus/aladin/arc/Agents.kt b/src/main/kotlin/com/github/zerubeus/aladin/arc/Agents.kt new file mode 100644 index 0000000..f475dd3 --- /dev/null +++ b/src/main/kotlin/com/github/zerubeus/aladin/arc/Agents.kt @@ -0,0 +1,26 @@ +package com.github.zerubeus.aladin.arc + +import org.eclipse.lmos.arc.agents.DSLAgents + +/** + * Create Agents. + */ +fun DSLAgents.createAgents() = define { + agent { + name = "Aladin" + prompt { + """ + Welcome to Aladin! I am a simple chatbot that can help you with your queries. + """ + } + } + + agent { + name = "AnotherAgent" + prompt { + """ + Welcome to AnotherAgent! I am a simple chatbot that can help you with your queries. + """ + } + } +} diff --git a/src/main/kotlin/com/github/zerubeus/aladin/arc/ArcSetup.kt b/src/main/kotlin/com/github/zerubeus/aladin/arc/ArcSetup.kt new file mode 100644 index 0000000..0c0cd4d --- /dev/null +++ b/src/main/kotlin/com/github/zerubeus/aladin/arc/ArcSetup.kt @@ -0,0 +1,22 @@ +package com.github.zerubeus.aladin.arc + + +import org.eclipse.lmos.arc.agents.ChatAgent +import org.eclipse.lmos.arc.agents.DSLAgents +import org.eclipse.lmos.arc.agents.events.BasicEventPublisher +import org.eclipse.lmos.arc.agents.events.LoggingEventHandler + +/** + * Initializes the ARC Framework. + */ +fun setupArc(appConfig: AIClientConfig, contextBeans: Set): DSLAgents { + val eventPublisher = BasicEventPublisher(LoggingEventHandler()) + val chatCompleterProvider = chatCompleterProvider(appConfig, eventPublisher) + return DSLAgents.init(chatCompleterProvider) +} + +/** + * Get a ChatAgent by name. + */ +fun DSLAgents.getChatAgent(name: String) = getAgents().find { it.name == name } as ChatAgent + diff --git a/src/main/kotlin/com/github/zerubeus/aladin/arc/ChatCompleterProvider.kt b/src/main/kotlin/com/github/zerubeus/aladin/arc/ChatCompleterProvider.kt new file mode 100644 index 0000000..5b9200e --- /dev/null +++ b/src/main/kotlin/com/github/zerubeus/aladin/arc/ChatCompleterProvider.kt @@ -0,0 +1,61 @@ + +package com.github.zerubeus.aladin.arc + +import com.azure.ai.openai.OpenAIClientBuilder +import com.azure.core.credential.KeyCredential +import org.eclipse.lmos.arc.agents.events.EventPublisher +import org.eclipse.lmos.arc.agents.llm.ChatCompleterProvider +import org.eclipse.lmos.arc.client.azure.AzureAIClient +import org.eclipse.lmos.arc.client.azure.AzureClientConfig +import org.eclipse.lmos.arc.client.langchain4j.LangChainClient +import org.eclipse.lmos.arc.client.langchain4j.LangChainConfig +import org.eclipse.lmos.arc.client.langchain4j.builders.bedrockBuilder +import org.eclipse.lmos.arc.client.langchain4j.builders.geminiBuilder +import org.eclipse.lmos.arc.client.langchain4j.builders.groqBuilder +import org.eclipse.lmos.arc.client.langchain4j.builders.ollamaBuilder + +/** + * Provides a ChatCompleterProvider based on the given configuration. + */ +fun chatCompleterProvider(config: AIClientConfig, eventPublisher: EventPublisher): ChatCompleterProvider { + val langChainConfig = LangChainConfig( + modelName = config.modelName, + url = config.url, + apiKey = config.apiKey, + accessKeyId = config.accessKey, + secretAccessKey = config.accessSecret, + ) + + val aiClient = when { + "gemini" == config.client -> LangChainClient(langChainConfig, geminiBuilder(), eventPublisher) + + "bedrock" == config.client -> LangChainClient(langChainConfig, bedrockBuilder(), eventPublisher) + + "groq" == config.client -> LangChainClient(langChainConfig, groqBuilder(), eventPublisher) + + "ollama" == config.client -> LangChainClient(langChainConfig, ollamaBuilder(), eventPublisher) + + "openai" == config.client -> AzureAIClient( + AzureClientConfig(config.modelName, config.url ?: "", config.apiKey ?: ""), + com.azure.ai.openai.OpenAIClientBuilder() + .apply { if (config.url != null) endpoint(config.url) } + .credential(KeyCredential(config.apiKey)) + .buildAsyncClient(), + eventPublisher, + ) + + else -> error("No client could be configured for client: ${config.client}") + } + + return ChatCompleterProvider { aiClient } +} + +data class AIClientConfig( + val id: String, + val client: String, + val modelName: String, + val url: String? = null, + val apiKey: String? = null, + val accessKey: String? = null, + val accessSecret: String? = null, +) diff --git a/src/main/kotlin/com/github/zerubeus/aladin/arc/Demo.kt b/src/main/kotlin/com/github/zerubeus/aladin/arc/Demo.kt new file mode 100644 index 0000000..cc83b95 --- /dev/null +++ b/src/main/kotlin/com/github/zerubeus/aladin/arc/Demo.kt @@ -0,0 +1,26 @@ +package com.github.zerubeus.aladin.arc + +import org.eclipse.lmos.arc.agents.conversation.Conversation +import org.eclipse.lmos.arc.agents.conversation.UserMessage + + +suspend fun demo() { + // Setup the ARC Framework + val agents = setupArc( + AIClientConfig( + id = "gpt-3.5", + client = "openai", + modelName = "gpt-3.5-turbo", + apiKey = "your-api" + ), emptySet() + ) + + // Create agents + agents.createAgents() + + // Execute an Agent + val conversation = Conversation(transcript = listOf(UserMessage("Hello"))) + val result = agents.getChatAgent("Aladin").execute(conversation) + + println(result) +} From 19b8a1e9ad3604489c42158ef6f1a40943c95b4a Mon Sep 17 00:00:00 2001 From: "patrick.whelan@telekom.de" Date: Mon, 24 Mar 2025 11:58:23 +0100 Subject: [PATCH 2/2] Test Java 17 version --- build.gradle.kts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 856d33c..b10c295 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,12 +16,13 @@ version = providers.gradleProperty("pluginVersion").get() // Set the JVM language level used to build the project. kotlin { - jvmToolchain(21) + jvmToolchain(17) } // Configure project's dependencies repositories { mavenCentral() + maven(url = "https://oss.sonatype.org/content/repositories/snapshots/") // IntelliJ Platform Gradle Plugin Repositories Extension - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-repositories-extension.html intellijPlatform { @@ -53,7 +54,7 @@ dependencies { } // Arc - val arcVersion = "0.121.0" + val arcVersion = "0.122.0-j17-SNAPSHOT" implementation("org.eclipse.lmos:arc-reader-pdf:$arcVersion") implementation("org.eclipse.lmos:arc-reader-html:$arcVersion") implementation("org.eclipse.lmos:arc-assistants:$arcVersion")