77import static io .quarkiverse .langchain4j .deployment .LangChain4jDotNames .TOKEN_COUNT_ESTIMATOR ;
88
99import java .util .List ;
10- import java .util .function .Supplier ;
10+ import java .util .function .Function ;
1111
1212import jakarta .enterprise .context .ApplicationScoped ;
1313
1414import org .jboss .jandex .AnnotationInstance ;
15+ import org .jboss .jandex .ClassType ;
16+ import org .jboss .jandex .ParameterizedType ;
17+ import org .jboss .jandex .Type ;
1518
1619import dev .langchain4j .model .chat .ChatLanguageModel ;
1720import dev .langchain4j .model .chat .StreamingChatLanguageModel ;
1821import io .quarkiverse .langchain4j .ModelName ;
22+ import io .quarkiverse .langchain4j .deployment .DotNames ;
1923import io .quarkiverse .langchain4j .deployment .items .ChatModelProviderCandidateBuildItem ;
2024import io .quarkiverse .langchain4j .deployment .items .EmbeddingModelProviderCandidateBuildItem ;
2125import io .quarkiverse .langchain4j .deployment .items .ScoringModelProviderCandidateBuildItem ;
2630import io .quarkiverse .langchain4j .watsonx .runtime .WatsonxRecorder ;
2731import io .quarkiverse .langchain4j .watsonx .runtime .config .LangChain4jWatsonxConfig ;
2832import io .quarkiverse .langchain4j .watsonx .runtime .config .LangChain4jWatsonxFixedRuntimeConfig ;
33+ import io .quarkus .arc .SyntheticCreationalContext ;
2934import io .quarkus .arc .deployment .SyntheticBeanBuildItem ;
3035import io .quarkus .deployment .Capabilities ;
3136import io .quarkus .deployment .Capability ;
@@ -86,8 +91,8 @@ void generateBeans(WatsonxRecorder recorder, LangChain4jWatsonxConfig runtimeCon
8691 ? fixedRuntimeConfig .defaultConfig ().mode ()
8792 : fixedRuntimeConfig .namedConfig ().get (configName ).mode ();
8893
89- Supplier < ChatLanguageModel > chatLanguageModel ;
90- Supplier < StreamingChatLanguageModel > streamingChatLanguageModel ;
94+ Function < SyntheticCreationalContext < ChatLanguageModel >, ChatLanguageModel > chatLanguageModel ;
95+ Function < SyntheticCreationalContext < StreamingChatLanguageModel >, StreamingChatLanguageModel > streamingChatLanguageModel ;
9196
9297 if (mode .equalsIgnoreCase ("chat" )) {
9398 chatLanguageModel = recorder .chatModel (runtimeConfig , configName );
@@ -106,7 +111,9 @@ void generateBeans(WatsonxRecorder recorder, LangChain4jWatsonxConfig runtimeCon
106111 .setRuntimeInit ()
107112 .defaultBean ()
108113 .scope (ApplicationScoped .class )
109- .supplier (chatLanguageModel );
114+ .addInjectionPoint (ParameterizedType .create (DotNames .CDI_INSTANCE ,
115+ new Type [] { ClassType .create (DotNames .CHAT_MODEL_LISTENER ) }, null ))
116+ .createWith (chatLanguageModel );
110117
111118 addQualifierIfNecessary (chatBuilder , configName );
112119 beanProducer .produce (chatBuilder .done ());
@@ -116,7 +123,9 @@ void generateBeans(WatsonxRecorder recorder, LangChain4jWatsonxConfig runtimeCon
116123 .setRuntimeInit ()
117124 .defaultBean ()
118125 .scope (ApplicationScoped .class )
119- .supplier (chatLanguageModel );
126+ .addInjectionPoint (ParameterizedType .create (DotNames .CDI_INSTANCE ,
127+ new Type [] { ClassType .create (DotNames .CHAT_MODEL_LISTENER ) }, null ))
128+ .createWith (chatLanguageModel );
120129
121130 addQualifierIfNecessary (tokenizerBuilder , configName );
122131 beanProducer .produce (tokenizerBuilder .done ());
@@ -126,7 +135,9 @@ void generateBeans(WatsonxRecorder recorder, LangChain4jWatsonxConfig runtimeCon
126135 .setRuntimeInit ()
127136 .defaultBean ()
128137 .scope (ApplicationScoped .class )
129- .supplier (streamingChatLanguageModel );
138+ .addInjectionPoint (ParameterizedType .create (DotNames .CDI_INSTANCE ,
139+ new Type [] { ClassType .create (DotNames .CHAT_MODEL_LISTENER ) }, null ))
140+ .createWith (streamingChatLanguageModel );
130141
131142 addQualifierIfNecessary (streamingBuilder , configName );
132143 beanProducer .produce (streamingBuilder .done ());
@@ -171,9 +182,8 @@ private void addQualifierIfNecessary(SyntheticBeanBuildItem.ExtendedBeanConfigur
171182
172183 /**
173184 * When both {@code rest-client-jackson} and {@code rest-client-jsonb} are present on the classpath we need to make sure
174- * that Jackson is used.
175- * This is not a proper solution as it affects all clients, but it's better than the having the reader/writers be selected
176- * at random.
185+ * that Jackson is used. This is not a proper solution as it affects all clients, but it's better than the having the
186+ * reader/writers be selected at random.
177187 */
178188 @ BuildStep
179189 public void deprioritizeJsonb (Capabilities capabilities ,
0 commit comments