From 4722bae4a2e866c1d7fee3dcb2e7feff71f98e15 Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:15:42 +0200 Subject: [PATCH 01/10] Add ktlint function naming ignore for Test annotations Included a new setting in .editorconfig to ignore ktlint function naming rules for functions annotated with @Test. This will help in keeping test functions with descriptive names without triggering lint warnings. --- .editorconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.editorconfig b/.editorconfig index 6fc7e1c..6a662a1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -27,3 +27,5 @@ indent_size = 4 max_line_length = 100 ij_kotlin_name_count_to_use_star_import = 999 ij_kotlin_name_count_to_use_star_import_for_members = 999 +# noinspection EditorConfigKeyCorrectness +ktlint_function_naming_ignore_when_annotated_with = "Test" From c392f0e9cb0b99e82d367ea58e3484c53cdc703e Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:15:55 +0200 Subject: [PATCH 02/10] Refactor imports and reformat code Reorganized imports by changing package paths from `dev.langchain4j` to `me.kpavlov.langchain4j.kotlin`. Applied consistent formatting to improve code readability. No functional changes were made. --- .../langchain4j/kotlin}/internal/Logging.kt | 2 +- .../model/chat/ChatLanguageModelExtensions.kt | 15 +-- .../StreamingChatLanguageModelExtensions.kt | 75 ++++++----- .../langchain4j/kotlin/ChatLanguageModelIT.kt | 123 +++++++++--------- .../kotlin/StreamingChatLanguageModelIT.kt | 96 +++++++------- 5 files changed, 163 insertions(+), 148 deletions(-) rename langchain4j-core-kotlin/src/main/kotlin/{dev/langchain4j => me/kpavlov/langchain4j/kotlin}/internal/Logging.kt (63%) rename langchain4j-core-kotlin/src/main/kotlin/{dev/langchain4j => me/kpavlov/langchain4j/kotlin}/model/chat/ChatLanguageModelExtensions.kt (94%) rename langchain4j-core-kotlin/src/main/kotlin/{dev/langchain4j => me/kpavlov/langchain4j/kotlin}/model/chat/StreamingChatLanguageModelExtensions.kt (61%) diff --git a/langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/internal/Logging.kt b/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt similarity index 63% rename from langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/internal/Logging.kt rename to langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt index c404544..19d9354 100644 --- a/langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/internal/Logging.kt +++ b/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt @@ -1,4 +1,4 @@ -package dev.langchain4j.internal +package me.kpavlov.langchain4j.kotlin.internal import org.slf4j.MarkerFactory diff --git a/langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/model/chat/ChatLanguageModelExtensions.kt b/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt similarity index 94% rename from langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/model/chat/ChatLanguageModelExtensions.kt rename to langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt index 9b0747d..b2b7ec4 100644 --- a/langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/model/chat/ChatLanguageModelExtensions.kt +++ b/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt @@ -1,7 +1,8 @@ -package dev.langchain4j.model.chat +package me.kpavlov.langchain4j.kotlin.model.chat import dev.langchain4j.data.message.AiMessage import dev.langchain4j.data.message.ChatMessage +import dev.langchain4j.model.chat.ChatLanguageModel import dev.langchain4j.model.chat.request.ChatRequest import dev.langchain4j.model.chat.response.ChatResponse import dev.langchain4j.model.output.Response @@ -55,9 +56,8 @@ suspend fun ChatLanguageModel.chatAsync(request: ChatRequest): ChatResponse { * @see ChatRequest.Builder * @see chatAsync */ -suspend fun ChatLanguageModel.chatAsync(requestBuilder: ChatRequest.Builder): ChatResponse { - return chatAsync(requestBuilder.build()) -} +suspend fun ChatLanguageModel.chatAsync(requestBuilder: ChatRequest.Builder): ChatResponse = + chatAsync(requestBuilder.build()) /** * Processes a chat request using a [ChatRequest.Builder] for convenient request @@ -82,9 +82,8 @@ suspend fun ChatLanguageModel.chatAsync(requestBuilder: ChatRequest.Builder): Ch * @see ChatResponse * @see ChatRequest.Builder */ -fun ChatLanguageModel.chat(requestBuilder: ChatRequest.Builder): ChatResponse { - return this.chat(requestBuilder.build()) -} +fun ChatLanguageModel.chat(requestBuilder: ChatRequest.Builder): ChatResponse = + this.chat(requestBuilder.build()) /** * Asynchronously generates a response for a list of chat messages using @@ -113,5 +112,3 @@ suspend fun ChatLanguageModel.generateAsync(messages: List): Respon val model = this return coroutineScope { model.generate(messages) } } - - diff --git a/langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/model/chat/StreamingChatLanguageModelExtensions.kt b/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt similarity index 61% rename from langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/model/chat/StreamingChatLanguageModelExtensions.kt rename to langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt index e8c6bc9..93e60c9 100644 --- a/langchain4j-core-kotlin/src/main/kotlin/dev/langchain4j/model/chat/StreamingChatLanguageModelExtensions.kt +++ b/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt @@ -1,13 +1,14 @@ -package dev.langchain4j.model.chat +package me.kpavlov.langchain4j.kotlin.model.chat import dev.langchain4j.data.message.AiMessage import dev.langchain4j.data.message.ChatMessage -import dev.langchain4j.internal.PII import dev.langchain4j.model.StreamingResponseHandler +import dev.langchain4j.model.chat.StreamingChatLanguageModel import dev.langchain4j.model.output.Response import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow +import me.kpavlov.langchain4j.kotlin.internal.PII import org.slf4j.LoggerFactory private val logger = LoggerFactory.getLogger(StreamingChatLanguageModel::class.java) @@ -22,14 +23,19 @@ sealed interface StreamingChatLanguageModelReply { * * @property token The individual token string generated by the model. */ - data class Token(val token: String) : StreamingChatLanguageModelReply + data class Token( + val token: String, + ) : StreamingChatLanguageModelReply + /** * Represents the complete response received at the end of the streaming process. * This includes the final message along with any additional metadata. * * @property response The complete response containing the AI message and associated metadata. */ - data class Completion(val response: Response) : StreamingChatLanguageModelReply + data class Completion( + val response: Response, + ) : StreamingChatLanguageModelReply } /** @@ -64,37 +70,42 @@ sealed interface StreamingChatLanguageModelReply { */ fun StreamingChatLanguageModel.generateFlow( messages: List, -): Flow = callbackFlow { - - val model = this@generateFlow +): Flow = + callbackFlow { + val model = this@generateFlow - val handler = object : StreamingResponseHandler { - override fun onNext(token: String) { - logger.trace(PII, "Received token: {}", token) - trySend(StreamingChatLanguageModelReply.Token(token)) - } + val handler = + object : StreamingResponseHandler { + override fun onNext(token: String) { + logger.trace( + me.kpavlov.langchain4j.kotlin.internal.PII, + "Received token: {}", + token, + ) + trySend(StreamingChatLanguageModelReply.Token(token)) + } - override fun onComplete(response: Response) { - logger.trace(PII, "Received response: {}", response) - trySend(StreamingChatLanguageModelReply.Completion(response)) - close() - } + override fun onComplete(response: Response) { + logger.trace( + me.kpavlov.langchain4j.kotlin.internal.PII, + "Received response: {}", + response, + ) + trySend(StreamingChatLanguageModelReply.Completion(response)) + close() + } - override fun onError(error: Throwable) { - close(error) - } - } + override fun onError(error: Throwable) { + close(error) + } + } - logger.info("Starting flow...") - model.generate(messages, handler) + logger.info("Starting flow...") + model.generate(messages, handler) - // This will be called when the flow collection is closed or cancelled. - awaitClose { - // cleanup - logger.info("Flow is canceled") + // This will be called when the flow collection is closed or cancelled. + awaitClose { + // cleanup + logger.info("Flow is canceled") + } } -} - - - - diff --git a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt b/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt index b6ea8ab..20ee54c 100644 --- a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt +++ b/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt @@ -3,94 +3,97 @@ package me.kpavlov.langchain4j.kotlin import assertk.assertThat import assertk.assertions.contains import assertk.assertions.isNotNull -import assertk.assertions.isSuccess import dev.langchain4j.data.document.Document -import dev.langchain4j.data.document.DocumentLoader -import dev.langchain4j.data.document.parser.TextDocumentParser -import dev.langchain4j.data.document.source.FileSystemSource import dev.langchain4j.data.message.SystemMessage import dev.langchain4j.data.message.UserMessage import dev.langchain4j.model.chat.ChatLanguageModel -import dev.langchain4j.model.chat.chatAsync -import dev.langchain4j.model.chat.generateAsync import dev.langchain4j.model.chat.request.ChatRequest import dev.langchain4j.model.chat.request.ResponseFormat import dev.langchain4j.model.openai.OpenAiChatModel import kotlinx.coroutines.test.runTest +import me.kpavlov.langchain4j.kotlin.model.chat.chatAsync +import me.kpavlov.langchain4j.kotlin.model.chat.generateAsync import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.slf4j.LoggerFactory -import java.nio.file.Paths @TestInstance(TestInstance.Lifecycle.PER_CLASS) internal class ChatLanguageModelIT { - private val logger = LoggerFactory.getLogger(javaClass) - private val model: ChatLanguageModel = OpenAiChatModel - .builder() - .apiKey("demo") - .modelName("gpt-4o-mini") - .temperature(0.0) - .maxTokens(1024) - .build() + private val model: ChatLanguageModel = + OpenAiChatModel + .builder() + .apiKey("demo") + .modelName("gpt-4o-mini") + .temperature(0.0) + .maxTokens(1024) + .build() private lateinit var document: Document @BeforeAll - fun beforeAll() = runTest { - document = loadDocument("notes/blumblefang.txt", logger) - } + fun beforeAll() = + runTest { + document = loadDocument("notes/blumblefang.txt", logger) + } @Test - fun `ChatLanguageModel should generateAsync`() = runTest { + fun `ChatLanguageModel should generateAsync`() = + runTest { + val response = + model.generateAsync( + listOf( + SystemMessage.from( + """ + You are helpful advisor answering questions only related to the given text - val response = model.generateAsync( - listOf( - SystemMessage.from( - """ - You are helpful advisor answering questions only related to the given text""" - .trimIndent() - ), - UserMessage.from( - """ - What does Blumblefang love? Text: ```${document.text()}``` - """.trimIndent() - ), - ) - ) + """.trimIndent(), + ), + UserMessage.from( + """ + What does Blumblefang love? Text: ```${document.text()}``` + """.trimIndent(), + ), + ), + ) - logger.info("Response: {}", response); - assertThat(response).isNotNull() - val content = response.content() - assertThat(content.text()).contains("Blumblefang loves to help") - } + logger.info("Response: {}", response) + assertThat(response).isNotNull() + val content = response.content() + assertThat(content.text()).contains("Blumblefang loves to help") + } @Test - fun `ChatLanguageModel should chatAsync`() = runTest { + fun `ChatLanguageModel should chatAsync`() = + runTest { + val document = loadDocument("notes/blumblefang.txt", logger) - val document = loadDocument("notes/blumblefang.txt", logger) + val response = + model.chatAsync( + ChatRequest + .builder() + .messages( + listOf( + SystemMessage.from( + """ + You are helpful advisor answering questions only related to the given text - val response = model.chatAsync(ChatRequest.builder() - .messages(listOf( - SystemMessage.from( - """ - You are helpful advisor answering questions only related to the given text""" - .trimIndent() - ), - UserMessage.from( - """ - What does Blumblefang love? Text: ```${document.text()}``` - """.trimIndent() - ), - )) - .responseFormat(ResponseFormat.TEXT) - ) + """.trimIndent(), + ), + UserMessage.from( + """ + What does Blumblefang love? Text: ```${document.text()}``` + """.trimIndent(), + ), + ), + ).responseFormat(ResponseFormat.TEXT), + ) - logger.info("Response: {}", response); - assertThat(response).isNotNull() - val content = response.aiMessage() - assertThat(content.text()).contains("Blumblefang loves to help") - } + logger.info("Response: {}", response) + assertThat(response).isNotNull() + val content = response.aiMessage() + assertThat(content.text()).contains("Blumblefang loves to help") + } } diff --git a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt b/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt index 3aaa7fc..cae14a5 100644 --- a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt +++ b/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt @@ -9,12 +9,12 @@ import dev.langchain4j.data.message.ChatMessage import dev.langchain4j.data.message.SystemMessage import dev.langchain4j.data.message.UserMessage import dev.langchain4j.model.chat.StreamingChatLanguageModel -import dev.langchain4j.model.chat.StreamingChatLanguageModelReply.Completion -import dev.langchain4j.model.chat.StreamingChatLanguageModelReply.Token -import dev.langchain4j.model.chat.generateFlow import dev.langchain4j.model.openai.OpenAiStreamingChatModel import dev.langchain4j.model.output.Response import kotlinx.coroutines.test.runTest +import me.kpavlov.langchain4j.kotlin.model.chat.StreamingChatLanguageModelReply.Completion +import me.kpavlov.langchain4j.kotlin.model.chat.StreamingChatLanguageModelReply.Token +import me.kpavlov.langchain4j.kotlin.model.chat.generateFlow import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test @@ -23,58 +23,62 @@ import java.util.concurrent.atomic.AtomicReference @Disabled("Run it manually") class StreamingChatLanguageModelIT { - private val logger = LoggerFactory.getLogger(javaClass) - private val model: StreamingChatLanguageModel = OpenAiStreamingChatModel - .builder() - .apiKey(TestEnvironment.env("OPENAI_API_KEY")) - .modelName("gpt-4o-mini") - .temperature(0.0) - .maxTokens(100) - .build() + private val model: StreamingChatLanguageModel = + OpenAiStreamingChatModel + .builder() + .apiKey(TestEnvironment.env("OPENAI_API_KEY")) + .modelName("gpt-4o-mini") + .temperature(0.0) + .maxTokens(100) + .build() @Test - fun `StreamingChatLanguageModel should generateFlow`() = runTest { - val document = loadDocument("notes/blumblefang.txt", logger) + fun `StreamingChatLanguageModel should generateFlow`() = + runTest { + val document = loadDocument("notes/blumblefang.txt", logger) - val messages = listOf( - SystemMessage.from( - """ - You are helpful advisor answering questions only related to the given text""" - .trimIndent() - ), - UserMessage.from( - """ - What does Blumblefang love? Text: ```${document.text()}``` - """.trimIndent() - ), - ) + val messages = + listOf( + SystemMessage.from( + """ + You are helpful advisor answering questions only related to the given text - val responseRef = AtomicReference?>() + """.trimIndent(), + ), + UserMessage.from( + """ + What does Blumblefang love? Text: ```${document.text()}``` + """.trimIndent(), + ), + ) - val collectedTokens = mutableListOf() + val responseRef = AtomicReference?>() - model.generateFlow(messages) - .collect { - logger.info("Received event: $it") - when (it) { - is Token -> { - logger.info("Token: '${it.token}'") - collectedTokens.add(it.token) - } + val collectedTokens = mutableListOf() - is Completion -> responseRef.set(it.response) - else -> fail("Unsupported event: $it") + model + .generateFlow(messages) + .collect { + logger.info("Received event: $it") + when (it) { + is Token -> { + logger.info("Token: '${it.token}'") + collectedTokens.add(it.token) + } + + is Completion -> responseRef.set(it.response) + else -> fail("Unsupported event: $it") + } } - } - val response = responseRef.get()!! - assertThat(response.metadata()).isNotNull() - val content = response.content() - assertThat(content).isNotNull() - assertThat(collectedTokens.joinToString("")) - .isEqualTo(content.text()) - assertThat(content.text()).contains("Blumblefang loves to help") - } + val response = responseRef.get()!! + assertThat(response.metadata()).isNotNull() + val content = response.content() + assertThat(content).isNotNull() + assertThat(collectedTokens.joinToString("")) + .isEqualTo(content.text()) + assertThat(content.text()).contains("Blumblefang loves to help") + } } From 3d06833e4e2b3bddedef956f4d4db637fe553caf Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:21:45 +0200 Subject: [PATCH 03/10] Rename langchain4j-core-kotlin to langchain4j-kotlin Refactor project structure by renaming all occurrences of langchain4j-core-kotlin to langchain4j-kotlin. This includes updates to file paths, Maven POM files, and module references to ensure consistency and clarity in the project hierarchy. --- {langchain4j-core-kotlin => langchain4j-kotlin}/pom.xml | 8 +++++--- .../me/kpavlov/langchain4j/kotlin/internal/Logging.kt | 0 .../kotlin/model/chat/ChatLanguageModelExtensions.kt | 0 .../model/chat/StreamingChatLanguageModelExtensions.kt | 0 .../me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt | 0 .../kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt | 0 .../langchain4j/kotlin/StreamingChatLanguageModelIT.kt | 0 .../me/kpavlov/langchain4j/kotlin/TestEnvironment.kt | 0 .../src/test/resources/data/books/captain-blood.txt | 0 .../src/test/resources/data/notes/blumblefang.txt | 0 .../src/test/resources/data/notes/quantum-computing.txt | 0 pom.xml | 4 ++-- reports/pom.xml | 5 +++-- 13 files changed, 10 insertions(+), 7 deletions(-) rename {langchain4j-core-kotlin => langchain4j-kotlin}/pom.xml (81%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/test/resources/data/books/captain-blood.txt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/test/resources/data/notes/blumblefang.txt (100%) rename {langchain4j-core-kotlin => langchain4j-kotlin}/src/test/resources/data/notes/quantum-computing.txt (100%) diff --git a/langchain4j-core-kotlin/pom.xml b/langchain4j-kotlin/pom.xml similarity index 81% rename from langchain4j-core-kotlin/pom.xml rename to langchain4j-kotlin/pom.xml index 4e54ed9..32c4d34 100644 --- a/langchain4j-core-kotlin/pom.xml +++ b/langchain4j-kotlin/pom.xml @@ -1,13 +1,15 @@ - + 4.0.0 me.kpavlov.langchain4j.kotlin - langchain4j-kotlin-aggregator + root 0.1.1-SNAPSHOT + ../pom.xml - langchain4j-core-kotlin + langchain4j-kotlin LangChain4j-Kotlin :: Core diff --git a/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt b/langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt similarity index 100% rename from langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt rename to langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/internal/Logging.kt diff --git a/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt b/langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt similarity index 100% rename from langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt rename to langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensions.kt diff --git a/langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt b/langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt similarity index 100% rename from langchain4j-core-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt rename to langchain4j-kotlin/src/main/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/StreamingChatLanguageModelExtensions.kt diff --git a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt similarity index 100% rename from langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt rename to langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt diff --git a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt similarity index 100% rename from langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt rename to langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt diff --git a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt similarity index 100% rename from langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt rename to langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt diff --git a/langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt similarity index 100% rename from langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt rename to langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt diff --git a/langchain4j-core-kotlin/src/test/resources/data/books/captain-blood.txt b/langchain4j-kotlin/src/test/resources/data/books/captain-blood.txt similarity index 100% rename from langchain4j-core-kotlin/src/test/resources/data/books/captain-blood.txt rename to langchain4j-kotlin/src/test/resources/data/books/captain-blood.txt diff --git a/langchain4j-core-kotlin/src/test/resources/data/notes/blumblefang.txt b/langchain4j-kotlin/src/test/resources/data/notes/blumblefang.txt similarity index 100% rename from langchain4j-core-kotlin/src/test/resources/data/notes/blumblefang.txt rename to langchain4j-kotlin/src/test/resources/data/notes/blumblefang.txt diff --git a/langchain4j-core-kotlin/src/test/resources/data/notes/quantum-computing.txt b/langchain4j-kotlin/src/test/resources/data/notes/quantum-computing.txt similarity index 100% rename from langchain4j-core-kotlin/src/test/resources/data/notes/quantum-computing.txt rename to langchain4j-kotlin/src/test/resources/data/notes/quantum-computing.txt diff --git a/pom.xml b/pom.xml index f7eeeae..23e89e3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 me.kpavlov.langchain4j.kotlin - langchain4j-kotlin-aggregator + root 0.1.1-SNAPSHOT pom LangChain4j-Kotlin :: Aggregator @@ -11,7 +11,7 @@ https://github.com/kpavlov/langchain4j-kotlin - langchain4j-core-kotlin + langchain4j-kotlin reports diff --git a/reports/pom.xml b/reports/pom.xml index bf93b6d..a511211 100644 --- a/reports/pom.xml +++ b/reports/pom.xml @@ -3,8 +3,9 @@ 4.0.0 me.kpavlov.langchain4j.kotlin - langchain4j-kotlin-aggregator + root 0.1.1-SNAPSHOT + ../pom.xml reports @@ -14,7 +15,7 @@ me.kpavlov.langchain4j.kotlin - langchain4j-core-kotlin + langchain4j-kotlin ${project.parent.version} From 02a3b93ec6482ab98067338c3fa7b6db444f8acd Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:41:38 +0200 Subject: [PATCH 04/10] Add Finchly and JUnit dependencies, refactor TestEnvironment Integrated Finchly and JUnit dependencies to improve testing capabilities. Refactored TestEnvironment to utilize Finchly's BaseTestEnvironment for better environment variable handling. Updated tests to leverage the new TestEnvironment setup. --- langchain4j-kotlin/pom.xml | 10 +++++++ .../langchain4j/kotlin/ChatLanguageModelIT.kt | 2 +- .../kotlin/StreamingChatLanguageModelIT.kt | 9 ++++--- .../langchain4j/kotlin/TestEnvironment.kt | 19 +++---------- pom.xml | 27 ++++++++++--------- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/langchain4j-kotlin/pom.xml b/langchain4j-kotlin/pom.xml index 32c4d34..fadd51d 100644 --- a/langchain4j-kotlin/pom.xml +++ b/langchain4j-kotlin/pom.xml @@ -27,6 +27,11 @@ ${slf4j.version} + + org.junit.jupiter + junit-jupiter-api + test + dev.langchain4j langchain4j @@ -37,6 +42,11 @@ langchain4j-open-ai test + + me.kpavlov.finchly + finchly + test + diff --git a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt index 20ee54c..1a55ef8 100644 --- a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt +++ b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt @@ -25,7 +25,7 @@ internal class ChatLanguageModelIT { private val model: ChatLanguageModel = OpenAiChatModel .builder() - .apiKey("demo") + .apiKey(TestEnvironment.openaiApiKey) .modelName("gpt-4o-mini") .temperature(0.0) .maxTokens(1024) diff --git a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt index cae14a5..cfa6461 100644 --- a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt +++ b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt @@ -16,19 +16,22 @@ import me.kpavlov.langchain4j.kotlin.model.chat.StreamingChatLanguageModelReply. import me.kpavlov.langchain4j.kotlin.model.chat.StreamingChatLanguageModelReply.Token import me.kpavlov.langchain4j.kotlin.model.chat.generateFlow import org.junit.jupiter.api.Assertions.fail -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable import org.slf4j.LoggerFactory import java.util.concurrent.atomic.AtomicReference -@Disabled("Run it manually") +@EnabledIfEnvironmentVariable( + named = "OPENAI_API_KEY", + matches = ".+", +) class StreamingChatLanguageModelIT { private val logger = LoggerFactory.getLogger(javaClass) private val model: StreamingChatLanguageModel = OpenAiStreamingChatModel .builder() - .apiKey(TestEnvironment.env("OPENAI_API_KEY")) + .apiKey(TestEnvironment.openaiApiKey) .modelName("gpt-4o-mini") .temperature(0.0) .maxTokens(100) diff --git a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt index 0c07fed..8e65690 100644 --- a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt +++ b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt @@ -1,18 +1,7 @@ package me.kpavlov.langchain4j.kotlin -import io.github.cdimascio.dotenv.dotenv -import org.slf4j.LoggerFactory -import java.nio.file.Paths - -private val logger = LoggerFactory.getLogger(TestEnvironment.javaClass) - -object TestEnvironment { - private val dotenv = - dotenv { - directory = Paths.get("${System.getProperty("user.dir")}/..").normalize().toString() - logger.info("Loading .env file from $directory") - ignoreIfMissing = true - } - - fun env(name: String) = dotenv.get(name) +object TestEnvironment : me.kpavlov.finchly.BaseTestEnvironment( + dotEnvFileDir = "../", +) { + val openaiApiKey = TestEnvironment.get("OPENAI_API_KEY", "demo") } diff --git a/pom.xml b/pom.xml index 23e89e3..53d2dc8 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ 4.2.2 6.4.2 + 0.1.1 5.11.3 1.9.0 0.35.0 @@ -65,6 +66,13 @@ pom import + + org.junit + junit-bom + ${junit.version} + pom + import + org.slf4j slf4j-simple @@ -77,6 +85,13 @@ 0.28.1 test + + me.kpavlov.finchly + finchly + ${finchly.version} + test + + @@ -99,18 +114,6 @@ ${dotenv-kotlin.version} test - - org.jetbrains.kotlin - kotlin-test-junit5 - test - - - org.junit.jupiter - junit-jupiter - ${junit.version} - test - - org.jetbrains.kotlinx kotlinx-coroutines-test From 38690715cab4678a3a4a5e088f722c94334bbd0f Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:41:58 +0200 Subject: [PATCH 05/10] Add .idea/externalDependencies.xml and update .editorconfig Include configuration for external dependencies in IntelliJ IDEA project. Update .editorconfig to standardize XML file indentation across the project. --- .editorconfig | 2 +- .idea/externalDependencies.xml | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .idea/externalDependencies.xml diff --git a/.editorconfig b/.editorconfig index 6a662a1..138c31d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,7 +19,7 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false -[pom.xml] +[*.xml] indent_size = 4 [*.kt] diff --git a/.idea/externalDependencies.xml b/.idea/externalDependencies.xml new file mode 100644 index 0000000..315bdfc --- /dev/null +++ b/.idea/externalDependencies.xml @@ -0,0 +1,10 @@ + + + + + + + + + + From a63c37075f4976a892ca75387448f8186dab9732 Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:44:47 +0200 Subject: [PATCH 06/10] Change artifactId in README for consistency Updated the artifactId in the dependency examples within README.md from 'langchain4j-core-kotlin' to 'langchain4j-kotlin'. This ensures consistency with the actual naming conventions used in the project. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf93add..866d77c 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Add the following dependencies to your `pom.xml`: me.kpavlov.langchain4j.kotlin - langchain4j-core-kotlin + langchain4j-kotlin [LATEST_VERSION] @@ -47,7 +47,7 @@ Add the following to your `build.gradle.kts`: ```kotlin dependencies { - implementation("me.kpavlov.langchain4j.kotlin:langchain4j-core-kotlin:$LATEST_VERSION") + implementation("me.kpavlov.langchain4j.kotlin:langchain4j-kotlin:$LATEST_VERSION") implementation("dev.langchain4j:langchain4j-core") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm") } From 987756204e86d6492ba687c11b5e3abcead39e7c Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:54:41 +0200 Subject: [PATCH 07/10] Add linting and developer info to project Removed explicit slf4j version in dependency. Updated Makefile and README with lint commands. Enhanced pom.xml with project metadata and linting profile. --- Makefile | 6 ++ README.md | 6 +- langchain4j-kotlin/pom.xml | 1 - .../kpavlov/langchain4j/kotlin/Documents.kt | 5 +- pom.xml | 80 +++++++++++++------ 5 files changed, 69 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index df04911..50873f9 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,8 @@ build: mvn clean verify site + +lint: + # brew install ktlint + ktlint --format + # https://docs.openrewrite.org/recipes/maven/bestpractices + mvn rewrite:run -P lint diff --git a/README.md b/README.md index 866d77c..80c9bb9 100644 --- a/README.md +++ b/README.md @@ -113,11 +113,15 @@ Using Make: make build ``` - ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. +Run before submitting your changes +```shell +make lint +``` + ## Acknowledgements - [LangChain4j](https://github.com/langchain4j/langchain4j) - The core library this project enhances diff --git a/langchain4j-kotlin/pom.xml b/langchain4j-kotlin/pom.xml index fadd51d..245a69b 100644 --- a/langchain4j-kotlin/pom.xml +++ b/langchain4j-kotlin/pom.xml @@ -24,7 +24,6 @@ org.slf4j slf4j-api - ${slf4j.version} diff --git a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt index 9853f1b..c2818ae 100644 --- a/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt +++ b/langchain4j-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/Documents.kt @@ -7,7 +7,10 @@ import dev.langchain4j.data.document.source.FileSystemSource import org.slf4j.Logger import java.nio.file.Paths -suspend fun loadDocument(documentName: String,logger: Logger) : Document { +suspend fun loadDocument( + documentName: String, + logger: Logger, +): Document { val source = FileSystemSource(Paths.get("./src/test/resources/data/$documentName")) val document = DocumentLoader.load(source, TextDocumentParser()) diff --git a/pom.xml b/pom.xml index 53d2dc8..c3cec4e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 me.kpavlov.langchain4j.kotlin @@ -10,11 +11,36 @@ Kotlin enhancements for LangChain4j https://github.com/kpavlov/langchain4j-kotlin + + + MIT License + https://opensource.org/license/mit + + + + + + Konstantin Pavlov + https://kpavlov.me + + author + owner + + + + langchain4j-kotlin reports + + scm:git:git://github.com/kpavlov/langchain4j-kotlin.git + scm:git:ssh://github.com/kpavlov/langchain4j-kotlin.git + https://github.com/kpavlov/langchain4j-kotlin/tree/main + HEAD + + UTF-8 official @@ -137,10 +163,12 @@ + org.apache.maven.plugins maven-surefire-plugin 3.5.2 + org.apache.maven.plugins maven-failsafe-plugin 3.5.2 @@ -185,6 +213,11 @@ maven-javadoc-plugin 3.11.1 + + org.apache.maven.plugins + maven-project-info-reports-plugin + 3.6.2 + @@ -215,6 +248,7 @@ + org.apache.maven.plugins maven-failsafe-plugin @@ -287,31 +321,6 @@ - - scm:git:git://github.com/kpavlov/langchain4j-kotlin.git - scm:git:ssh://github.com/kpavlov/langchain4j-kotlin.git - https://github.com/kpavlov/langchain4j-kotlin/tree/main - HEAD - - - - - MIT License - https://opensource.org/license/mit - - - - - - Konstantin Pavlov - https://kpavlov.me - - author - owner - - - - release @@ -358,6 +367,25 @@ + + lint + + + + org.openrewrite.maven + rewrite-maven-plugin + 5.43.0 + + true + + org.openrewrite.maven.BestPractices + + true + + + + + From b21b158e7e2feabf00ccb353fd78ff135ba5ea7b Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:37:30 +0200 Subject: [PATCH 08/10] Remove dotenv-kotlin dependency from pom.xml dotenv-kotlin dependency was removed to clean up unused dependencies. This change helps in reducing the build complexity and potential maintenance issues arising from redundant library versions. --- pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pom.xml b/pom.xml index c3cec4e..c77520e 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,6 @@ ${java.version} 4.2.2 - 6.4.2 0.1.1 5.11.3 1.9.0 @@ -117,7 +116,6 @@ ${finchly.version} test - @@ -134,12 +132,6 @@ ${awaitility.version} test - - io.github.cdimascio - dotenv-kotlin - ${dotenv-kotlin.version} - test - org.jetbrains.kotlinx kotlinx-coroutines-test From 8bf7aff0dd97630d2fbd173e33a9b7939f187027 Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:37:43 +0200 Subject: [PATCH 09/10] Add initial Kotlin Notebook for LangChain4j This commit introduces a Jupyter notebook set up for LangChain4j in Kotlin, including dependencies and a simple demonstration of generating a joke using OpenAiChatModel. The notebook aims to provide a starting point for users to experiment with LangChain4j's capabilities in a Kotlin environment. --- .../notebooks/lc4kNotebook.ipynb | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 langchain4j-kotlin/notebooks/lc4kNotebook.ipynb diff --git a/langchain4j-kotlin/notebooks/lc4kNotebook.ipynb b/langchain4j-kotlin/notebooks/lc4kNotebook.ipynb new file mode 100644 index 0000000..c09a214 --- /dev/null +++ b/langchain4j-kotlin/notebooks/lc4kNotebook.ipynb @@ -0,0 +1,112 @@ +{ + "cells": [ + { + "metadata": {}, + "cell_type": "markdown", + "source": "# Welcome to LangChain4j-Kotlin Notebook!" + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-11-13T08:35:39.189257Z", + "start_time": "2024-11-13T08:35:39.148534Z" + } + }, + "cell_type": "code", + "source": [ + "@file:DependsOn(\"me.kpavlov.langchain4j.kotlin:langchain4j-core-kotlin:0.1.0\")\n", + "@file:DependsOn(\"dev.langchain4j:langchain4j:0.35.0\")\n", + "@file:DependsOn(\"dev.langchain4j:langchain4j-open-ai:0.35.0\")\n", + "// Add your project's target/classes to classpath\n", + "@file:DependsOn(\"../target/classes\")" + ], + "outputs": [], + "execution_count": 25 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-11-13T08:35:40.666480Z", + "start_time": "2024-11-13T08:35:39.193189Z" + } + }, + "cell_type": "code", + "source": [ + "import dev.langchain4j.model.chat.generateAsync\n", + "import dev.langchain4j.model.openai.OpenAiChatModel\n", + "import dev.langchain4j.data.message.SystemMessage\n", + "import dev.langchain4j.data.message.UserMessage\n", + "import kotlinx.coroutines.runBlocking\n", + "\n", + "val model = OpenAiChatModel\n", + " .builder()\n", + " .apiKey(\"demo\")\n", + " .modelName(\"gpt-4o-mini\")\n", + " .temperature(0.0)\n", + " .maxTokens(1024)\n", + " .build()\n", + "\n", + "runBlocking {\n", + " val result = model.generateAsync(\n", + " listOf(\n", + " SystemMessage.from(\"You are helpful assistant\"),\n", + " UserMessage.from(\"make a joke about Kotlin and LLM\"),\n", + " )\n", + " )\n", + " \n", + " println(result.content().text())\n", + "}\n", + "\n", + " \n", + " " + ], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Why did the Kotlin developer break up with the LLM?\n", + "\n", + "Because every time they tried to have a conversation, the LLM kept saying, \"I can't infer your type!\"\n" + ] + } + ], + "execution_count": 26 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2024-11-13T08:35:40.732569Z", + "start_time": "2024-11-13T08:35:40.731444Z" + } + }, + "cell_type": "code", + "source": "", + "outputs": [], + "execution_count": null + } + ], + "metadata": { + "kernelspec": { + "display_name": "Kotlin", + "language": "kotlin", + "name": "kotlin" + }, + "language_info": { + "name": "kotlin", + "version": "1.9.23", + "mimetype": "text/x-kotlin", + "file_extension": ".kt", + "pygments_lexer": "kotlin", + "codemirror_mode": "text/x-kotlin", + "nbconvert_exporter": "" + }, + "ktnbPluginMetadata": { + "projectDependencies": [ + "langchain4j-kotlin" + ] + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From 4e5a050c8acec646d94a764b3811b9ba9079805c Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com> Date: Wed, 13 Nov 2024 10:43:04 +0200 Subject: [PATCH 10/10] Update joke content and timestamps in lc4kNotebook.ipynb Revised the joke text to include Langchain4j and modified its punchline for better context. Adjusted the timestamps and execution counts of certain cells to reflect the latest execution time and sequence. --- .../notebooks/lc4kNotebook.ipynb | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/langchain4j-kotlin/notebooks/lc4kNotebook.ipynb b/langchain4j-kotlin/notebooks/lc4kNotebook.ipynb index c09a214..d1187ec 100644 --- a/langchain4j-kotlin/notebooks/lc4kNotebook.ipynb +++ b/langchain4j-kotlin/notebooks/lc4kNotebook.ipynb @@ -8,26 +8,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2024-11-13T08:35:39.189257Z", - "start_time": "2024-11-13T08:35:39.148534Z" - } - }, - "cell_type": "code", - "source": [ - "@file:DependsOn(\"me.kpavlov.langchain4j.kotlin:langchain4j-core-kotlin:0.1.0\")\n", - "@file:DependsOn(\"dev.langchain4j:langchain4j:0.35.0\")\n", - "@file:DependsOn(\"dev.langchain4j:langchain4j-open-ai:0.35.0\")\n", - "// Add your project's target/classes to classpath\n", - "@file:DependsOn(\"../target/classes\")" - ], - "outputs": [], - "execution_count": 25 - }, - { - "metadata": { - "ExecuteTime": { - "end_time": "2024-11-13T08:35:40.666480Z", - "start_time": "2024-11-13T08:35:39.193189Z" + "end_time": "2024-11-13T08:41:13.973072Z", + "start_time": "2024-11-13T08:41:11.937475Z" } }, "cell_type": "code", @@ -50,7 +32,7 @@ " val result = model.generateAsync(\n", " listOf(\n", " SystemMessage.from(\"You are helpful assistant\"),\n", - " UserMessage.from(\"make a joke about Kotlin and LLM\"),\n", + " UserMessage.from(\"Make a joke about Kotlin, Langchani4j and LLM\"),\n", " )\n", " )\n", " \n", @@ -65,19 +47,19 @@ "name": "stdout", "output_type": "stream", "text": [ - "Why did the Kotlin developer break up with the LLM?\n", + "Why did the Kotlin developer break up with Langchain4j?\n", "\n", - "Because every time they tried to have a conversation, the LLM kept saying, \"I can't infer your type!\"\n" + "Because they found a new love in LLM that could handle their \"null\" feelings without throwing any exceptions!\n" ] } ], - "execution_count": 26 + "execution_count": 36 }, { "metadata": { "ExecuteTime": { - "end_time": "2024-11-13T08:35:40.732569Z", - "start_time": "2024-11-13T08:35:40.731444Z" + "end_time": "2024-11-13T08:39:55.837900Z", + "start_time": "2024-11-13T08:39:55.836524Z" } }, "cell_type": "code",