@@ -22,20 +22,24 @@ final class ConfigToRequestTransformer {
2222 static CompletionPostRequest toCompletionPostRequest (
2323 @ Nonnull final OrchestrationPrompt prompt , @ Nonnull final OrchestrationModuleConfig config ) {
2424 val template = toTemplateModuleConfig (prompt , config .getTemplateConfig ());
25+
2526 // note that the config is immutable and implicitly copied here
2627 // copying is required here, to not alter the original config object, which might be reused for
2728 // subsequent requests
2829 val configCopy = config .withTemplateConfig (template );
2930
31+ val messageHistory =
32+ prompt .getMessagesHistory ().stream ()
33+ .map (Message ::createChatMessage )
34+ .map (ChatMessage .class ::cast )
35+ .toList ();
36+
37+ val moduleConfigs = toModuleConfigs (configCopy );
38+
3039 return CompletionPostRequest .create ()
31- .orchestrationConfig (
32- OrchestrationConfig .create ().moduleConfigurations (toModuleConfigs (configCopy )))
40+ .orchestrationConfig (OrchestrationConfig .create ().moduleConfigurations (moduleConfigs ))
3341 .inputParams (prompt .getTemplateParameters ())
34- .messagesHistory (
35- prompt .getMessagesHistory ().stream ()
36- .map (Message ::createChatMessage )
37- .map (ChatMessage .class ::cast )
38- .toList ());
42+ .messagesHistory (messageHistory );
3943 }
4044
4145 @ Nonnull
@@ -53,18 +57,18 @@ static TemplatingModuleConfig toTemplateModuleConfig(
5357 }
5458 val template = config instanceof Template t ? t : Template .create ().template ();
5559 val messages = template .getTemplate ();
56- val responseFormat = template .getResponseFormat ();
5760 val messagesWithPrompt = new ArrayList <>(messages );
5861 messagesWithPrompt .addAll (
5962 prompt .getMessages ().stream ().map (Message ::createChatMessage ).toList ());
6063 if (messagesWithPrompt .isEmpty ()) {
6164 throw new IllegalStateException (
6265 "A prompt is required. Pass at least one message or configure a template with messages or a template reference." );
6366 }
67+
6468 return Template .create ()
6569 .template (messagesWithPrompt )
6670 .tools (template .getTools ())
67- .responseFormat (responseFormat );
71+ .responseFormat (template . getResponseFormat () );
6872 }
6973
7074 @ Nonnull
0 commit comments