1212import modelengine .fel .core .chat .ChatMessage ;
1313import modelengine .fel .core .chat .ChatModel ;
1414import modelengine .fel .core .chat .ChatOption ;
15+ import modelengine .fel .core .chat .support .ChatMessages ;
1516import modelengine .fel .core .model .http .SecureConfig ;
17+ import modelengine .fel .core .template .support .HumanMessageTemplate ;
1618import modelengine .fel .core .util .Tip ;
1719import modelengine .fel .engine .flows .AiFlows ;
1820import modelengine .fel .engine .flows .AiProcessFlow ;
@@ -54,7 +56,8 @@ public AppBuilderRecommendServiceImpl(ChatModel chatModelService, AippModelCente
5456 }
5557
5658 @ Override
57- public List <String > queryRecommends (AppBuilderRecommendDto recommendDto , OperationContext context , boolean isGuest ) {
59+ public List <String > queryRecommends (AppBuilderRecommendDto recommendDto , OperationContext context ,
60+ boolean isGuest ) {
5861 // 游客模式下,需要查询应用所属用户名下的模型信息
5962 if (isGuest && recommendDto .getAppOwner () != null ) {
6063 context .setOperator (recommendDto .getAppOwner ());
@@ -67,32 +70,29 @@ public List<String> queryRecommends(AppBuilderRecommendDto recommendDto, Operati
6770 + "inside <history></history> XML tags.\n <history>\n {{history}}\n </history>\n \n " ;
6871
6972 String recommendPrompt = "Please predict the three most likely questions that human would ask, "
70- + "and keeping each question under 20 characters.\n "
71- + "Do not include any explanations, "
73+ + "and keeping each question under 20 characters.\n " + "Do not include any explanations, "
7274 + "only provide output that strictly following the specified JSON format:\n "
7375 + "[\" question1\" ,\" question2\" ,\" question3\" ]\n " ;
76+ HumanMessageTemplate template = new HumanMessageTemplate (historyPrompt + recommendPrompt );
7477
7578 List <String > res ;
7679 try {
77- AiProcessFlow <Tip , String > flow = AiFlows .<Tip >create ()
78- .prompt (Prompts .human (historyPrompt + recommendPrompt ))
79- .generate (new ChatBlockModel (chatModelService )
80- .bind (ChatOption .custom ()
81- .model (model )
82- .stream (false )
83- .temperature (0.3 )
84- .baseUrl (modelAccessInfo .getBaseUrl ())
85- .secureConfig (modelAccessInfo .isSystemModel ()
86- ? null
87- : SecureConfig .custom ().ignoreTrust (true ).build ())
88- .apiKey (modelAccessInfo .getAccessKey ())
89- .build ()))
90- .map (ChatMessage ::text )
91- .close ();
80+ ChatOption option = ChatOption .custom ()
81+ .model (model )
82+ .stream (false )
83+ .temperature (0.3 )
84+ .baseUrl (modelAccessInfo .getBaseUrl ())
85+ .secureConfig (modelAccessInfo .isSystemModel ()
86+ ? null
87+ : SecureConfig .custom ().ignoreTrust (true ).build ())
88+ .apiKey (modelAccessInfo .getAccessKey ())
89+ .build ();
9290
93- String chatHistory = "User: " + recommendDto .getQuestion () + '\n' + "Assistant: " + recommendDto .getAnswer ()
94- + '\n' ;
95- String response = flow .converse ().offer (Tip .from ("history" , chatHistory )).await ();
91+ String chatHistory =
92+ "User: " + recommendDto .getQuestion () + '\n' + "Assistant: " + recommendDto .getAnswer () + '\n' ;
93+ String response =
94+ chatModelService .generate (ChatMessages .from (template .render (Tip .from ("history" , chatHistory )
95+ .freeze ())), option ).first ().block ().get ().text ();
9696
9797 res = JSONArray .parseArray (ContentProcessUtils .filterReasoningContent (response ), String .class );
9898 } catch (SerializationException | JSONException | IllegalStateException e ) {
0 commit comments