26
26
import java .util .Map ;
27
27
import java .util .function .Consumer ;
28
28
29
- import org .springframework .ai .chat .model .ChatModel ;
30
- import org .springframework .ai .chat .model .ChatResponse ;
31
- import org .springframework .ai .chat .model .StreamingChatModel ;
32
29
import reactor .core .publisher .Flux ;
33
30
34
31
import org .springframework .ai .chat .messages .Media ;
35
32
import org .springframework .ai .chat .messages .Message ;
36
33
import org .springframework .ai .chat .messages .SystemMessage ;
37
34
import org .springframework .ai .chat .messages .UserMessage ;
35
+ import org .springframework .ai .chat .model .ChatModel ;
36
+ import org .springframework .ai .chat .model .ChatResponse ;
37
+ import org .springframework .ai .chat .model .StreamingChatModel ;
38
38
import org .springframework .ai .chat .prompt .ChatOptions ;
39
39
import org .springframework .ai .chat .prompt .Prompt ;
40
40
import org .springframework .ai .chat .prompt .PromptTemplate ;
@@ -443,9 +443,7 @@ public <T> T entity(StructuredOutputConverter<T> structuredOutputConverter) {
443
443
}
444
444
445
445
private <T > T doSingleWithBeanOutputConverter (StructuredOutputConverter <T > boc ) {
446
- var processedUserText = this .request .userText + System .lineSeparator () + System .lineSeparator ()
447
- + "{format}" ;
448
- var chatResponse = doGetChatResponse (processedUserText , boc .getFormat ());
446
+ var chatResponse = doGetChatResponse (boc .getFormat ());
449
447
var stringResponse = chatResponse .getResult ().getOutput ().getContent ();
450
448
return boc .convert (stringResponse );
451
449
}
@@ -456,11 +454,15 @@ public <T> T entity(Class<T> type) {
456
454
return doSingleWithBeanOutputConverter (boc );
457
455
}
458
456
459
- private ChatResponse doGetChatResponse (String processedUserText ) {
460
- return this .doGetChatResponse (processedUserText , "" );
457
+ private ChatResponse doGetChatResponse () {
458
+ return this .doGetChatResponse ("" );
461
459
}
462
460
463
- private ChatResponse doGetChatResponse (String processedUserText , String formatParam ) {
461
+ private ChatResponse doGetChatResponse (String formatParam ) {
462
+
463
+ var processedUserText = StringUtils .hasText (formatParam )
464
+ ? this .request .userText + System .lineSeparator () + "{format}" : this .request .userText ;
465
+
464
466
Map <String , Object > userParams = new HashMap <>(this .request .userParams );
465
467
if (StringUtils .hasText (formatParam )) {
466
468
userParams .put ("format" , formatParam );
@@ -486,9 +488,6 @@ private ChatResponse doGetChatResponse(String processedUserText, String formatPa
486
488
messages .add (userMessage );
487
489
}
488
490
if (this .request .chatOptions instanceof FunctionCallingOptions functionCallingOptions ) {
489
- // if (this.request.chatOptions instanceof
490
- // FunctionCallingOptionsBuilder.PortableFunctionCallingOptions
491
- // functionCallingOptions) {
492
491
if (!this .request .functionNames .isEmpty ()) {
493
492
functionCallingOptions .setFunctions (new HashSet <>(this .request .functionNames ));
494
493
}
@@ -501,11 +500,11 @@ private ChatResponse doGetChatResponse(String processedUserText, String formatPa
501
500
}
502
501
503
502
public ChatResponse chatResponse () {
504
- return doGetChatResponse (this . request . userText );
503
+ return doGetChatResponse ();
505
504
}
506
505
507
506
public String content () {
508
- return doGetChatResponse (this . request . userText ).getResult ().getOutput ().getContent ();
507
+ return doGetChatResponse ().getResult ().getOutput ().getContent ();
509
508
}
510
509
511
510
}
0 commit comments