Skip to content

Commit

Permalink
add redis store module and fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Jun 21, 2024
1 parent 462e6c2 commit 29d3ef8
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 38 deletions.
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ micronaut-core = "4.5.3"
micronaut-platform = "4.5.0"
micronaut-docs = "2.0.0"
micronaut-serde = "2.10.1"
micronaut-redis = "6.4.0"
micronaut-test = "4.2.1"
micronaut-test-resources = "2.5.0"
micronaut-logging = "1.3.0"
Expand All @@ -34,6 +35,7 @@ managed-langchain4j = "0.31.0"

[libraries]
micronaut-core = { module = 'io.micronaut:micronaut-core-bom', version.ref = 'micronaut-core' }
micronaut-redis = { module = 'io.micronaut.redis:micronaut-redis-bom', version.ref = 'micronaut-redis' }
micronaut-logging = { module = 'io.micronaut.logging:micronaut-logging-bom', version.ref = 'micronaut-logging' }
micronaut-serde = { module = 'io.micronaut.serde:micronaut-serde-bom', version.ref = 'micronaut-serde' }
micronaut-sourcegen = { module = 'io.micronaut.sourcegen:micronaut-sourcegen-bom', version.ref = 'micronaut-sourcegen' }
Expand All @@ -47,6 +49,8 @@ langchain4j-vertex-ai = { module = 'dev.langchain4j:langchain4j-vertex-ai', vers
langchain4j-mistral-ai = { module = 'dev.langchain4j:langchain4j-mistral-ai', version.ref = "managed-langchain4j" }
langchain4j-open-ai = { module = 'dev.langchain4j:langchain4j-open-ai', version.ref = "managed-langchain4j" }
langchain4j-azure-open-ai = { module = 'dev.langchain4j:langchain4j-azure-open-ai', version.ref = "managed-langchain4j" }
langchain4j-redis = { module = 'dev.langchain4j:langchain4j-redis', version.ref = "managed-langchain4j" }


# BOMs
boms-langchain4j = { module = "dev.langchain4j:langchain4j-bom", version.ref = "managed-langchain4j" }
Expand Down
20 changes: 1 addition & 19 deletions micronaut-langchain4j-bom/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
plugins {
id("io.micronaut.build.internal.langchain4j-module")
}

dependencies {
annotationProcessor(mn.micronaut.inject.java)

api(mn.micronaut.context)
api(mn.micronaut.json.core)
}

tasks {
test {
systemProperty("micronaut.databind", "generated")
}

// compileJava {
// options.isFork = true
// options.forkOptions.jvmArgs = listOf("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
// }
id("io.micronaut.build.internal.bom")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package io.micronaut.langchain4j.annotation;

import io.micronaut.aop.Introduction;
import io.micronaut.context.annotation.AliasFor;
import io.micronaut.core.annotation.AnnotationMetadata;
import io.micronaut.core.annotation.ReflectiveAccess;
import jakarta.inject.Named;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
Expand All @@ -33,7 +36,8 @@
* The name of a configured AI model.
* @return The model name.
*/
String modelName() default "";
@AliasFor(annotation = Named.class, member = AnnotationMetadata.VALUE_MEMBER)
String named() default "";

/**
* The types of the tools to include. Can be set to an empty array to include none.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import java.util.Set;
import javax.lang.model.element.Modifier;

public class Langchain4jModelVisitor implements TypeElementVisitor<Lang4jConfig, Object> {
public class Langchain4jConfigVisitor implements TypeElementVisitor<Lang4jConfig, Object> {
public static final String CONFIG_PREFIX = "langchain4j.";
private static final Map<String, String> MODEL_NAME_MAPPINGS = Map.of(
"ChatLanguageModel", "ChatModel",
Expand Down Expand Up @@ -162,6 +162,7 @@ private static RecordDef buildCommonConfig(ClassElement element, VisitorContext
String prefix = firstConfig.getCommonPrefix();
RecordDef.RecordDefBuilder recordDefBuilder = RecordDef.builder(packageName + "." + commonConfigSimpleName)
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Context.class)
.addAnnotation(AnnotationDef.builder(Requires.class)
.addMember("property", prefix)
.build())
Expand Down Expand Up @@ -282,7 +283,7 @@ private ClassDef buildFactory(
.addModifiers(Modifier.PROTECTED)
.addAnnotation(Context.class)
.addAnnotation(AnnotationDef.builder(Bean.class)
.addMember("typed", new VariableDef.StaticField(TypeDef.of(languageModelKind), "class", TypeDef.of(Class.class)))
.addMember("typed", new VariableDef.StaticField(ClassTypeDef.of(languageModelKind.getRawClassElement().getName()), "class", TypeDef.of(Class.class)))
.build())
.addAnnotation(AnnotationDef.builder(EachBean.class)
.addMember("value", new VariableDef.StaticField(builderTypeDef, "class", TypeDef.of(Class.class)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.micronaut.langchain4j.processor.Langchain4jModelVisitor
io.micronaut.langchain4j.processor.Langchain4jConfigVisitor
15 changes: 15 additions & 0 deletions micronaut-langchain4j-store-redis/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id("io.micronaut.build.internal.langchain4j-module")
}

dependencies {
annotationProcessor(projects.micronautLangchain4jProcessor)
annotationProcessor(mn.micronaut.inject.java)
annotationProcessor(mnSourcegen.micronaut.sourcegen.generator.java)
api(projects.micronautLangchain4jCore)
implementation(libs.langchain4j.redis)
testAnnotationProcessor(mn.micronaut.inject.java)
testImplementation(mnTest.micronaut.test.junit5)
testRuntimeOnly(mnLogging.logback.classic)
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2017-2024 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.langchain4j.redis;

import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.redis.RedisEmbeddingStore;
import io.micronaut.langchain4j.annotation.Lang4jConfig;

@Lang4jConfig(
models = @Lang4jConfig.Model(
kind = EmbeddingStore.class,
impl = RedisEmbeddingStore.class
)
)
final class RedisModule {
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ include("micronaut-langchain4j-vertexai")
include("micronaut-langchain4j-mistralai")
include("micronaut-langchain4j-vertexai-gemini")
include("micronaut-langchain4j-ollama-testresource")
include("micronaut-langchain4j-store-redis")
include("doc-examples:example-groovy")
include("doc-examples:example-java")
include("doc-examples:example-kotlin")
Expand All @@ -44,5 +45,6 @@ configure<io.micronaut.build.MicronautBuildSettingsExtension> {
importMicronautCatalog("micronaut-test-resources")
importMicronautCatalog("micronaut-logging")
importMicronautCatalog("micronaut-serde")
importMicronautCatalog("micronaut-redis")
// importMicronautCatalog("micronaut-validation")
}
2 changes: 1 addition & 1 deletion src/main/docs/guide/chatModels/anthropic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.anthropic
.Example Configuration
[configuration]
----
langchain4j.anthropic.api-key=YOUR_KEY
langchain4j.anthropic.api-key: YOUR_KEY
----
4 changes: 2 additions & 2 deletions src/main/docs/guide/chatModels/azure.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.azure.Com
.Example Configuration
[configuration]
----
langchain4j.azure-open-ai.api-key=YOUR_KEY
langchain4j.azure-open-ai.endpoint=YOUR_ENDPOINT
langchain4j.azure-open-ai.api-key: YOUR_KEY
langchain4j.azure-open-ai.endpoint: YOUR_ENDPOINT
----

You will additionally need to define a bean of type https://learn.microsoft.com/en-us/java/api/com.azure.core.credential.tokencredential?view=azure-java-stable[TokenCredentials].
Expand Down
2 changes: 1 addition & 1 deletion src/main/docs/guide/chatModels/bedrock.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.bedrock.C
.Example Configuration
[configuration]
----
langchain4j.bedrock-llama.api-key=YOUR_KEY
langchain4j.bedrock-llama.api-key: YOUR_KEY
----

You will additionally need to define a bean of type https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/AwsCredentialsProvider.html[AwsCredentialsProvider].
Expand Down
2 changes: 1 addition & 1 deletion src/main/docs/guide/chatModels/mistralai.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.mistralai
.Example Configuration
[configuration]
----
langchain4j.mistral-ai.api-key=YOUR_KEY
langchain4j.mistral-ai.api-key: YOUR_KEY
----
2 changes: 1 addition & 1 deletion src/main/docs/guide/chatModels/ollama.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.ollama.Co
.Example Configuration
[configuration]
----
langchain4j.ollama.base-url=YOUR_URL
langchain4j.ollama.base-url: YOUR_URL
----
2 changes: 1 addition & 1 deletion src/main/docs/guide/chatModels/openai.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.openai.Co
.Example Configuration
[configuration]
----
langchain4j.open-ai.api-key=YOUR_KEY
langchain4j.open-ai.api-key: YOUR_KEY
----
6 changes: 3 additions & 3 deletions src/main/docs/guide/chatModels/vertexai-gemini.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.vertexai.
.Example Configuration
[configuration]
----
langchain4j.vertex-ai-gemini.model-name=YOUR_MODEL
langchain4j.vertex-ai-gemini.project=YOUR_PROJECT
langchain4j.vertex-ai-gemini.location=YOUR_LOCATION
langchain4j.vertex-ai-gemini.model-name: YOUR_MODEL
langchain4j.vertex-ai-gemini.project: YOUR_PROJECT
langchain4j.vertex-ai-gemini.location: YOUR_LOCATION
----
10 changes: 5 additions & 5 deletions src/main/docs/guide/chatModels/vertexai.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Then add the link:configurationreference.html#io.micronaut.langchain4j.vertexai.
.Example Configuration
[configuration]
----
langchain4j.vertex-ai.endpoint=YOUR_ENDPOINT
langchain4j.vertex-ai.model-name=YOUR_MODEL
langchain4j.vertex-ai.project=YOUR_PROJECT
langchain4j.vertex-ai.location=YOUR_LOCATION
langchain4j.vertex-ai.publisher=YOUR_PUBLISHER
langchain4j.vertex-ai.endpoint: YOUR_ENDPOINT
langchain4j.vertex-ai.model-name: YOUR_MODEL
langchain4j.vertex-ai.project: YOUR_PROJECT
langchain4j.vertex-ai.location: YOUR_LOCATION
langchain4j.vertex-ai.publisher: YOUR_PUBLISHER
----

0 comments on commit 29d3ef8

Please sign in to comment.