Implement model-specific prompt handling in AdvancedAIPromptSolver

This commit is contained in:
andrea.terzani
2024-11-14 09:53:05 +01:00
parent c96f8a773a
commit 06d4989cc1

View File

@@ -66,17 +66,40 @@ public class AdvancedAIPromptSolver extends StepSolver {
String userText = this.qai_user_input;
Message userMessage = new UserMessage(userText);
Message systemMessage = new SystemMessage(this.qai_system_prompt_template);
CallResponseSpec resp = chatClient.prompt()
.messages(userMessage,systemMessage)
.advisors(advisor -> advisor
.param("chat_memory_conversation_id", this.scenarioExecution.getId()+this.qai_custom_memory_id)
.param("chat_memory_response_size", 100))
.call();
CallResponseSpec resp=null;
if( chatModel.getDefaultOptions().getModel().contains("o1-") ){
logger.info("Using o1- model => " + chatModel.getDefaultOptions().getModel());
String completePrompt = this.qai_system_prompt_template + userText;
resp = chatClient.prompt()
.messages(new UserMessage(completePrompt))
.advisors(advisor -> advisor
.param("chat_memory_conversation_id", this.scenarioExecution.getId()+this.qai_custom_memory_id)
.param("chat_memory_response_size", 100))
.call();
}else{
logger.info("Using standard model=> " + chatModel.getDefaultOptions().getModel());
Message userMessage = new UserMessage(userText);
Message systemMessage = new SystemMessage(this.qai_system_prompt_template);
resp = chatClient.prompt()
.messages(userMessage,systemMessage)
.advisors(advisor -> advisor
.param("chat_memory_conversation_id", this.scenarioExecution.getId()+this.qai_custom_memory_id)
.param("chat_memory_response_size", 100))
.call();
}
Usage usage = resp.chatResponse().getMetadata().getUsage();
if (usage != null) {
Long usedTokens = usage.getTotalTokens();
this.scenarioExecution.setUsedTokens(usedTokens);