-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9102884
commit 31ed68c
Showing
30 changed files
with
3,408 additions
and
111 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/AiCacheBuildItem.java
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,16 @@ | ||
package io.quarkiverse.langchain4j.deployment; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class AiCacheBuildItem extends SimpleBuildItem { | ||
|
||
private boolean enable; | ||
|
||
public AiCacheBuildItem(boolean enable) { | ||
this.enable = enable; | ||
} | ||
|
||
public boolean isEnable() { | ||
return enable; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/AiCacheProcessor.java
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,65 @@ | ||
package io.quarkiverse.langchain4j.deployment; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.AnnotationTarget; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.ClassType; | ||
import org.jboss.jandex.IndexView; | ||
|
||
import io.quarkiverse.langchain4j.runtime.AiCacheRecorder; | ||
import io.quarkiverse.langchain4j.runtime.cache.AiCacheConfig; | ||
import io.quarkiverse.langchain4j.runtime.cache.AiCacheProvider; | ||
import io.quarkiverse.langchain4j.runtime.cache.AiCacheStore; | ||
import io.quarkus.arc.deployment.SyntheticBeanBuildItem; | ||
import io.quarkus.arc.deployment.UnremovableBeanBuildItem; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
|
||
public class AiCacheProcessor { | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.RUNTIME_INIT) | ||
void setupBeans(ChatMemoryBuildConfig buildConfig, AiCacheConfig cacheConfig, | ||
AiCacheRecorder recorder, | ||
CombinedIndexBuildItem indexBuildItem, | ||
BuildProducer<AiCacheBuildItem> aiCacheBuildItemProducer, | ||
BuildProducer<UnremovableBeanBuildItem> unremovableProducer, | ||
BuildProducer<SyntheticBeanBuildItem> syntheticBeanProducer) { | ||
|
||
IndexView index = indexBuildItem.getIndex(); | ||
boolean enableCache = false; | ||
|
||
for (AnnotationInstance instance : index.getAnnotations(LangChain4jDotNames.REGISTER_AI_SERVICES)) { | ||
if (instance.target().kind() != AnnotationTarget.Kind.CLASS) { | ||
continue; | ||
} | ||
|
||
ClassInfo declarativeAiServiceClassInfo = instance.target().asClass(); | ||
|
||
if (declarativeAiServiceClassInfo.hasAnnotation(LangChain4jDotNames.CACHE_RESULT)) { | ||
enableCache = true; | ||
break; | ||
} | ||
} | ||
|
||
aiCacheBuildItemProducer.produce(new AiCacheBuildItem(enableCache)); | ||
|
||
if (enableCache) { | ||
var configurator = SyntheticBeanBuildItem | ||
.configure(AiCacheProvider.class) | ||
.setRuntimeInit() | ||
.addInjectionPoint(ClassType.create(AiCacheStore.class)) | ||
.scope(ApplicationScoped.class) | ||
.createWith(recorder.messageWindow(cacheConfig)) | ||
.defaultBean(); | ||
|
||
syntheticBeanProducer.produce(configurator.done()); | ||
unremovableProducer.produce(UnremovableBeanBuildItem.beanTypes(AiCacheStore.class)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.