Skip to content

Commit

Permalink
update ktor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed Dec 26, 2024
1 parent 7f911b8 commit 4d3ed2b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<version>2.1.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/kotlin/io/github/llmagentbuilder/core/Agent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ interface Agent<in REQUEST : AgentRequest, out RESPONSE> {
fun call(request: REQUEST): RESPONSE
}

data class ChatAgentRequest(val input: String, val memoryId: String? = null) :
data class ChatAgentRequest(
val input: String,
val conversationId: String? = null
) :
AgentRequest {
override fun toMap(): Map<String, Any> {
return mapOf("input" to input) + (memoryId?.let { mapOf("memory_id" to it) }
return mapOf("input" to input) + (conversationId?.let { mapOf("conversation_id" to it) }
?: mapOf())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package io.github.llmagentbuilder.core

const val VERSION = "0.4.0"
2 changes: 1 addition & 1 deletion launchers/ktor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ktor.version>2.3.12</ktor.version>
<ktor.version>3.0.3</ktor.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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.agentApi
import io.github.llmagentbuilder.launcher.ktor.server.apis.devUI
import io.ktor.serialization.jackson.*
import io.ktor.server.application.*
Expand Down Expand Up @@ -48,11 +48,11 @@ fun Application.module(
}
install(
Compression,
ApplicationCompressionConfiguration()
applicationCompressionConfiguration()
)
install(Resources)
install(Routing) {
AgentApi(chatAgent)
routing {
agentApi(chatAgent)
if (featureConfig?.devUiEnabled != false) {
devUI()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package io.github.llmagentbuilder.launcher.ktor.server

// Use this file to hold package-level internal functions that return receiver object passed to the `install` method.
import io.ktor.server.plugins.compression.*


/**
* Application block for [Compression] configuration.
*
* This file may be excluded in .openapi-generator-ignore,
* and application-specific configuration can be applied in this function.
*
* See http://ktor.io/features/compression.html
*/
internal fun ApplicationCompressionConfiguration(): CompressionConfig.() -> Unit {
internal fun applicationCompressionConfiguration(): CompressionConfig.() -> Unit {
return {
gzip {
priority = 1.0
}
deflate {
priority = 10.0
minimumSize(1024) // condition
minimumSize(1024)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import io.github.llmagentbuilder.launcher.ktor.server.models.Step
import io.github.llmagentbuilder.launcher.ktor.server.models.Task
import io.github.llmagentbuilder.launcher.ktor.server.models.TaskRequestBody
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.set

fun Route.AgentApi(chatAgent: ChatAgent) {
fun Route.agentApi(chatAgent: ChatAgent) {
val tasks = ConcurrentHashMap<String, String>()

post("/chat") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.llmagentbuilder.launcher.ktor.server.apis

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

Expand Down
22 changes: 12 additions & 10 deletions launchers/ktor/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -
%msg%n
</pattern>
</encoder>
</appender>

<root level="trace">
<appender-ref ref="STDOUT"/>
</root>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>

<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>
<logger name="org.eclipse.jetty" level="INFO"/>
<logger name="io.netty" level="INFO"/>

</configuration>

0 comments on commit 4d3ed2b

Please sign in to comment.