Skip to content

Commit

Permalink
Bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Buhake Sindi committed Dec 14, 2024
1 parent 084a1be commit 7506143
Showing 1 changed file with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.literal.NamedLiteral;
import jakarta.enterprise.inject.spi.DeploymentException;
import jakarta.enterprise.util.TypeLiteral;

import org.jboss.logging.Logger;
Expand Down Expand Up @@ -80,17 +78,12 @@ public static void createAllLLMBeans(LLMConfig llmConfig, Consumer<BeanData> bea
beanBuilder.accept(
new BeanData(targetClass, builderCLass, scopeClass, beanName,
(Instance<Object> creationalContext) -> {
try {
return CommonLLMPluginCreator.create(
creationalContext,
beanName,
targetClass,
builderCLass);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
throw new DeploymentException(e);
}
}));
return CommonLLMPluginCreator.create(
creationalContext,
beanName,
targetClass,
builderCLass);
}));
}
}
}
Expand Down Expand Up @@ -134,7 +127,7 @@ public Function<Instance<Object>, Object> getCallback() {
}

@SuppressWarnings("unchecked")
public static Object create(Instance<Object> lookup, String beanName, Class<?> targetClass, Class<?> builderClass) throws ClassNotFoundException {
public static Object create(Instance<Object> lookup, String beanName, Class<?> targetClass, Class<?> builderClass) {
LLMConfig llmConfig = LLMConfigProvider.getLlmConfig();
LOGGER.info(
"Create instance config:" + beanName + ", target class : " + targetClass + ", builderClass : " + builderClass);
Expand All @@ -156,24 +149,27 @@ public static Object create(Instance<Object> lookup, String beanName, Class<?> t
for (Method methodToCall : methodsToCall) {
Class<?> parameterType = methodToCall.getParameterTypes()[0];
if ("listeners".equals(property)) {
Class<?> typeParameterClass = ChatLanguageModel.class.isAssignableFrom(targetClass)
Class<?> typeParameterClass = ChatLanguageModel.class.isAssignableFrom(targetClass)
? ChatModelListener.class
: parameterType.getTypeParameters()[0].getGenericDeclaration();
List<Object> listeners = (List<Object>) Collections.checkedList(new ArrayList<>(), typeParameterClass);
List<Object> listeners = (List<Object>) Collections.checkedList(new ArrayList<>(),
typeParameterClass);
if ("@all".equals(stringValue.trim())) {
Instance<Object> inst = (Instance<Object>) getInstance(lookup, typeParameterClass);
if (inst != null) {
inst.forEach(listeners::add);
listeners = StreamSupport.stream(inst.spliterator(), false)
.collect(Collectors.toList());
}
Instance<Object> inst = (Instance<Object>) getInstance(lookup, typeParameterClass);
if (inst != null) {
inst.forEach(listeners::add);
}
} else {
for (String className : stringValue.split(",")) {
Instance<?> inst = getInstance(lookup, loadClass(className.trim()));
listeners.add(inst.get());
}
try {
for (String className : stringValue.split(",")) {
Instance<?> inst = getInstance(lookup, loadClass(className.trim()));
listeners.add(inst.get());
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}

if (listeners != null && !listeners.isEmpty()) {
listeners.stream().forEach(l -> LOGGER.info("Adding listener: " + l.getClass().getName()));
methodToCall.invoke(builder, listeners);
Expand Down

0 comments on commit 7506143

Please sign in to comment.