Skip to content

Commit cf1cdab

Browse files
kpavlovKonstantin Pavlov
andauthored
Refactoring, add Kotlin Notebook (#20)
This pull request includes several changes to improve code consistency, add new features, and clean up the repository. The most important changes include the renaming of modules, updates to documentation, addition of linting tools, and removal of outdated test files. ### Module Renaming: * Renamed `langchain4j-core-kotlin` module to `langchain4j-kotlin` and updated references in `pom.xml` and source files accordingly. [[1]](diffhunk://#diff-988dd67f6a0de416687ee39291f2713a8229de37918339f305c4ec8ae58e539bL2-R12) [[2]](diffhunk://#diff-86cfcde484068926e474ebf795f51332ad7f830a07465ac97aea6f887d026b25L1-R1) [[3]](diffhunk://#diff-a767044c70bcc37001555b8e9ad4479ead9a4e0b45fe1107fb666affe030c55dL1-R5) [[4]](diffhunk://#diff-fb4b6067883a6e0b3179329be99cfe11aef1c673ab8fcdb4d96d1f28bb05ac48L1-R11) ### Documentation Updates: * Updated `README.md` to reflect the new artifact ID for Maven and Gradle dependencies. Also, added instructions for running linting before submitting changes. [[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L28-R28) [[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L50-R50) [[3]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L116-R124) ### Linting Tools: * Added `.editorconfig` settings for XML files and Kotlin specific settings. * Introduced linting commands in `Makefile` and added external dependencies for linting in `.idea/externalDependencies.xml`. [[1]](diffhunk://#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R3-R8) [[2]](diffhunk://#diff-28f6bd7cae82cae961bd9e592c97303c3fcbee726488ffeb5353710114b94659R1-R10) ### Test Files Cleanup: * Removed outdated integration test files and environment configuration files. [[1]](diffhunk://#diff-bf22a8e4a133639655c76accff8d4890f5b2039ff577f0e32cb85dc3aaee3b49L1-L96) [[2]](diffhunk://#diff-b1bcb0799c4402f3288a7949cb2a16a9ef4593810b438586cb7ac0b15e426bdcL1-L80) [[3]](diffhunk://#diff-caf79976057a1796247141661e8d2ecf64678198930c7d55e5ddb8790048df20L1-L18) ### New Features: * Added a new Jupyter notebook for `langchain4j-kotlin` to demonstrate usage examples. --------- Co-authored-by: Konstantin Pavlov <{ID}+{username}@users.noreply.github.com>
1 parent 0eb66ac commit cf1cdab

File tree

21 files changed

+455
-294
lines changed

21 files changed

+455
-294
lines changed

.editorconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ insert_final_newline = true
1919
[*.md]
2020
trim_trailing_whitespace = false
2121

22-
[pom.xml]
22+
[*.xml]
2323
indent_size = 4
2424

2525
[*.kt]
2626
indent_size = 4
2727
max_line_length = 100
2828
ij_kotlin_name_count_to_use_star_import = 999
2929
ij_kotlin_name_count_to_use_star_import_for_members = 999
30+
# noinspection EditorConfigKeyCorrectness
31+
ktlint_function_naming_ignore_when_annotated_with = "Test"

.idea/externalDependencies.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
build:
22
mvn clean verify site
3+
4+
lint:
5+
# brew install ktlint
6+
ktlint --format
7+
# https://docs.openrewrite.org/recipes/maven/bestpractices
8+
mvn rewrite:run -P lint

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Add the following dependencies to your `pom.xml`:
2525
<!-- LangChain4j Kotlin Extensions -->
2626
<dependency>
2727
<groupId>me.kpavlov.langchain4j.kotlin</groupId>
28-
<artifactId>langchain4j-core-kotlin</artifactId>
28+
<artifactId>langchain4j-kotlin</artifactId>
2929
<version>[LATEST_VERSION]</version>
3030
</dependency>
3131

@@ -47,7 +47,7 @@ Add the following to your `build.gradle.kts`:
4747

4848
```kotlin
4949
dependencies {
50-
implementation("me.kpavlov.langchain4j.kotlin:langchain4j-core-kotlin:$LATEST_VERSION")
50+
implementation("me.kpavlov.langchain4j.kotlin:langchain4j-kotlin:$LATEST_VERSION")
5151
implementation("dev.langchain4j:langchain4j-core")
5252
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm")
5353
}
@@ -113,11 +113,15 @@ Using Make:
113113
make build
114114
```
115115

116-
117116
## Contributing
118117

119118
Contributions are welcome! Please feel free to submit a Pull Request.
120119

120+
Run before submitting your changes
121+
```shell
122+
make lint
123+
```
124+
121125
## Acknowledgements
122126

123127
- [LangChain4j](https://github.com/langchain4j/langchain4j) - The core library this project enhances

langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/ChatLanguageModelIT.kt

Lines changed: 0 additions & 96 deletions
This file was deleted.

langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/StreamingChatLanguageModelIT.kt

Lines changed: 0 additions & 80 deletions
This file was deleted.

langchain4j-core-kotlin/src/test/kotlin/me/kpavlov/langchain4j/kotlin/TestEnvironment.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"cells": [
3+
{
4+
"metadata": {},
5+
"cell_type": "markdown",
6+
"source": "# Welcome to LangChain4j-Kotlin Notebook!"
7+
},
8+
{
9+
"metadata": {
10+
"ExecuteTime": {
11+
"end_time": "2024-11-13T08:41:13.973072Z",
12+
"start_time": "2024-11-13T08:41:11.937475Z"
13+
}
14+
},
15+
"cell_type": "code",
16+
"source": [
17+
"import dev.langchain4j.model.chat.generateAsync\n",
18+
"import dev.langchain4j.model.openai.OpenAiChatModel\n",
19+
"import dev.langchain4j.data.message.SystemMessage\n",
20+
"import dev.langchain4j.data.message.UserMessage\n",
21+
"import kotlinx.coroutines.runBlocking\n",
22+
"\n",
23+
"val model = OpenAiChatModel\n",
24+
" .builder()\n",
25+
" .apiKey(\"demo\")\n",
26+
" .modelName(\"gpt-4o-mini\")\n",
27+
" .temperature(0.0)\n",
28+
" .maxTokens(1024)\n",
29+
" .build()\n",
30+
"\n",
31+
"runBlocking {\n",
32+
" val result = model.generateAsync(\n",
33+
" listOf(\n",
34+
" SystemMessage.from(\"You are helpful assistant\"),\n",
35+
" UserMessage.from(\"Make a joke about Kotlin, Langchani4j and LLM\"),\n",
36+
" )\n",
37+
" )\n",
38+
" \n",
39+
" println(result.content().text())\n",
40+
"}\n",
41+
"\n",
42+
" \n",
43+
" "
44+
],
45+
"outputs": [
46+
{
47+
"name": "stdout",
48+
"output_type": "stream",
49+
"text": [
50+
"Why did the Kotlin developer break up with Langchain4j?\n",
51+
"\n",
52+
"Because they found a new love in LLM that could handle their \"null\" feelings without throwing any exceptions!\n"
53+
]
54+
}
55+
],
56+
"execution_count": 36
57+
},
58+
{
59+
"metadata": {
60+
"ExecuteTime": {
61+
"end_time": "2024-11-13T08:39:55.837900Z",
62+
"start_time": "2024-11-13T08:39:55.836524Z"
63+
}
64+
},
65+
"cell_type": "code",
66+
"source": "",
67+
"outputs": [],
68+
"execution_count": null
69+
}
70+
],
71+
"metadata": {
72+
"kernelspec": {
73+
"display_name": "Kotlin",
74+
"language": "kotlin",
75+
"name": "kotlin"
76+
},
77+
"language_info": {
78+
"name": "kotlin",
79+
"version": "1.9.23",
80+
"mimetype": "text/x-kotlin",
81+
"file_extension": ".kt",
82+
"pygments_lexer": "kotlin",
83+
"codemirror_mode": "text/x-kotlin",
84+
"nbconvert_exporter": ""
85+
},
86+
"ktnbPluginMetadata": {
87+
"projectDependencies": [
88+
"langchain4j-kotlin"
89+
]
90+
}
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 0
94+
}

0 commit comments

Comments
 (0)