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 ;
@@ -56,7 +58,8 @@ public AppBuilderRecommendServiceImpl(ChatModel chatModelService, AippModelCente
5658 }
5759
5860 @ Override
59- public List <String > queryRecommends (AppBuilderRecommendDto recommendDto , OperationContext context , boolean isGuest ) {
61+ public List <String > queryRecommends (AppBuilderRecommendDto recommendDto , OperationContext context ,
62+ boolean isGuest ) {
6063 // 游客模式下,需要查询应用所属用户名下的模型信息
6164 Map <String , Object > extensions = new HashMap <>();
6265 if (isGuest && recommendDto .getAppOwner () != null ) {
@@ -73,33 +76,29 @@ public List<String> queryRecommends(AppBuilderRecommendDto recommendDto, Operati
7376 + "inside <history></history> XML tags.\n <history>\n {{history}}\n </history>\n \n " ;
7477
7578 String recommendPrompt = "Please predict the three most likely questions that human would ask, "
76- + "and keeping each question under 20 characters.\n "
77- + "Do not include any explanations, "
79+ + "and keeping each question under 20 characters.\n " + "Do not include any explanations, "
7880 + "only provide output that strictly following the specified JSON format:\n "
7981 + "[\" question1\" ,\" question2\" ,\" question3\" ]\n " ;
82+ HumanMessageTemplate template = new HumanMessageTemplate (historyPrompt + recommendPrompt );
8083
8184 List <String > res ;
8285 try {
83- AiProcessFlow <Tip , String > flow = AiFlows .<Tip >create ()
84- .prompt (Prompts .human (historyPrompt + recommendPrompt ))
85- .generate (new ChatBlockModel (chatModelService )
86- .bind (ChatOption .custom ()
87- .model (model )
88- .stream (false )
89- .temperature (0.3 )
90- .baseUrl (modelAccessInfo .getBaseUrl ())
91- .secureConfig (modelAccessInfo .isSystemModel ()
92- ? null
93- : SecureConfig .custom ().ignoreTrust (true ).build ())
94- .apiKey (modelAccessInfo .getAccessKey ())
95- .extensions (extensions )
96- .build ()))
97- .map (ChatMessage ::text )
98- .close ();
86+ ChatOption option = ChatOption .custom ()
87+ .model (model )
88+ .stream (false )
89+ .temperature (0.3 )
90+ .baseUrl (modelAccessInfo .getBaseUrl ())
91+ .secureConfig (modelAccessInfo .isSystemModel ()
92+ ? null
93+ : SecureConfig .custom ().ignoreTrust (true ).build ())
94+ .apiKey (modelAccessInfo .getAccessKey ())
95+ .build ();
9996
100- String chatHistory = "User: " + recommendDto .getQuestion () + '\n' + "Assistant: " + recommendDto .getAnswer ()
101- + '\n' ;
102- String response = flow .converse ().offer (Tip .from ("history" , chatHistory )).await ();
97+ String chatHistory =
98+ "User: " + recommendDto .getQuestion () + '\n' + "Assistant: " + recommendDto .getAnswer () + '\n' ;
99+ String response =
100+ chatModelService .generate (ChatMessages .from (template .render (Tip .from ("history" , chatHistory )
101+ .freeze ())), option ).first ().block ().get ().text ();
103102
104103 res = JSONArray .parseArray (ContentProcessUtils .filterReasoningContent (response ), String .class );
105104 } catch (SerializationException | JSONException | IllegalStateException e ) {
0 commit comments