-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- **Renamed and enhanced DocumentParserExtensions test:** - Test class renamed to `DocumentParserExtensionsKtTest` to adhere to Kotlin naming conventions. - Added a test case to validate the `parseAsync` method when no source metadata is available, ensuring proper document parsing. - **Added unit tests for ChatLanguageModel extensions:** - Implemented tests for `chatAsync` and `generateAsync` methods in `ChatLanguageModel`. - Updated README with a Codecov badge for enhanced code coverage visibility. - Ensures asynchronous chat processing functions correctly. --------- Co-authored-by: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...test/kotlin/me/kpavlov/langchain4j/kotlin/model/chat/ChatLanguageModelExtensionsKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package me.kpavlov.langchain4j.kotlin.model.chat | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import assertk.assertions.isSameInstanceAs | ||
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 | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
internal class ChatLanguageModelExtensionsKtTest { | ||
@Mock | ||
private lateinit var mockModel: ChatLanguageModel | ||
|
||
@Mock | ||
private lateinit var request: ChatRequest | ||
|
||
@Mock | ||
private lateinit var requestBuilder: ChatRequest.Builder | ||
|
||
@Mock | ||
private lateinit var expectedResponse: ChatResponse | ||
|
||
/** | ||
* This class tests the `chatAsync` extension function of `ChatLanguageModel`. | ||
* The function takes a `ChatRequest` or a `ChatRequest.Builder` as input, | ||
* performs asynchronous processing, and returns a `ChatResponse`. | ||
*/ | ||
|
||
@Test | ||
fun `chatAsync should return expected ChatResponse when using ChatRequest`() = | ||
runTest { | ||
whenever(mockModel.chat(request)).thenReturn(expectedResponse) | ||
|
||
val actualResponse = mockModel.chatAsync(request) | ||
|
||
assertThat(actualResponse).isEqualTo(expectedResponse) | ||
verify(mockModel).chat(request) | ||
} | ||
|
||
@Test | ||
fun `generateAsync should return expected AiMessage when using valid ChatMessages`() = | ||
runTest { | ||
val messages = mock<List<ChatMessage>>() | ||
val expectedAiMessage = mock<Response<AiMessage>>() | ||
|
||
whenever(mockModel.generate(messages)).thenReturn(expectedAiMessage) | ||
|
||
val actualAiMessage = mockModel.generateAsync(messages) | ||
|
||
assertThat(actualAiMessage).isSameInstanceAs(expectedAiMessage) | ||
} | ||
|
||
@Test | ||
fun `chatAsync should return expected ChatResponse when using ChatRequest Builder`() = | ||
runTest { | ||
whenever(requestBuilder.build()).thenReturn(request) | ||
whenever(mockModel.chat(request)).thenReturn(expectedResponse) | ||
|
||
val actualResponse = mockModel.chatAsync(requestBuilder) | ||
|
||
assertThat(actualResponse).isEqualTo(expectedResponse) | ||
verify(mockModel).chat(request) | ||
} | ||
|
||
@Test | ||
fun `chat should return expected ChatResponse when using ChatRequest Builder`() = | ||
runTest { | ||
whenever(requestBuilder.build()).thenReturn(request) | ||
whenever(mockModel.chat(request)).thenReturn(expectedResponse) | ||
|
||
val actualResponse = mockModel.chat(requestBuilder) | ||
|
||
assertThat(actualResponse).isEqualTo(expectedResponse) | ||
verify(mockModel).chat(request) | ||
} | ||
} |