File tree Expand file tree Collapse file tree 4 files changed +14
-14
lines changed
src/main/kotlin/cc/unitmesh/devti/llms Expand file tree Collapse file tree 4 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -390,21 +390,14 @@ project(":") {
390
390
plugins.set(ideaPlugins)
391
391
}
392
392
393
- // sourceSets {
394
- // main {
395
- // resources.srcDirs("src/main/resources")
396
- // resources.srcDirs("src/$platformVersion/main/resources")
397
- // }
398
- // }
399
-
400
393
dependencies {
401
394
implementation(libs.bundles.openai)
402
395
implementation(libs.bundles.markdown)
403
396
implementation(libs.yaml)
404
397
405
398
implementation(libs.json.pathkt)
406
399
407
- implementation(" org.jetbrains:markdown:0.5 .1" )
400
+ implementation(" org.jetbrains:markdown:0.6 .1" )
408
401
implementation(libs.kotlinx.serialization.json)
409
402
410
403
implementation(" cc.unitmesh:cocoa-core:0.4.5" )
@@ -414,11 +407,14 @@ project(":") {
414
407
implementation(libs.github.api)
415
408
implementation(" org.gitlab4j:gitlab4j-api:5.3.0" )
416
409
410
+ // template engine
417
411
implementation(" org.apache.velocity:velocity-engine-core:2.3" )
418
412
413
+ // http request/response
419
414
implementation(libs.jackson.module.kotlin)
420
415
421
- implementation(" com.knuddels:jtokkit:0.6.1" )
416
+ // token count
417
+ implementation(" com.knuddels:jtokkit:1.0.0" )
422
418
423
419
// junit
424
420
testImplementation(" io.kotest:kotest-assertions-core:5.7.2" )
Original file line number Diff line number Diff line change @@ -149,17 +149,17 @@ fun JsonObject.updateCustomBody(customRequest: String): JsonObject {
149
149
150
150
// TODO clean code with magic literals
151
151
var roleKey = " role"
152
- var contentKey = " message "
152
+ var contentKey = " content "
153
153
customRequestJson.jsonObject[" messageKeys" ]?.let {
154
154
roleKey = it.jsonObject[" role" ]?.jsonPrimitive?.content ? : " role"
155
- contentKey = it.jsonObject[" content" ]?.jsonPrimitive?.content ? : " message "
155
+ contentKey = it.jsonObject[" content" ]?.jsonPrimitive?.content ? : " content "
156
156
}
157
157
158
158
val messages: JsonArray = this @updateCustomBody[" messages" ]?.jsonArray ? : buildJsonArray { }
159
159
this .put(" messages" , buildJsonArray {
160
160
messages.forEach { message ->
161
161
val role: String = message.jsonObject[" role" ]?.jsonPrimitive?.content ? : " user"
162
- val content: String = message.jsonObject[" message " ]?.jsonPrimitive?.content ? : " "
162
+ val content: String = message.jsonObject[" content " ]?.jsonPrimitive?.content ? : " "
163
163
add(buildJsonObject {
164
164
put(roleKey, role)
165
165
put(contentKey, content)
Original file line number Diff line number Diff line change 1
1
package cc.unitmesh.devti.llms.tokenizer
2
2
3
+ import com.knuddels.jtokkit.api.IntArrayList
4
+
3
5
interface Tokenizer {
4
6
fun getMaxLength (): Int
5
7
fun count (string : String ): Int
6
- fun tokenize (chunk : String ): List < Int >
8
+ fun tokenize (chunk : String ): IntArrayList ?
7
9
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import com.knuddels.jtokkit.Encodings
6
6
import com.knuddels.jtokkit.api.Encoding
7
7
import com.knuddels.jtokkit.api.EncodingRegistry
8
8
import com.knuddels.jtokkit.api.EncodingType
9
+ import com.knuddels.jtokkit.api.IntArrayList
9
10
10
11
@Service(Service .Level .APP )
11
12
class TokenizerImpl (private val maxTokenLength : Int = 8192 ) : Tokenizer {
@@ -15,7 +16,8 @@ class TokenizerImpl(private val maxTokenLength: Int = 8192) : Tokenizer {
15
16
override fun getMaxLength (): Int = maxTokenLength
16
17
17
18
override fun count (string : String ): Int = encoding.countTokens(string)
18
- override fun tokenize (chunk : String ): List <Int > {
19
+
20
+ override fun tokenize (chunk : String ): IntArrayList ? {
19
21
return encoding.encode(chunk, maxTokenLength).tokens
20
22
}
21
23
You can’t perform that action at this time.
0 commit comments