Aggiungi supporto per temperatura personalizzata e strumenti nel solver AI
This commit is contained in:
@@ -2,9 +2,11 @@ package com.olympus.hermione.stepSolvers;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.chat.client.ChatClient.CallResponseSpec;
|
||||
import org.springframework.ai.chat.client.ChatClient.ChatClientRequestSpec;
|
||||
import org.springframework.ai.chat.memory.ChatMemory;
|
||||
import org.springframework.ai.chat.metadata.Usage;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.chat.prompt.ChatOptions;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -23,6 +25,10 @@ public class AdvancedAIPromptSolver extends StepSolver {
|
||||
private String qai_output_entityType;
|
||||
private String qai_custom_memory_id;
|
||||
private String qai_available_tools;
|
||||
private String qai_custom_temperaure;
|
||||
private String qai_custom_max_tokens;
|
||||
|
||||
private double customTemperature = 0.7;
|
||||
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(AdvancedAIPromptSolver.class);
|
||||
|
||||
@@ -61,6 +67,17 @@ public class AdvancedAIPromptSolver extends StepSolver {
|
||||
|
||||
this.qai_available_tools = (String) this.step.getAttributes().get("qai_available_tools");
|
||||
logger.info("qai_available_tools: {}", this.qai_available_tools);
|
||||
|
||||
this.qai_custom_temperaure = (String) this.step.getAttributes().get("qai_custom_temperature");
|
||||
if(this.qai_custom_temperaure !=null && !this.qai_custom_temperaure.isEmpty()){
|
||||
logger.info("qai_custom_temperature: {}", this.qai_custom_temperaure);
|
||||
customTemperature = Double.parseDouble(this.qai_custom_temperaure);
|
||||
logger.info("Custom temperature set to: {}", customTemperature);
|
||||
} else {
|
||||
logger.info("qai_custom_temperature not specified, using default value of 0.7");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,24 +147,34 @@ public class AdvancedAIPromptSolver extends StepSolver {
|
||||
} else {
|
||||
logger.info("No tools specified or available");
|
||||
}
|
||||
|
||||
|
||||
|
||||
CallResponseSpec resp=null;
|
||||
if(tools==null){
|
||||
logger.info("No tools available, calling chatClient without tools");
|
||||
resp = chatClient.prompt()
|
||||
ChatClientRequestSpec requestSpec = null;
|
||||
|
||||
requestSpec = chatClient.prompt()
|
||||
.user(this.qai_user_input)
|
||||
.system(this.qai_system_prompt_template)
|
||||
.advisors(advisor -> advisor.param(ChatMemory.CONVERSATION_ID, this.scenarioExecution.getId()+this.qai_custom_memory_id))
|
||||
.call();
|
||||
}else{
|
||||
.advisors(advisor -> advisor.param(ChatMemory.CONVERSATION_ID, this.scenarioExecution.getId()+this.qai_custom_memory_id));
|
||||
|
||||
if(tools!=null){
|
||||
logger.info("Calling chatClient with tools: {}", tools.getClass().getName());
|
||||
resp = chatClient.prompt()
|
||||
.user(this.qai_user_input)
|
||||
.system(this.qai_system_prompt_template)
|
||||
.advisors(advisor -> advisor
|
||||
.param(ChatMemory.CONVERSATION_ID, this.scenarioExecution.getId()+this.qai_custom_memory_id))
|
||||
.tools(tools)
|
||||
.call();
|
||||
requestSpec = requestSpec.tools(tools);
|
||||
}
|
||||
|
||||
if(this.qai_custom_temperaure!=null){
|
||||
logger.info("Setting custom temperature: {}", this.qai_custom_temperaure);
|
||||
ChatOptions chatOptions = ChatOptions.builder()
|
||||
.temperature(customTemperature)
|
||||
.build();
|
||||
requestSpec = requestSpec.options(chatOptions);
|
||||
}
|
||||
|
||||
resp = requestSpec.call();
|
||||
|
||||
|
||||
|
||||
ChatResponse response = null;
|
||||
if(qai_output_entityType!=null && qai_output_entityType.equals("CiaOutputEntity")){
|
||||
logger.info("Output is of type CiaOutputEntity");
|
||||
|
||||
Reference in New Issue
Block a user