@@ -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
@@ -54,7 +58,6 @@ static TemplatingModuleConfig toTemplateModuleConfig(
5458
5559 val template = config instanceof Template t ? t : Template .create ().template ();
5660 val messages = template .getTemplate ();
57- val responseFormat = template .getResponseFormat ();
5861 val messagesWithPrompt = new ArrayList <>(messages );
5962
6063 messagesWithPrompt .addAll (
@@ -69,7 +72,7 @@ static TemplatingModuleConfig toTemplateModuleConfig(
6972 .template (messagesWithPrompt )
7073 .tools (template .getTools ())
7174 .defaults (template .getDefaults ())
72- .responseFormat (responseFormat );
75+ .responseFormat (template . getResponseFormat () );
7376
7477 for (val customFieldName : template .getCustomFieldNames ()) {
7578 result .setCustomField (customFieldName , template .getCustomField (customFieldName ));
0 commit comments