Skip to content

Commit

Permalink
change task type and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjoyo committed Aug 15, 2023
1 parent 85e78f7 commit d81bde9
Show file tree
Hide file tree
Showing 67 changed files with 862 additions and 837 deletions.
7 changes: 4 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

root = true

[*]
[*.kt]
# We recommend you to keep these unchanged
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
max_line_length = 160

# camunda uses 2 spaces for indention
# camunda uses 2 spaces for indention but I honestly hate it too much
indent_size = 4
indent_style = space
indent_size = 2

# in markdown, we might want trailing whitespaces
[*.md]
trim_trailing_whitespace = false

[*.py]
indent_style = space
indent_size = 4
2 changes: 1 addition & 1 deletion bpmn/.camunda/element-templates/connector-gpt-compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.compose:1",
"value": "io.holunda:connector-compose:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.database:1",
"value": "io.holunda:connector-database:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
2 changes: 1 addition & 1 deletion bpmn/.camunda/element-templates/connector-gpt-decide.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.decide:1",
"value": "io.holunda:connector-decide:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.executor:1",
"value": "io.holunda:connector-executor:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
2 changes: 1 addition & 1 deletion bpmn/.camunda/element-templates/connector-gpt-extract.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.extract:1",
"value": "io.holunda:connector-extract:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
2 changes: 1 addition & 1 deletion bpmn/.camunda/element-templates/connector-gpt-generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.generic:1",
"value": "io.holunda:connector-generic:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
2 changes: 1 addition & 1 deletion bpmn/.camunda/element-templates/connector-gpt-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.openapi:1",
"value": "io.holunda:connector-openapi:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
2 changes: 1 addition & 1 deletion bpmn/.camunda/element-templates/connector-gpt-planner.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.planner:1",
"value": "io.holunda:connector-planner:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
2 changes: 1 addition & 1 deletion bpmn/.camunda/element-templates/connector-gpt-process.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.process:1",
"value": "io.holunda:connector-process:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.retrieval:1",
"value": "io.holunda:connector-retrieval:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"properties": [
{
"type": "Hidden",
"value": "io.holunda.connector.translate:1",
"value": "io.holunda:connector-translate:1",
"binding": {
"type": "zeebe:taskDefinition:type"
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/kotlin/io/holunda/connector/common/JsonUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import com.fasterxml.jackson.module.kotlin.*
private val mapper = jacksonObjectMapper()

fun JsonNode.toMap(): Map<String, Any?> {
val typeRef = object : TypeReference<Map<String, Any?>>() {}
return mapper.convertValue(this, typeRef)
val typeRef = object : TypeReference<Map<String, Any?>>() {}
return mapper.convertValue(this, typeRef)
}

fun JsonNode.toStringMap(): Map<String, String> {
val typeRef = object : TypeReference<Map<String, String>>() {}
return mapper.convertValue(this, typeRef)
val typeRef = object : TypeReference<Map<String, String>>() {}
return mapper.convertValue(this, typeRef)
}

fun JsonNode.toStringList(): List<String> {
val typeRef = object : TypeReference<List<String>>() {}
return mapper.convertValue(this, typeRef)
val typeRef = object : TypeReference<List<String>>() {}
return mapper.convertValue(this, typeRef)
}

inline fun <reified T> String.readFromJson() = jacksonObjectMapper().readValue<T>(this)
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ import kotlinx.coroutines.*

object LLMServiceClient {

val llmServiceUrl = System.getenv("LLM_SERVICE_URL") ?: "http://localhost:9999"
val llmServiceUrl = System.getenv("LLM_SERVICE_URL") ?: "http://localhost:9999"

val client = HttpClient {
install(ContentNegotiation) {
jackson {
configure(SerializationFeature.INDENT_OUTPUT, true)
setDefaultPrettyPrinter(DefaultPrettyPrinter().apply {
indentArraysWith(DefaultPrettyPrinter.FixedSpaceIndenter.instance)
indentObjectsWith(DefaultIndenter(" ", "\n"))
})
}
expectSuccess = true
val client = HttpClient {
install(ContentNegotiation) {
jackson {
configure(SerializationFeature.INDENT_OUTPUT, true)
setDefaultPrettyPrinter(DefaultPrettyPrinter().apply {
indentArraysWith(DefaultPrettyPrinter.FixedSpaceIndenter.instance)
indentObjectsWith(DefaultIndenter(" ", "\n"))
})
}
expectSuccess = true
}
install(HttpTimeout) {
requestTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
connectTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
socketTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
}
}
install(HttpTimeout) {
requestTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
connectTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
socketTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
}
}

val jsonMapper = jacksonObjectMapper()
val jsonMapper = jacksonObjectMapper()

inline fun <reified T: Any> run(task: String, request: T): JsonNode = runBlocking {
val response: String = client.post("${llmServiceUrl}/$task") {
contentType(ContentType.Application.Json)
setBody(jsonMapper.writeValueAsString(request))
}.body()
jsonMapper.readTree(response)
}
inline fun <reified T : Any> run(task: String, request: T): JsonNode = runBlocking {
val response: String = client.post("${llmServiceUrl}/$task") {
contentType(ContentType.Application.Json)
setBody(jsonMapper.writeValueAsString(request))
}.body()
jsonMapper.readTree(response)
}

}
Original file line number Diff line number Diff line change
@@ -1,74 +1,44 @@
package io.holunda.connector.compose

import com.fasterxml.jackson.databind.*
import io.camunda.connector.api.annotation.*
import io.camunda.connector.api.outbound.*
import io.holunda.connector.common.*
import io.holunda.connector.generic.*
import mu.*
import org.apache.commons.text.*
import org.slf4j.*
import java.util.*

@OutboundConnector(
name = "gpt-compose",
inputVariables = ["inputJson", "description", "temperature", "type", "style", "tone", "length", "language", "sender", "customPrinciple", "constitutionalPrinciple", "model"],
type = "io.holunda.connector.compose:1"
name = "gpt-compose",
inputVariables = [
"inputJson",
"description",
"temperature",
"type",
"style",
"tone",
"length",
"language",
"sender",
"customPrinciple",
"constitutionalPrinciple",
"model"
],
type = "io.holunda:connector-compose:1"
)
class ComposeFunction : OutboundConnectorFunction {

@Throws(Exception::class)
override fun execute(context: OutboundConnectorContext): Any {
LOG.info("Executing ComposeFunction")
val unescapedVariables = StringEscapeUtils.unescapeJson(context.variables) // TODO remove when Camunda fixes this in zeebe :P zeebe/issues/9859
val connectorRequest = unescapedVariables.readFromJson<ComposeRequest>()
//val connectorRequest = context.bindVariables(ComposeRequest::class.java)
LOG.info("Request: {}", connectorRequest)
return executeConnector(connectorRequest)
}

private fun executeConnector(request: ComposeRequest): ComposeResult {
val constitutionalPrinciple = when (request.constitutionalPrinciple) {
null, "none" -> null
"custom" -> request.customPrinciple
else -> request.constitutionalPrinciple
override fun execute(context: OutboundConnectorContext): Any {
logger.info("Executing ComposeFunction")
val unescapedVariables = StringEscapeUtils.unescapeJson(context.variables) // TODO remove when Camunda fixes this in zeebe :P zeebe/issues/9859
val connectorRequest = unescapedVariables.readFromJson<ComposeRequest>()
logger.info("ComposeFunction request: $connectorRequest")
return executeRequest(ComposeTask.fromRequest(connectorRequest))
}

val result = LLMServiceClient.run("compose",
ComposeTask(
request.model.modelId,
request.inputJson,
request.description,
request.type,
request.style,
request.tone,
request.length,
request.language,
request.temperature,
request.sender,
constitutionalPrinciple
)
)

LOG.info("ComposeFunction result: $result")

return ComposeResult(result)
}

data class ComposeTask(
val model: String,
val context: JsonNode,
val instructions: String,
val type: String,
val style: String,
val tone: String,
val length: String,
val language: String,
val temperature: Double,
val sender: String?,
val constitutional_principle: String?,
)
private fun executeRequest(composeTask: ComposeTask): ComposeResult {
val result = LLMServiceClient.run("compose", composeTask)
logger.info("ComposeFunction result: $result")
return ComposeResult(result)
}

companion object {
private val LOG = LoggerFactory.getLogger(ComposeFunction::class.java)
}
companion object : KLogging()
}
26 changes: 13 additions & 13 deletions core/src/main/kotlin/io/holunda/connector/compose/ComposeRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import com.fasterxml.jackson.databind.*
import io.holunda.connector.common.*

data class ComposeRequest(
val inputJson: JsonNode,
val description: String,
val style: String,
val type: String,
val tone: String,
val length: String,
val language: String,
val temperature: Double = 0.0,
val sender: String?,
val template: String?,
val constitutionalPrinciple: String?,
val customPrinciple: String?,
val model: Model
val inputJson: JsonNode,
val description: String,
val style: String,
val type: String,
val tone: String,
val length: String,
val language: String,
val temperature: Double = 0.0,
val sender: String?,
val template: String?,
val constitutionalPrinciple: String?,
val customPrinciple: String?,
val model: Model
)
38 changes: 38 additions & 0 deletions core/src/main/kotlin/io/holunda/connector/compose/ComposeTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.holunda.connector.compose

import com.fasterxml.jackson.databind.*

data class ComposeTask(
val model: String,
val context: JsonNode,
val instructions: String,
val type: String,
val style: String,
val tone: String,
val length: String,
val language: String,
val temperature: Double,
val sender: String?,
val constitutional_principle: String?,
) {
companion object {
fun fromRequest(request: ComposeRequest) =
ComposeTask(
request.model.modelId,
request.inputJson,
request.description,
request.type,
request.style,
request.tone,
request.length,
request.language,
request.temperature,
request.sender,
when (request.constitutionalPrinciple) {
null, "none" -> null
"custom" -> request.customPrinciple
else -> request.constitutionalPrinciple
}
)
}
}
Loading

0 comments on commit d81bde9

Please sign in to comment.