update summarize 2
This commit is contained in:
@@ -44,6 +44,8 @@ public class SummarizeDocSolver extends StepSolver {
|
||||
private int percent_summarize;
|
||||
private Integer maxTokenChunk;
|
||||
private String qai_custom_memory_id;
|
||||
private Integer max_output_token;
|
||||
private String qai_system_prompt_template_minimum;
|
||||
// private boolean qai_load_graph_schema=false;
|
||||
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(SummarizeDocSolver.class);
|
||||
@@ -67,6 +69,12 @@ public class SummarizeDocSolver extends StepSolver {
|
||||
this.percent_summarize = Integer.parseInt((String) this.step.getAttributes().get("percent_summarize"));
|
||||
|
||||
this.qai_custom_memory_id = (String) this.step.getAttributes().get("qai_custom_memory_id");
|
||||
|
||||
this.max_output_token = Integer.parseInt((String) this.step.getAttributes().get("max_output_token"));
|
||||
|
||||
this.qai_system_prompt_template_minimum = attributeParser
|
||||
.parse((String) this.step.getAttributes().get("qai_system_prompt_template_minimum"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,21 +102,29 @@ public class SummarizeDocSolver extends StepSolver {
|
||||
int charCount = text.length();
|
||||
|
||||
// Stima media caratteri per token
|
||||
double charPerToken = (double) charCount / tokenCount;
|
||||
// double charPerToken = (double) charCount / tokenCount;
|
||||
|
||||
//Double output_char = (double) charCount * ((double) this.percent_summarize / 100.0);
|
||||
Double min_output_token = (double) tokenCount * ((double) this.percent_summarize / 100.0);
|
||||
String content = new String("");
|
||||
content = this.qai_system_prompt_template.replace("max_number_token",
|
||||
max_output_token.toString());
|
||||
|
||||
if (min_output_token < max_output_token) {
|
||||
content += this.qai_system_prompt_template_minimum.replace(
|
||||
"min_number_token",
|
||||
min_output_token.toString());
|
||||
}
|
||||
|
||||
Double output_char = (double) charCount * ((double) this.percent_summarize / 100.0);
|
||||
Integer output_char_int = output_char.intValue();
|
||||
this.qai_system_prompt_template = this.qai_system_prompt_template.replace("number_char",
|
||||
output_char_int.toString());
|
||||
// **Fase di Summarization**
|
||||
String summarizedText = summarize(text); // 🔹 Applica la funzione di riassunto
|
||||
// String template = this.qai_system_prompt_template+" The output length should
|
||||
// be of " + output_char + " characters";
|
||||
logger.info("template: " + this.qai_system_prompt_template);
|
||||
logger.info("template: " + content);
|
||||
// Creazione dei messaggi per il modello AI
|
||||
Message userMessage = new UserMessage(summarizedText);
|
||||
Message systemMessage = new SystemMessage(this.qai_system_prompt_template);
|
||||
|
||||
Message systemMessage = new SystemMessage(content);
|
||||
logger.info("template: " + systemMessage.getContent().toString());
|
||||
CallResponseSpec resp = chatClient.prompt()
|
||||
.messages(userMessage, systemMessage)
|
||||
.advisors(advisor -> advisor
|
||||
@@ -192,26 +208,34 @@ public class SummarizeDocSolver extends StepSolver {
|
||||
|
||||
// Metodo di riassunto per singolo chunk
|
||||
private String summarizeChunk(String chunk) {
|
||||
try {
|
||||
this.qai_system_prompt_template_chunk = this.qai_system_prompt_template_chunk.replace("number_char",
|
||||
maxTokenChunk.toString());
|
||||
String content = new String("");
|
||||
|
||||
Message chunkMessage = new UserMessage(chunk);
|
||||
Message systemMessage = new SystemMessage(qai_system_prompt_template_chunk);
|
||||
|
||||
CallResponseSpec resp = chatClient.prompt()
|
||||
.messages(chunkMessage, systemMessage)
|
||||
/* .advisors(advisor -> advisor
|
||||
.param("chat_memory_conversation_id",
|
||||
this.scenarioExecution.getId() + this.qai_custom_memory_id)
|
||||
.param("chat_memory_response_size", 100))*/
|
||||
.call();
|
||||
|
||||
return resp.content();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return chunk.substring(0, Math.max(1, chunk.length() / 10)); // Fallback
|
||||
if (maxTokenChunk < max_output_token) {
|
||||
content = this.qai_system_prompt_template_chunk.replace("max_number_token",
|
||||
maxTokenChunk.toString());
|
||||
}else{
|
||||
content = this.qai_system_prompt_template_chunk.replace("max_number_token",
|
||||
max_output_token.toString());
|
||||
}
|
||||
|
||||
Message chunkMessage = new UserMessage(chunk);
|
||||
Message systemMessage = new SystemMessage(
|
||||
content);
|
||||
|
||||
logger.info("template chunk: " + content);
|
||||
|
||||
CallResponseSpec resp = chatClient.prompt()
|
||||
.messages(chunkMessage, systemMessage)
|
||||
/*
|
||||
* .advisors(advisor -> advisor
|
||||
* .param("chat_memory_conversation_id",
|
||||
* this.scenarioExecution.getId() + this.qai_custom_memory_id)
|
||||
* .param("chat_memory_response_size", 100))
|
||||
*/
|
||||
.call();
|
||||
|
||||
return resp.content();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user