Skip to content

Commit

Permalink
add dev UI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed Oct 8, 2024
1 parent 57abad5 commit 4de7513
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# LLM Agent Builder

[![build](https://github.com/LLMAgentBuilder/llm-agent-builder/actions/workflows/build.yaml/badge.svg)](https://github.com/LLMAgentBuilder/llm-agent-builder/actions/workflows/build.yaml)

**LLM Agent Powered by Java / Spring AI**

## Documentation
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<artifactId>open-telemetry</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.github.llmagentbuilder</groupId>
<artifactId>chat-agent-ui</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>io.github.llmagentbuilder</groupId>
<artifactId>llm-openai</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ object AgentBootstrap {
UUID.randomUUID().toString(),
observationRegistry,
)
KtorLauncher.launch(chatAgent)
KtorLauncher.launch(chatAgent, agentConfig.launch)
}

private fun profileAdvisor(agentConfig: AgentConfig): Advisor? {
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/kotlin/io/github/llmagentbuilder/core/AgentConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ class ObservationConfig {
var metrics: MetricsConfig? = null
}

class LaunchConfig {
var server: ServerConfig? = null
val feature: FeatureConfig? = null
}

class ServerConfig {
var host: String? = "localhost"
var port: Int? = 8080
}

class FeatureConfig {
var devUiEnabled: Boolean? = true
}


class AgentConfig {
var metadata: AgentMetadata? = null
var profile: ProfileConfig? = null
Expand All @@ -71,6 +86,7 @@ class AgentConfig {
var planner: Map<String, Any?>? = null
var tools: List<ToolConfig>? = null
var observation: ObservationConfig? = null
var launch: LaunchConfig? = null
}

object AgentConfigLoader {
Expand Down
5 changes: 5 additions & 0 deletions launchers/ktor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<artifactId>ktor-serialization-jackson-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-server-webjars-jvm</artifactId>
<version>${ktor.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.github.llmagentbuilder.launcher.ktor.server

import io.github.llmagentbuilder.core.ChatAgent
import io.github.llmagentbuilder.core.FeatureConfig
import io.github.llmagentbuilder.core.LaunchConfig
import io.github.llmagentbuilder.launcher.ktor.server.apis.AgentApi
import io.github.llmagentbuilder.launcher.ktor.server.apis.devUI
import io.ktor.serialization.jackson.*
import io.ktor.server.application.*
import io.ktor.server.cio.*
Expand All @@ -11,21 +14,34 @@ import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.defaultheaders.*
import io.ktor.server.resources.*
import io.ktor.server.routing.*
import io.ktor.server.webjars.*
import org.slf4j.LoggerFactory

object KtorLauncher {
fun launch(chatAgent: ChatAgent) {
private val logger = LoggerFactory.getLogger(KtorLauncher::class.java)

fun launch(chatAgent: ChatAgent, launchConfig: LaunchConfig? = null) {
val host = launchConfig?.server?.host ?: "localhost"
val port = launchConfig?.server?.port ?: 8080
logger.info("Starting agent server: $host:$port")
embeddedServer(
CIO,
port = 8080,
host = "0.0.0.0",
port,
host,
module = {
module(chatAgent)
}
).start(wait = true)
}
}

fun Application.module(chatAgent: ChatAgent) {
fun Application.module(
chatAgent: ChatAgent,
featureConfig: FeatureConfig? = null
) {
install(Webjars) {
path = "/webjars"
}
install(DefaultHeaders)
install(ContentNegotiation) {
jackson()
Expand All @@ -37,5 +53,8 @@ fun Application.module(chatAgent: ChatAgent) {
install(Resources)
install(Routing) {
AgentApi(chatAgent)
if (featureConfig?.devUiEnabled != false) {
devUI()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.github.llmagentbuilder.launcher.ktor.server.apis

import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun Route.devUI() {
get("/") {
call.respondRedirect("/webjars/chat-agent-ui/index.html")
}
get("/_next/{path...}") {
val redirectPath = call.parameters.getAll("path")?.joinToString("/")
call.respondRedirect("/webjars/chat-agent-ui/${redirectPath}")
}
}

0 comments on commit 4de7513

Please sign in to comment.