Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/main/kotlin/com/github/zerubeus/aladin/arc/Agents.kt
Original file line number Diff line number Diff line change
@@ -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.
"""
}
}
}
22 changes: 22 additions & 0 deletions src/main/kotlin/com/github/zerubeus/aladin/arc/ArcSetup.kt
Original file line number Diff line number Diff line change
@@ -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<Any>): 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

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

package com.github.zerubeus.aladin.arc

import com.azure.ai.openai.OpenAIClientBuilder

Check warning on line 4 in src/main/kotlin/com/github/zerubeus/aladin/arc/ChatCompleterProvider.kt

View workflow job for this annotation

GitHub Actions / Inspect code

Unused import directive

Unused import directive
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 {

Check notice on line 29 in src/main/kotlin/com/github/zerubeus/aladin/arc/ChatCompleterProvider.kt

View workflow job for this annotation

GitHub Actions / Inspect code

'when' that can be simplified by introducing an argument

'when' with subject should be used
"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()

Check warning on line 40 in src/main/kotlin/com/github/zerubeus/aladin/arc/ChatCompleterProvider.kt

View workflow job for this annotation

GitHub Actions / Inspect code

Redundant qualifier name

Redundant qualifier name
.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,
)
26 changes: 26 additions & 0 deletions src/main/kotlin/com/github/zerubeus/aladin/arc/Demo.kt
Original file line number Diff line number Diff line change
@@ -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() {

Check warning on line 7 in src/main/kotlin/com/github/zerubeus/aladin/arc/Demo.kt

View workflow job for this annotation

GitHub Actions / Inspect code

Unused symbol

Function "demo" is never used
// 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)
}
Loading