diff --git a/build.gradle.kts b/build.gradle.kts index 5b5fb0b..b10c295 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,6 +22,7 @@ kotlin { // 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 { @@ -51,6 +52,26 @@ dependencies { zipSigner() testFramework(TestFrameworkType.Platform) } + + // Arc + 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") + 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) +}