luigidemasi commented on code in PR #27494:
URL: https://github.com/apache/camel/pull/27494#discussion_r4216999298


##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/UnaryExpression.java:
##########
@@ -102,10 +103,7 @@ public void init(CamelContext context) {
 
             @Override
             public <T> T evaluate(Exchange exchange, Class<T> type) {
-                Object value = exp.evaluate(exchange, Object.class);
-                // the same rule the language uses for a predicate on its own, 
where ${body} is true and a missing
-                // header is false, so !${body} and !${header.foo} answer the 
opposite of those (CAMEL-24984)
-                boolean matches = ObjectHelper.evaluateValuePredicate(value);
+                boolean matches = 
ExpressionToPredicateAdapter.toPredicate(exp).matches(exchange);

Review Comment:
   Fixed in 
[2ad0b3a75251](https://github.com/apache/camel/commit/2ad0b3a75251700121823e954c49f9f975ef170d).
 `createNotExpression()` creates the predicate once, outside `evaluate()`, and 
retains the CAMEL-24984 explanation. Existing expressions keep value-based 
negation, including body and missing-header behavior; only the new 
`SimplePredicateExpression` opt-in uses the predicate contract. 
`SimpleNotOperatorTest` covers compatibility.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java:
##########
@@ -148,9 +149,8 @@ public void init(CamelContext context) {
 
             @Override
             public <T> T evaluate(Exchange exchange, Class<T> type) {
-                Object value = exp.evaluate(exchange, Object.class);
-                // the same rule the language uses for a predicate on its own 
(CAMEL-24984)
-                boolean matches = ObjectHelper.evaluateValuePredicate(value);
+                // Preserve a function's predicate contract, including 
semantic's boolean-only guard.
+                boolean matches = 
ExpressionToPredicateAdapter.toPredicate(exp).matches(exchange);

Review Comment:
   Fixed in 
[2ad0b3a75251](https://github.com/apache/camel/commit/2ad0b3a75251700121823e954c49f9f975ef170d).
 `createNegatedExpression()` builds its predicate once and reuses it for 
evaluation. The CAMEL-24984 comment and existing value-based semantics are 
retained; semantic expressions opt into predicate semantics through 
`SimplePredicateExpression`.
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
components/camel-ai/camel-typesafe-ai/src/main/java/org/apache/camel/component/typesafeai/TypeSafeAiSemanticAdapter.java:
##########
@@ -120,10 +187,47 @@ private SemanticResult result(SemanticQuestion question, 
JsonObject answer, Json
         if (answer.get("probabilities") instanceof Map<?, ?> values) {
             values.forEach((key, value) -> probabilities.put((String) key, 
((Number) value).doubleValue()));
         }
-        return new SemanticResult(
-                question.getType() == SemanticQuestion.Type.BOOLEAN ? null : 
answer.get(type(question)),
-                question.getType() == SemanticQuestion.Type.BOOLEAN ? 
answer.getDouble("noul") : null,
+        Double probability = question.getType() == 
SemanticQuestion.Type.BOOLEAN ? answer.getDouble("noul") : null;
+        Object value = switch (question.getType()) {
+            case BOOLEAN -> booleanDecision(question, probability);

Review Comment:
   The HTTP client rejects a missing `noul` with `IOException: Invalid TypeSafe 
AI response: Expected a number` before this mapping code runs. 
[96e6d465f016](https://github.com/apache/camel/commit/96e6d465f016856fb43c7e95b8e67818cda8112d)
 adds adapter-level HTTP regressions for missing `noul`, the named answer and 
`answers`. No duplicate null guard is needed here. Resolving following your 
confirmation in [your latest 
review](https://github.com/apache/camel/pull/27494#pullrequestreview-5453768092).
   
   _AI-generated by Codex on behalf of @luigidemasi._



##########
components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/SemanticQuestion.java:
##########
@@ -16,118 +16,178 @@
  */
 package org.apache.camel.semantic;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
-import java.util.Objects;
+import java.util.Set;
 
-/**
- * Immutable question definition. Probabilities and thresholds are 
provider-specific evidence, not accuracy guarantees.
- */
+/** Immutable evaluation declaration. The expert defines the operation, 
parameter vocabulary and result semantics. */
 public final class SemanticQuestion {
+    private static final Set<Class<?>> NUMBER_TYPES = Set.of(Byte.class, 
Short.class, Integer.class, Long.class,
+            Float.class, Double.class, BigInteger.class, BigDecimal.class);
+
     public enum Type {

Review Comment:
   Addressed in 
[2ad0b3a75251](https://github.com/apache/camel/commit/2ad0b3a75251700121823e954c49f9f975ef170d).
 The generic declaration is now `SemanticEvaluation`, containing only 
operation, expert, state and immutable parameters. The generic 
TypeSafe-specific enum, convenience constructors and policy getters were 
removed; operation mapping, policy defaults and interpretation live in 
`TypeSafeAiSemanticAdapter`.
   
   _AI-generated by Codex on behalf of @luigidemasi._



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to