Skip to content

Commit ea63b66

Browse files
committed
1 parent 970793a commit ea63b66

21 files changed

+79
-81
lines changed

langchain4j-kotlin/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
<artifactId>junit-jupiter-api</artifactId>
3737
<scope>test</scope>
3838
</dependency>
39-
<dependency>
40-
<groupId>org.jetbrains.kotlinx</groupId>
41-
<artifactId>kotlinx-coroutines-test-jvm</artifactId>
42-
<scope>test</scope>
43-
</dependency>
4439
<dependency>
4540
<groupId>dev.langchain4j</groupId>
4641
<artifactId>langchain4j-open-ai</artifactId>

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/Configuration.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import java.util.Properties
1111
* their renderers. The configurations are loaded from a properties file, and components are instantiated dynamically
1212
* based on the class names specified in the properties.
1313
*/
14-
object Configuration {
15-
val properties: Properties = loadProperties()
14+
public object Configuration {
15+
public val properties: Properties = loadProperties()
1616

17-
operator fun get(key: String): String = properties.getProperty(key)
17+
public operator fun get(key: String): String = properties.getProperty(key)
1818

19-
val promptTemplateSource: PromptTemplateSource =
19+
public val promptTemplateSource: PromptTemplateSource =
2020
createInstanceByName(this["prompt.template.source"])
21-
val promptTemplateRenderer: TemplateRenderer =
21+
public val promptTemplateRenderer: TemplateRenderer =
2222
createInstanceByName(this["prompt.template.renderer"])
2323
}
2424

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/TypeAliases.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package me.kpavlov.langchain4j.kotlin
77
* and its implementations to specify the input parameter for retrieving
88
* system messages.
99
*/
10-
typealias ChatMemoryId = Any
10+
public typealias ChatMemoryId = Any
1111

1212
/**
1313
* Type alias for the name of a template.
@@ -16,7 +16,7 @@ typealias ChatMemoryId = Any
1616
* of the codebase, providing a clearer and more specific meaning compared
1717
* to using `String` directly.
1818
*/
19-
typealias TemplateName = String
19+
public typealias TemplateName = String
2020

2121
/**
2222
* Represents the content of a template.
@@ -25,7 +25,7 @@ typealias TemplateName = String
2525
* which is expected to be in the form of a string. Various classes and functions that deal
2626
* with templates will utilize this type alias to ensure consistency and clarity.
2727
*/
28-
typealias TemplateContent = String
28+
public typealias TemplateContent = String
2929

3030
/**
3131
* Type alias for a string representing the content of a prompt.
@@ -34,4 +34,4 @@ typealias TemplateContent = String
3434
* by various functions and methods within the system that deal with
3535
* generating and handling prompts.
3636
*/
37-
typealias PromptContent = String
37+
public typealias PromptContent = String

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/adapters/TokenStreamToReplyFlowAdapter.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import me.kpavlov.langchain4j.kotlin.model.chat.asReplyFlow
88
import java.lang.reflect.ParameterizedType
99
import java.lang.reflect.Type
1010

11-
class TokenStreamToReplyFlowAdapter : TokenStreamAdapter {
11+
public class TokenStreamToReplyFlowAdapter : TokenStreamAdapter {
1212
override fun canAdaptTokenStreamTo(type: Type?): Boolean {
13-
if (type is ParameterizedType) {
14-
if (type.rawType === Flow::class.java) {
15-
val typeArguments: Array<Type?> = type.actualTypeArguments
16-
return typeArguments.size == 1 &&
17-
typeArguments[0] === StreamingChatLanguageModelReply::class.java
18-
}
13+
if (type is ParameterizedType && type.rawType === Flow::class.java) {
14+
val typeArguments: Array<Type> = type.actualTypeArguments
15+
return typeArguments.size == 1 &&
16+
typeArguments[0] === StreamingChatLanguageModelReply::class.java
1917
}
2018
return false
2119
}

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/adapters/TokenStreamToStringFlowAdapter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import me.kpavlov.langchain4j.kotlin.model.chat.asFlow
77
import java.lang.reflect.ParameterizedType
88
import java.lang.reflect.Type
99

10-
class TokenStreamToStringFlowAdapter : TokenStreamAdapter {
11-
override fun canAdaptTokenStreamTo(type: Type?): Boolean {
10+
public class TokenStreamToStringFlowAdapter : TokenStreamAdapter {
11+
public override fun canAdaptTokenStreamTo(type: Type?): Boolean {
1212
if (type is ParameterizedType) {
1313
if (type.rawType === Flow::class.java) {
1414
val typeArguments: Array<Type?> = type.actualTypeArguments
@@ -18,5 +18,5 @@ class TokenStreamToStringFlowAdapter : TokenStreamAdapter {
1818
return false
1919
}
2020

21-
override fun adapt(tokenStream: TokenStream): Any = tokenStream.asFlow()
21+
public override fun adapt(tokenStream: TokenStream): Any = tokenStream.asFlow()
2222
}

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import me.kpavlov.langchain4j.kotlin.model.chat.request.chatRequest
2626
* @see ChatRequest
2727
* @see ChatResponse
2828
*/
29-
suspend fun ChatLanguageModel.chatAsync(request: ChatRequest): ChatResponse =
29+
public suspend fun ChatLanguageModel.chatAsync(request: ChatRequest): ChatResponse =
3030
coroutineScope { this@chatAsync.chat(request) }
3131

3232
/**
@@ -53,7 +53,7 @@ suspend fun ChatLanguageModel.chatAsync(request: ChatRequest): ChatResponse =
5353
* @see ChatRequest.Builder
5454
* @see chatAsync
5555
*/
56-
suspend fun ChatLanguageModel.chatAsync(requestBuilder: ChatRequest.Builder): ChatResponse =
56+
public suspend fun ChatLanguageModel.chatAsync(requestBuilder: ChatRequest.Builder): ChatResponse =
5757
chatAsync(requestBuilder.build())
5858

5959
/**
@@ -79,7 +79,7 @@ suspend fun ChatLanguageModel.chatAsync(requestBuilder: ChatRequest.Builder): Ch
7979
* associated metadata.
8080
* @throws Exception if the chat request fails or encounters an error during execution.
8181
*/
82-
suspend fun ChatLanguageModel.chatAsync(block: ChatRequestBuilder.() -> Unit): ChatResponse =
82+
public suspend fun ChatLanguageModel.chatAsync(block: ChatRequestBuilder.() -> Unit): ChatResponse =
8383
chatAsync(chatRequest(block))
8484

8585
/**
@@ -109,5 +109,5 @@ suspend fun ChatLanguageModel.chatAsync(block: ChatRequestBuilder.() -> Unit): C
109109
* @see ChatRequest.Builder
110110
* @see ChatRequestBuilder
111111
*/
112-
fun ChatLanguageModel.chat(requestBuilder: ChatRequest.Builder): ChatResponse =
112+
public fun ChatLanguageModel.chat(requestBuilder: ChatRequest.Builder): ChatResponse =
113113
this.chat(requestBuilder.build())

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private val logger = LoggerFactory.getLogger(StreamingChatLanguageModel::class.j
2020
* Represents different types of replies that can be received from an AI language model during streaming.
2121
* This sealed interface provides type-safe handling of both intermediate tokens and final completion responses.
2222
*/
23-
sealed interface StreamingChatLanguageModelReply {
23+
public sealed interface StreamingChatLanguageModelReply {
2424
/**
2525
* Represents a partial response received from an AI language model during a streaming interaction.
2626
*
@@ -31,7 +31,7 @@ sealed interface StreamingChatLanguageModelReply {
3131
* @property token The string representation of the token generated as part of the streaming process.
3232
* @see StreamingChatResponseHandler.onPartialResponse
3333
*/
34-
data class PartialResponse(
34+
public data class PartialResponse(
3535
val token: String,
3636
) : StreamingChatLanguageModelReply
3737

@@ -45,7 +45,7 @@ sealed interface StreamingChatLanguageModelReply {
4545
* @property response The final chat response generated by the model.
4646
* @see StreamingChatResponseHandler.onCompleteResponse
4747
*/
48-
data class CompleteResponse(
48+
public data class CompleteResponse(
4949
val response: ChatResponse,
5050
) : StreamingChatLanguageModelReply
5151

@@ -58,7 +58,7 @@ sealed interface StreamingChatLanguageModelReply {
5858
* @property cause The underlying exception or error that caused the failure.
5959
* @see StreamingChatResponseHandler.onError
6060
*/
61-
data class Error(
61+
public data class Error(
6262
val cause: Throwable,
6363
) : StreamingChatLanguageModelReply
6464
}
@@ -79,7 +79,7 @@ sealed interface StreamingChatLanguageModelReply {
7979
* types of replies during the chat interaction, including partial responses,
8080
* final responses, and errors.
8181
*/
82-
fun StreamingChatLanguageModel.chatFlow(
82+
public fun StreamingChatLanguageModel.chatFlow(
8383
block: ChatRequestBuilder.() -> Unit,
8484
): Flow<StreamingChatLanguageModelReply> =
8585
callbackFlow {
@@ -127,7 +127,7 @@ fun StreamingChatLanguageModel.chatFlow(
127127
}
128128
}
129129

130-
fun TokenStream.asFlow(): Flow<String> =
130+
public fun TokenStream.asFlow(): Flow<String> =
131131
flow {
132132
callbackFlow {
133133
onPartialResponse { trySend(it) }
@@ -138,7 +138,7 @@ fun TokenStream.asFlow(): Flow<String> =
138138
}.buffer(Channel.UNLIMITED).collect(this)
139139
}
140140

141-
fun TokenStream.asReplyFlow(): Flow<StreamingChatLanguageModelReply> =
141+
public fun TokenStream.asReplyFlow(): Flow<StreamingChatLanguageModelReply> =
142142
flow {
143143
callbackFlow<StreamingChatLanguageModelReply> {
144144
onPartialResponse { token ->

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/request/ChatRequestExtensions.kt

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import dev.langchain4j.model.chat.request.ToolChoice
1717
* and/or parameters for the `ChatRequest`.
1818
* @return A fully constructed `ChatRequest` instance based on the applied configurations.
1919
*/
20-
fun chatRequest(block: ChatRequestBuilder.() -> Unit): ChatRequest {
20+
public fun chatRequest(block: ChatRequestBuilder.() -> Unit): ChatRequest {
2121
val builder = ChatRequestBuilder()
2222
builder.apply { block() }
2323
return builder.build()
@@ -44,19 +44,19 @@ fun chatRequest(block: ChatRequestBuilder.() -> Unit): ChatRequest {
4444
* @property responseFormat Specifies the format of the response, such as plain text or structured data.
4545
*/
4646
@Suppress("LongParameterList")
47-
open class ChatRequestParametersBuilder<B : DefaultChatRequestParameters.Builder<*>>(
48-
val builder: B,
49-
var modelName: String? = null,
50-
var temperature: Double? = null,
51-
var topP: Double? = null,
52-
var topK: Int? = null,
53-
var frequencyPenalty: Double? = null,
54-
var presencePenalty: Double? = null,
55-
var maxOutputTokens: Int? = null,
56-
var stopSequences: List<String>? = null,
57-
var toolSpecifications: List<ToolSpecification>? = null,
58-
var toolChoice: ToolChoice? = null,
59-
var responseFormat: ResponseFormat? = null,
47+
public open class ChatRequestParametersBuilder<B : DefaultChatRequestParameters.Builder<*>>(
48+
public val builder: B,
49+
public var modelName: String? = null,
50+
public var temperature: Double? = null,
51+
public var topP: Double? = null,
52+
public var topK: Int? = null,
53+
public var frequencyPenalty: Double? = null,
54+
public var presencePenalty: Double? = null,
55+
public var maxOutputTokens: Int? = null,
56+
public var stopSequences: List<String>? = null,
57+
public var toolSpecifications: List<ToolSpecification>? = null,
58+
public var toolChoice: ToolChoice? = null,
59+
public var responseFormat: ResponseFormat? = null,
6060
)
6161

6262
/**
@@ -66,25 +66,26 @@ open class ChatRequestParametersBuilder<B : DefaultChatRequestParameters.Builder
6666
* This builder provides methods to add individual or multiple chat messages,
6767
* as well as set request parameters for the generated `ChatRequest`.
6868
*/
69-
open class ChatRequestBuilder(
70-
var messages: MutableList<ChatMessage> = mutableListOf(),
71-
var parameters: ChatRequestParameters? = null,
69+
public open class ChatRequestBuilder(
70+
public var messages: MutableList<ChatMessage> = mutableListOf(),
71+
public var parameters: ChatRequestParameters? = null,
7272
) {
7373
/**
7474
* Adds a list of `ChatMessage` objects to the builder's messages collection.
7575
*
7676
* @param value The list of `ChatMessage` objects to be added to the builder.
7777
* @return This builder instance for chaining other method calls.
7878
*/
79-
fun messages(value: List<ChatMessage>) = apply { this.messages.addAll(value) }
79+
public fun messages(value: List<ChatMessage>): ChatRequestBuilder =
80+
apply { this.messages.addAll(value) }
8081

8182
/**
8283
* Adds a chat message to the messages list.
8384
*
8485
* @param value The chat message to be added.
8586
* @return The current instance for method chaining.
8687
*/
87-
fun message(value: ChatMessage) = apply { this.messages.add(value) }
88+
public fun message(value: ChatMessage): ChatRequestBuilder = apply { this.messages.add(value) }
8889

8990
/**
9091
* Builds and returns a ChatRequest instance using the current state of messages and parameters.
@@ -106,7 +107,7 @@ open class ChatRequestBuilder(
106107
* @param configurer A lambda with the builder as receiver to configure the chat request parameters.
107108
*/
108109
@JvmOverloads
109-
fun <B : DefaultChatRequestParameters.Builder<*>> parameters(
110+
public fun <B : DefaultChatRequestParameters.Builder<*>> parameters(
110111
@Suppress("UNCHECKED_CAST")
111112
builder: B = DefaultChatRequestParameters.builder() as B,
112113
configurer: ChatRequestParametersBuilder<B>.() -> Unit,

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/prompt/PromptTemplate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import me.kpavlov.langchain4j.kotlin.TemplateContent
1010
* incorporate variables or placeholders.
1111
*/
1212
public interface PromptTemplate {
13-
fun content(): TemplateContent
13+
public fun content(): TemplateContent
1414
}
1515

1616
/**
@@ -25,5 +25,5 @@ public interface PromptTemplate {
2525
public data class SimplePromptTemplate(
2626
private val content: TemplateContent,
2727
) : PromptTemplate {
28-
override fun content(): TemplateContent = content
28+
public override fun content(): TemplateContent = content
2929
}

langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/prompt/PromptTemplateSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import me.kpavlov.langchain4j.kotlin.TemplateName
99
* a template name. The implementation of this interface will determine
1010
* how and from where the templates are sourced.
1111
*/
12-
interface PromptTemplateSource {
12+
public interface PromptTemplateSource {
1313
/**
1414
* Retrieves a prompt template based on the provided template name.
1515
*
1616
* @param name The name of the template to retrieve.
1717
* @return The prompt template associated with the specified name, or null if no such template exists.
1818
*/
19-
fun getTemplate(name: TemplateName): PromptTemplate?
19+
public fun getTemplate(name: TemplateName): PromptTemplate?
2020
}

0 commit comments

Comments
 (0)