Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring, add Kotlin Notebook #20

Merged
merged 10 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

[pom.xml]
[*.xml]
indent_size = 4

[*.kt]
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"
10 changes: 10 additions & 0 deletions .idea/externalDependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Add the following dependencies to your `pom.xml`:
<!-- LangChain4j Kotlin Extensions -->
<dependency>
<groupId>me.kpavlov.langchain4j.kotlin</groupId>
<artifactId>langchain4j-core-kotlin</artifactId>
<artifactId>langchain4j-kotlin</artifactId>
<version>[LATEST_VERSION]</version>
</dependency>

Expand All @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

94 changes: 94 additions & 0 deletions langchain4j-kotlin/notebooks/lc4kNotebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Welcome to LangChain4j-Kotlin Notebook!"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-13T08:41:13.973072Z",
"start_time": "2024-11-13T08:41:11.937475Z"
}
},
"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, Langchani4j 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 Langchain4j?\n",
"\n",
"Because they found a new love in LLM that could handle their \"null\" feelings without throwing any exceptions!\n"
]
}
],
"execution_count": 36
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-11-13T08:39:55.837900Z",
"start_time": "2024-11-13T08:39:55.836524Z"
}
},
"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
}
Loading
Loading