orpiske commented on code in PR #21704:
URL: https://github.com/apache/camel/pull/21704#discussion_r2900007575
##########
components/camel-ai/camel-langchain4j-agent/src/main/java/org/apache/camel/component/langchain4j/agent/LangChain4jAgentConverter.java:
##########
@@ -191,10 +197,79 @@ public static AiAgentBody<?>
inputStreamToAiAgentBody(InputStream inputStream, E
}
}
+ /**
+ * Converts a {@link String} to an {@link AiAgentBody} with the
appropriate {@link Content} type.
+ * <p>
+ * This converter is useful for the text components that return Text Body.
+ * </p>
+ *
+ * @param text
+ * @param exchange
+ * @return an AiAgentBody with the appropriate Content type
+ */
+ @Converter
+ public static AiAgentBody<?> textToAiAgentBody(String text, Exchange
exchange) {
+ String userMessage = exchange.getIn().getHeader(USER_MESSAGE,
String.class);
+ String systemMessage = exchange.getIn().getHeader(SYSTEM_MESSAGE,
String.class);
+ Object memoryId = exchange.getIn().getHeader(MEMORY_ID);
+
+ TextContent content = TextContent.from(text);
+
+ AiAgentBody<TextContent> body = new AiAgentBody<>();
+ body.setUserMessage(userMessage != null ? userMessage : text);
+ body.setSystemMessage(systemMessage);
+ body.setMemoryId(memoryId);
+ body.setContent(content);
+ return body;
+ }
+
+ /**
+ * Converts a {@link String} to an {@link AiAgentBody} with the
appropriate {@link Content} type.
Review Comment:
That approach is correct, we just need to make sure any limitation or
expectation is documented (sorry I wasn't clear in my request earlier)
--
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]