Merge branch 'master' of https://dev.azure.com/olympusai/Olympus/_git/hermione
This commit is contained in:
@@ -24,15 +24,4 @@ public class ExecutionController {
|
|||||||
return scenarioExecutionRepository.findById(id).get();
|
return scenarioExecutionRepository.findById(id).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @PostMapping("/updateRating")
|
|
||||||
// public String updateScenarioExecRating(@RequestBody ScenarioExecution scenarioExecution){
|
|
||||||
// String result = scenarioExecutionService.updateRating2(scenarioExecution);
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@GetMapping("/updateRating")
|
|
||||||
public String updateScenarioExecRating(@RequestParam String id, @RequestParam String rating){
|
|
||||||
String result = scenarioExecutionService.updateRating(id, rating);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
package com.olympus.hermione.controllers;
|
package com.olympus.hermione.controllers;
|
||||||
|
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.olympus.hermione.dto.ScenarioExecutionInput;
|
import com.olympus.hermione.dto.ScenarioExecutionInput;
|
||||||
import com.olympus.hermione.dto.ScenarioOutput;
|
import com.olympus.hermione.dto.ScenarioOutput;
|
||||||
import com.olympus.hermione.models.Scenario;
|
import com.olympus.hermione.models.Scenario;
|
||||||
@@ -20,6 +29,7 @@ import com.olympus.model.Application;
|
|||||||
import com.olympus.model.Project;
|
import com.olympus.model.Project;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class ScenarioController {
|
public class ScenarioController {
|
||||||
@@ -33,6 +43,7 @@ public class ScenarioController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ScenarioService scenarioService;
|
ScenarioService scenarioService;
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/scenarios")
|
@GetMapping("/scenarios")
|
||||||
public Iterable<Scenario> getScenarios() {
|
public Iterable<Scenario> getScenarios() {
|
||||||
return scenarioRepository.findAll();
|
return scenarioRepository.findAll();
|
||||||
@@ -90,15 +101,33 @@ public class ScenarioController {
|
|||||||
return scenarioExecutionService.getExecutionProgress(id);
|
return scenarioExecutionService.getExecutionProgress(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/scenarios/execute/{id}")
|
@GetMapping("/scenarios/execute/{id}")
|
||||||
public ScenarioExecution getScenarioExecution(@PathVariable String id) {
|
public ScenarioExecution getScenarioExecution(@PathVariable String id) {
|
||||||
return scenarioExecutionRepository.findById(id).get();
|
ScenarioExecution scenarioExecution = scenarioExecutionRepository.findById(id).get();
|
||||||
|
String apiKey = scenarioExecution.getScenario().getAiModel().getApiKey();
|
||||||
|
String endpoint = scenarioExecution.getScenario().getAiModel().getEndpoint();
|
||||||
|
List<Project> availableForProject = scenarioExecution.getScenario().getAvailableForProjects();
|
||||||
|
List<Project> availableForApplication = scenarioExecution.getScenario().getAvailableForApplications();
|
||||||
|
if (apiKey != null) {
|
||||||
|
scenarioExecution.getScenario().getAiModel().setApiKey("**********");
|
||||||
}
|
}
|
||||||
|
if (endpoint != null) {
|
||||||
|
scenarioExecution.getScenario().getAiModel().setEndpoint("**********");
|
||||||
|
}
|
||||||
|
if (availableForProject != null) {
|
||||||
|
scenarioExecution.getScenario().setAvailableForProjects(null);
|
||||||
|
}
|
||||||
|
if (availableForApplication != null) {
|
||||||
|
scenarioExecution.getScenario().setAvailableForApplications(null);
|
||||||
|
}
|
||||||
|
return scenarioExecution;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/scenariosByUser")
|
@PostMapping("/executions")
|
||||||
public List<ScenarioExecution> getScenarioByUser() {
|
public Page<ScenarioExecution> getAdvancedExecutions(
|
||||||
return scenarioExecutionService.getListExecutionScenarioByUser();
|
@RequestBody Map<String, Object> allParams) {
|
||||||
|
|
||||||
|
return scenarioExecutionService.getFilteredExecutions(allParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getScenariosForRE")
|
@GetMapping("/getScenariosForRE")
|
||||||
@@ -106,6 +135,10 @@ public class ScenarioController {
|
|||||||
return scenarioService.getListScenariosForRE();
|
return scenarioService.getListScenariosForRE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/updateRating")
|
||||||
|
public String updateScenarioExecRating(@RequestParam String id, @RequestParam String rating){
|
||||||
|
String result = scenarioService.updateRating(id, rating);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,6 @@ public class AiModel {
|
|||||||
private Integer maxTokens;
|
private Integer maxTokens;
|
||||||
private String apiKey;
|
private String apiKey;
|
||||||
private boolean isDefault = false;
|
private boolean isDefault = false;
|
||||||
|
private boolean isCanvasDefault = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class Scenario {
|
|||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
|
private String hint;
|
||||||
private String startWithStepId;
|
private String startWithStepId;
|
||||||
private List<ScenarioStep> steps;
|
private List<ScenarioStep> steps;
|
||||||
private List<ScenarioInputs> inputs;
|
private List<ScenarioInputs> inputs;
|
||||||
@@ -36,6 +37,7 @@ public class Scenario {
|
|||||||
|
|
||||||
private boolean useChatMemory=false;
|
private boolean useChatMemory=false;
|
||||||
private String outputType;
|
private String outputType;
|
||||||
|
private boolean canvasEnabled=false;
|
||||||
|
private boolean chatEnabled=false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.olympus.hermione.repository;
|
package com.olympus.hermione.repository;
|
||||||
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
import com.olympus.hermione.models.AiModel;
|
import com.olympus.hermione.models.AiModel;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface AiModelRepository extends MongoRepository<AiModel, String>{
|
public interface AiModelRepository extends MongoRepository<AiModel, String>{
|
||||||
AiModel findByIsDefault(Boolean isDefault);
|
AiModel findByIsDefault(Boolean isDefault);
|
||||||
|
AiModel findByIsCanvasDefault(Boolean isCanvasDefault);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.olympus.hermione.repository;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
import org.springframework.data.mongodb.repository.Query;
|
import org.springframework.data.mongodb.repository.Query;
|
||||||
@@ -21,13 +23,30 @@ public interface ScenarioExecutionRepository extends MongoRepository<ScenarioExe
|
|||||||
@Query("{ $and: [ { 'executedByUserId': ?0 }, { 'scenarioExecutionInput.inputs.selected_project': ?1 }, { 'scenarioExecutionInput.inputs.selected_application': ?2 } ] }")
|
@Query("{ $and: [ { 'executedByUserId': ?0 }, { 'scenarioExecutionInput.inputs.selected_project': ?1 }, { 'scenarioExecutionInput.inputs.selected_application': ?2 } ] }")
|
||||||
List<ScenarioExecution> findByExecutedByUserIdAndInputs(String userId, String selectedProject, String selectedApplication);
|
List<ScenarioExecution> findByExecutedByUserIdAndInputs(String userId, String selectedProject, String selectedApplication);
|
||||||
|
|
||||||
@Query("{ $and: [ { 'executedByUserId': ?0 }, { 'scenarioExecutionInput.inputs.selected_project': ?1 }, { 'scenarioExecutionInput.inputs.selected_application': ?2 } ] }")
|
// @Query("{ $and: [ { 'executedByUserId': ?0 }, { 'scenarioExecutionInput.inputs.selected_project': ?1 }, { 'scenarioExecutionInput.inputs.selected_application': ?2 } ] }")
|
||||||
List<ScenarioExecution> getFromProjectAndAPP(String userId, String value1, String value2, Sort sort);
|
// List<ScenarioExecution> getFromProjectAndAPP(String userId, String value1, String value2, Sort sort);
|
||||||
//findByExecutedByUserIdAndInputsOrderByStartDateDesc
|
// //findByExecutedByUserIdAndInputsOrderByStartDateDesc
|
||||||
|
|
||||||
@Query("{ $and: [ { 'executedByUserId': ?0 }, { 'scenarioExecutionInput.inputs.selected_project': ?1 } ] }")
|
@Query("{ $and: [ { 'scenarioExecutionInput.inputs.selected_project': ?0 }, { 'scenarioExecutionInput.inputs.selected_application': ?1 } ] }")
|
||||||
List<ScenarioExecution> getFromProject(String userId, String value1, Sort sort);
|
Page<ScenarioExecution> getFromProjectAndAPP( String value1, String value2, Pageable pageable);
|
||||||
|
|
||||||
|
@Query("{ $and: [ "
|
||||||
|
+ " { 'scenarioExecutionInput.inputs.selected_project': ?0 }, "
|
||||||
|
+ " { 'scenarioExecutionInput.inputs.selected_application': ?1 }, "
|
||||||
|
+ " { $or: [ { 'scenarioExecutionInput.inputs.optional_field': ?2 }, { 'scenarioExecutionInput.inputs.optional_field': { $exists: false } } ] } "
|
||||||
|
+ "] }")
|
||||||
|
Page<ScenarioExecution> getFromProjectAndAPPOptional(
|
||||||
|
String value1,
|
||||||
|
String value2,
|
||||||
|
String optionalValue,
|
||||||
|
Pageable pageable);
|
||||||
|
|
||||||
|
|
||||||
|
// @Query("{ $and: [ { 'executedByUserId': ?0 }, { 'scenarioExecutionInput.inputs.selected_project': ?1 } ] }")
|
||||||
|
// List<ScenarioExecution> getFromProject(String userId, String value1, Sort sort);
|
||||||
|
|
||||||
|
@Query("{ $and: [ { 'scenarioExecutionInput.inputs.selected_project': ?0 } ] }")
|
||||||
|
Page<ScenarioExecution> getFromProject( String value1, Pageable pageable);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,20 +19,30 @@ public interface ScenarioRepository extends MongoRepository<Scenario, String> {
|
|||||||
List<Scenario> findByUsableFor(String projectId);*/
|
List<Scenario> findByUsableFor(String projectId);*/
|
||||||
|
|
||||||
//List<Scenario> findByAvailableForProjects_Id(String projectId);
|
//List<Scenario> findByAvailableForProjects_Id(String projectId);
|
||||||
List<Scenario> findByAvailableForProjects_IdAndVisible(String projectId, String visible);
|
//List<Scenario> findByAvailableForProjects_IdAndVisible(String projectId, String visible);
|
||||||
|
List<Scenario> findByAvailableForProjects_IdAndVisibleIn(String projectId, List<String> visible);
|
||||||
|
|
||||||
|
List<Scenario> findByAvailableForApplications_IdAndVisibleIn(String projectId, List<String> visible);
|
||||||
|
|
||||||
|
List<Scenario> findByAvailableForProjectsIsNullAndAvailableForApplicationsIsNullAndVisibleIn(List<String> visible);
|
||||||
|
|
||||||
|
|
||||||
List<Scenario> findByAvailableForApplications_IdAndVisible(String projectId, String visible);
|
/* @Query("{ 'visible': 'Y', 'category': 'RE', " +
|
||||||
|
|
||||||
List<Scenario> findByAvailableForProjectsIsNullAndAvailableForApplicationsIsNullAndVisible(String visible);
|
|
||||||
|
|
||||||
|
|
||||||
@Query("{ 'visible': 'Y', 'category': 'RE', " +
|
|
||||||
" $or: [ " +
|
" $or: [ " +
|
||||||
" { 'availableForProjects': ObjectId(?0) }, " +
|
" { 'availableForProjects': ObjectId(?0) }, " +
|
||||||
" { 'availableForApplications': ObjectId(?1) } " +
|
" { 'availableForApplications': ObjectId(?1) } " +
|
||||||
" ] " +
|
" ] " +
|
||||||
"}")
|
"}")
|
||||||
List<Scenario> findByVisibleAndCategoryAndProjectOrApplication(String projectId, String applicationId);
|
List<Scenario> findByVisibleAndCategoryAndProjectOrApplication(String projectId, String applicationId);
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Query("{ 'visible': { $in: ?2 }, 'category': 'RE', " +
|
||||||
|
" $or: [ " +
|
||||||
|
" { 'availableForProjects': ObjectId(?0) }, " +
|
||||||
|
" { 'availableForApplications': ObjectId(?1) } " +
|
||||||
|
" ] " +
|
||||||
|
"}")
|
||||||
|
List<Scenario> findByVisibleInAndCategoryAndProjectOrApplication(String projectId, String applicationId, List<String> visibleValues);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,91 +1,115 @@
|
|||||||
package com.olympus.hermione.services;
|
package com.olympus.hermione.services;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.ai.chat.messages.Message;
|
|
||||||
import org.springframework.ai.chat.messages.SystemMessage;
|
|
||||||
import org.springframework.ai.chat.messages.UserMessage;
|
|
||||||
import org.springframework.ai.chat.model.ChatModel;
|
|
||||||
import org.springframework.ai.chat.model.Generation;
|
|
||||||
import org.springframework.ai.chat.prompt.Prompt;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.olympus.hermione.client.OlympusChatClient;
|
||||||
|
import com.olympus.hermione.client.AzureOpenApiChatClient;
|
||||||
|
import com.olympus.hermione.client.GoogleGeminiChatClient;
|
||||||
|
import com.olympus.hermione.client.OlympusChatClientResponse;
|
||||||
import com.olympus.hermione.dto.CanvasExecutionInput;
|
import com.olympus.hermione.dto.CanvasExecutionInput;
|
||||||
import com.olympus.hermione.dto.CanvasOutput;
|
import com.olympus.hermione.dto.CanvasOutput;
|
||||||
|
import com.olympus.hermione.models.AiModel;
|
||||||
|
import com.olympus.hermione.repository.AiModelRepository;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CanvasExecutionService {
|
public class CanvasExecutionService {
|
||||||
|
|
||||||
|
|
||||||
private final ChatModel chatModel;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public CanvasExecutionService(@Qualifier("openAiChatModel") ChatModel chatModel) {
|
private AiModelRepository aiModelRepository;
|
||||||
this.chatModel = chatModel;
|
|
||||||
}
|
private OlympusChatClient olympusChatClient = null;
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(CanvasExecutionService.class);
|
private Logger logger = LoggerFactory.getLogger(CanvasExecutionService.class);
|
||||||
|
|
||||||
|
public OlympusChatClient createCanvasClient(AiModelRepository aiModelRepository){
|
||||||
|
AiModel aiModel = aiModelRepository.findByIsCanvasDefault(true);
|
||||||
|
if (aiModel == null) {
|
||||||
|
logger.error("No default AI model found");
|
||||||
|
throw new IllegalArgumentException("No default AI model found");
|
||||||
|
}
|
||||||
|
if (aiModel.getApiProvider().equals("AzureOpenAI")) {
|
||||||
|
olympusChatClient = new AzureOpenApiChatClient();
|
||||||
|
}
|
||||||
|
if (aiModel.getApiProvider().equals("GoogleGemini")) {
|
||||||
|
olympusChatClient = new GoogleGeminiChatClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
olympusChatClient.init(aiModel.getEndpoint(), aiModel.getApiKey(), aiModel.getMaxTokens());
|
||||||
|
|
||||||
|
return olympusChatClient;
|
||||||
|
}
|
||||||
|
|
||||||
public CanvasOutput askHermione(CanvasExecutionInput canvasExecutionInput){
|
public CanvasOutput askHermione(CanvasExecutionInput canvasExecutionInput){
|
||||||
|
try{
|
||||||
CanvasOutput canvasOutput = new CanvasOutput();
|
CanvasOutput canvasOutput = new CanvasOutput();
|
||||||
String input = canvasExecutionInput.getInput();
|
String input = canvasExecutionInput.getInput();
|
||||||
if(input != null){
|
if(input != null){
|
||||||
Message userMessage = new UserMessage(input);
|
olympusChatClient = createCanvasClient(aiModelRepository);
|
||||||
Message systemMessage = new SystemMessage("Please answer the question accurately.");
|
String userText = input;
|
||||||
Prompt prompt = new Prompt(List.of(userMessage,systemMessage));
|
String systemText = "Answer the following question: ";
|
||||||
List<Generation> response = chatModel.call(prompt).getResults();
|
OlympusChatClientResponse resp = olympusChatClient.getChatCompletion(systemText +"\n"+ userText);
|
||||||
|
|
||||||
canvasOutput.setStringOutput(response.get(0).getOutput().getText());
|
canvasOutput.setStringOutput(resp.getContent());
|
||||||
return canvasOutput;
|
return canvasOutput;
|
||||||
} else{
|
} else{
|
||||||
logger.error("Input is not correct");
|
logger.error("Input is not correct");
|
||||||
canvasOutput.setStringOutput(null);
|
canvasOutput.setStringOutput(null);
|
||||||
}
|
}
|
||||||
return canvasOutput;
|
return canvasOutput;
|
||||||
|
} catch (Exception e){
|
||||||
|
logger.error("Error in askHermione: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CanvasOutput rephraseText(CanvasExecutionInput canvasExecutionInput) {
|
public CanvasOutput rephraseText(CanvasExecutionInput canvasExecutionInput) {
|
||||||
|
try{
|
||||||
CanvasOutput canvasOutput = new CanvasOutput();
|
CanvasOutput canvasOutput = new CanvasOutput();
|
||||||
String input = canvasExecutionInput.getInput();
|
String input = canvasExecutionInput.getInput();
|
||||||
if(input != null){
|
if(input != null){
|
||||||
Message userMessage = new UserMessage(input);
|
olympusChatClient = createCanvasClient(aiModelRepository);
|
||||||
Message systemMessage = new SystemMessage("Please rephrase the following text: ");
|
String userText = input;
|
||||||
Prompt prompt = new Prompt(List.of(userMessage,systemMessage));
|
String systemText = "Rephrase the following text: ";
|
||||||
List<Generation> response = chatModel.call(prompt).getResults();
|
OlympusChatClientResponse resp = olympusChatClient.getChatCompletion(systemText+"\n"+userText);
|
||||||
|
|
||||||
canvasOutput.setStringOutput(response.get(0).getOutput().getText());
|
canvasOutput.setStringOutput(resp.getContent());
|
||||||
return canvasOutput;
|
return canvasOutput;
|
||||||
} else{
|
} else{
|
||||||
logger.error("Input is not correct");
|
logger.error("Input is not correct");
|
||||||
canvasOutput.setStringOutput(null);
|
canvasOutput.setStringOutput(null);
|
||||||
}
|
}
|
||||||
return canvasOutput;
|
return canvasOutput;
|
||||||
|
} catch (Exception e){
|
||||||
|
logger.error("Error in rephraseText: " + e.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public CanvasOutput summarizeText(CanvasExecutionInput canvasExecutionInput) {
|
public CanvasOutput summarizeText(CanvasExecutionInput canvasExecutionInput) {
|
||||||
|
try{
|
||||||
CanvasOutput canvasOutput = new CanvasOutput();
|
CanvasOutput canvasOutput = new CanvasOutput();
|
||||||
String input = canvasExecutionInput.getInput();
|
String input = canvasExecutionInput.getInput();
|
||||||
if(input != null){
|
if(input != null){
|
||||||
Message userMessage = new UserMessage(input);
|
olympusChatClient = createCanvasClient(aiModelRepository);
|
||||||
Message systemMessage = new SystemMessage("Please summarize the following text: ");
|
String userText = input;
|
||||||
Prompt prompt = new Prompt(List.of(userMessage,systemMessage));
|
String systemText = "Summarize the following text: ";
|
||||||
List<Generation> response = chatModel.call(prompt).getResults();
|
OlympusChatClientResponse resp = olympusChatClient.getChatCompletion(systemText+"\n"+userText);
|
||||||
|
|
||||||
canvasOutput.setStringOutput(response.get(0).getOutput().getText());
|
canvasOutput.setStringOutput(resp.getContent());
|
||||||
return canvasOutput;
|
return canvasOutput;
|
||||||
} else{
|
} else{
|
||||||
logger.error("Input is not correct");
|
logger.error("Input is not correct");
|
||||||
canvasOutput.setStringOutput(null);
|
canvasOutput.setStringOutput(null);
|
||||||
}
|
}
|
||||||
return canvasOutput;
|
return canvasOutput;
|
||||||
|
} catch (Exception e){
|
||||||
|
logger.error("Error in summarizeText: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,18 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.ai.azure.openai.AzureOpenAiChatModel;
|
import org.springframework.ai.azure.openai.AzureOpenAiChatModel;
|
||||||
@@ -29,7 +33,14 @@ import org.springframework.ai.vectorstore.VectorStore;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -55,6 +66,7 @@ import com.olympus.hermione.stepSolvers.QueryNeo4JSolver;
|
|||||||
import com.olympus.hermione.stepSolvers.SourceCodeRagSolver;
|
import com.olympus.hermione.stepSolvers.SourceCodeRagSolver;
|
||||||
import com.olympus.hermione.stepSolvers.StepSolver;
|
import com.olympus.hermione.stepSolvers.StepSolver;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.neo4j.driver.Driver;
|
import org.neo4j.driver.Driver;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@@ -65,15 +77,15 @@ import com.olympus.hermione.stepSolvers.ExternalAgentSolver;
|
|||||||
import com.olympus.hermione.stepSolvers.ExternalCodeGenieSolver;
|
import com.olympus.hermione.stepSolvers.ExternalCodeGenieSolver;
|
||||||
import com.olympus.hermione.stepSolvers.OlynmpusChatClientSolver;
|
import com.olympus.hermione.stepSolvers.OlynmpusChatClientSolver;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ScenarioExecutionService {
|
public class ScenarioExecutionService {
|
||||||
|
|
||||||
@Value("${file.upload-dir}")
|
@Value("${file.upload-dir}")
|
||||||
private String uploadDir;
|
private String uploadDir;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ScenarioRepository scenarioRepository;
|
private ScenarioRepository scenarioRepository;
|
||||||
|
|
||||||
@@ -89,7 +101,6 @@ public class ScenarioExecutionService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
DiscoveryClient discoveryClient;
|
DiscoveryClient discoveryClient;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
Driver graphDriver;
|
Driver graphDriver;
|
||||||
|
|
||||||
@@ -101,44 +112,49 @@ public class ScenarioExecutionService {
|
|||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(ScenarioExecutionService.class);
|
private Logger logger = LoggerFactory.getLogger(ScenarioExecutionService.class);
|
||||||
|
|
||||||
public ScenarioOutput getExecutionProgress(String scenarioExecutionId){
|
public ScenarioOutput getExecutionProgress(String scenarioExecutionId) {
|
||||||
ScenarioOutput scenarioOutput = new ScenarioOutput();
|
ScenarioOutput scenarioOutput = new ScenarioOutput();
|
||||||
Optional<ScenarioExecution> o_scenarioExecution = scenarioExecutionRepository.findById(scenarioExecutionId);
|
Optional<ScenarioExecution> o_scenarioExecution = scenarioExecutionRepository.findById(scenarioExecutionId);
|
||||||
|
|
||||||
if(o_scenarioExecution.isPresent()){
|
if (o_scenarioExecution.isPresent()) {
|
||||||
ScenarioExecution scenarioExecution = o_scenarioExecution.get();
|
ScenarioExecution scenarioExecution = o_scenarioExecution.get();
|
||||||
scenarioExecution.setCurrentStepId(scenarioExecution.getCurrentStepId());
|
scenarioExecution.setCurrentStepId(scenarioExecution.getCurrentStepId());
|
||||||
|
|
||||||
if(scenarioExecution.getExecSharedMap()!=null && scenarioExecution.getExecSharedMap().get("scenario_output")!=null){
|
if (scenarioExecution.getExecSharedMap() != null
|
||||||
|
&& scenarioExecution.getExecSharedMap().get("scenario_output") != null) {
|
||||||
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
||||||
scenarioOutput.setStatus("OK");
|
scenarioOutput.setStatus("OK");
|
||||||
scenarioOutput.setStringOutput(scenarioExecution.getExecSharedMap().get("scenario_output").toString());
|
scenarioOutput.setStringOutput(scenarioExecution.getExecSharedMap().get("scenario_output").toString());
|
||||||
scenarioOutput.setMessage("");
|
scenarioOutput.setMessage("");
|
||||||
}else{
|
} else {
|
||||||
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
||||||
scenarioOutput.setStatus("IN_PROGRESS");
|
scenarioOutput.setStatus("IN_PROGRESS");
|
||||||
|
|
||||||
if (scenarioExecution.getCurrentStepId() != null){
|
if (scenarioExecution.getCurrentStepId() != null) {
|
||||||
OptionalInt indexOpt = IntStream.range(0, scenarioExecution.getScenario().getSteps().size())
|
OptionalInt indexOpt = IntStream.range(0, scenarioExecution.getScenario().getSteps().size())
|
||||||
.filter(i -> scenarioExecution.getScenario().getSteps().get(i).getStepId().equals(scenarioExecution.getCurrentStepId()))
|
.filter(i -> scenarioExecution.getScenario().getSteps().get(i).getStepId()
|
||||||
|
.equals(scenarioExecution.getCurrentStepId()))
|
||||||
.map(i -> i + 1)
|
.map(i -> i + 1)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
scenarioOutput.setCurrentStepId(scenarioExecution.getCurrentStepId());
|
scenarioOutput.setCurrentStepId(scenarioExecution.getCurrentStepId());
|
||||||
scenarioOutput.setCurrentStepDescription(scenarioExecution.getCurrentStepDescription());
|
scenarioOutput.setCurrentStepDescription(scenarioExecution.getCurrentStepDescription());
|
||||||
scenarioOutput.setMessage("Executing step "+indexOpt.getAsInt()+"/"+scenarioExecution.getScenario().getSteps().size()+": "+scenarioOutput.getCurrentStepDescription()+".");
|
scenarioOutput.setMessage("Executing step " + indexOpt.getAsInt() + "/"
|
||||||
}else {
|
+ scenarioExecution.getScenario().getSteps().size() + ": "
|
||||||
|
+ scenarioOutput.getCurrentStepDescription() + ".");
|
||||||
|
} else {
|
||||||
scenarioOutput.setMessage("Starting execution...");
|
scenarioOutput.setMessage("Starting execution...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scenarioExecution.getLatestStepStatus()!= null && scenarioExecution.getLatestStepStatus().equals("ERROR")){
|
if (scenarioExecution.getLatestStepStatus() != null
|
||||||
|
&& scenarioExecution.getLatestStepStatus().equals("ERROR")) {
|
||||||
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
||||||
scenarioOutput.setStatus("ERROR");
|
scenarioOutput.setStatus("ERROR");
|
||||||
scenarioOutput.setMessage(scenarioExecution.getLatestStepOutput());
|
scenarioOutput.setMessage(scenarioExecution.getLatestStepOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
scenarioOutput.setScenarioExecution_id(null);
|
scenarioOutput.setScenarioExecution_id(null);
|
||||||
scenarioOutput.setStatus("ERROR");
|
scenarioOutput.setStatus("ERROR");
|
||||||
scenarioOutput.setMessage("Scenario Execution not found");
|
scenarioOutput.setMessage("Scenario Execution not found");
|
||||||
@@ -148,15 +164,15 @@ public class ScenarioExecutionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public void executeScenarioAsync(ScenarioOutput scenarioOutput){
|
public void executeScenarioAsync(ScenarioOutput scenarioOutput) {
|
||||||
|
|
||||||
String scenarioExecutionID = scenarioOutput.getScenarioExecution_id();
|
String scenarioExecutionID = scenarioOutput.getScenarioExecution_id();
|
||||||
|
|
||||||
Optional<ScenarioExecution> o_scenarioExecution = scenarioExecutionRepository.findById(scenarioExecutionID);
|
Optional<ScenarioExecution> o_scenarioExecution = scenarioExecutionRepository.findById(scenarioExecutionID);
|
||||||
|
|
||||||
if(o_scenarioExecution.isPresent()){
|
if (o_scenarioExecution.isPresent()) {
|
||||||
ScenarioExecution scenarioExecution = o_scenarioExecution.get();
|
ScenarioExecution scenarioExecution = o_scenarioExecution.get();
|
||||||
HashMap<String,String> inputs = scenarioExecution.getScenarioExecutionInput().getInputs();
|
HashMap<String, String> inputs = scenarioExecution.getScenarioExecutionInput().getInputs();
|
||||||
Optional<Scenario> o_scenario = scenarioRepository.findById(scenarioExecution.getScenario().getId());
|
Optional<Scenario> o_scenario = scenarioRepository.findById(scenarioExecution.getScenario().getId());
|
||||||
|
|
||||||
Scenario scenario = o_scenario.get();
|
Scenario scenario = o_scenario.get();
|
||||||
@@ -169,9 +185,9 @@ public class ScenarioExecutionService {
|
|||||||
scenarioExecution.setExecSharedMap(execSharedMap);
|
scenarioExecution.setExecSharedMap(execSharedMap);
|
||||||
|
|
||||||
AiModel aiModel;
|
AiModel aiModel;
|
||||||
if(scenario.getAiModel() != null){
|
if (scenario.getAiModel() != null) {
|
||||||
aiModel = scenario.getAiModel();
|
aiModel = scenario.getAiModel();
|
||||||
}else {
|
} else {
|
||||||
aiModel = aiModelRepository.findByIsDefault(true);
|
aiModel = aiModelRepository.findByIsDefault(true);
|
||||||
scenario.setAiModel(aiModel);
|
scenario.setAiModel(aiModel);
|
||||||
scenarioExecution.setScenario(scenario);
|
scenarioExecution.setScenario(scenario);
|
||||||
@@ -181,48 +197,47 @@ public class ScenarioExecutionService {
|
|||||||
|
|
||||||
scenarioExecutionRepository.save(scenarioExecution);
|
scenarioExecutionRepository.save(scenarioExecution);
|
||||||
|
|
||||||
|
if (scenario.isUseChatMemory()) {
|
||||||
if(scenario.isUseChatMemory()){
|
|
||||||
logger.info("Initializing chatClient with chat-memory advisor");
|
logger.info("Initializing chatClient with chat-memory advisor");
|
||||||
|
|
||||||
ChatMemory chatMemory = new InMemoryChatMemory();
|
ChatMemory chatMemory = new InMemoryChatMemory();
|
||||||
chatClient = ChatClient.builder(chatModel)
|
chatClient = ChatClient.builder(chatModel)
|
||||||
.defaultAdvisors(
|
.defaultAdvisors(
|
||||||
new MessageChatMemoryAdvisor(chatMemory), // chat-memory advisor
|
new MessageChatMemoryAdvisor(chatMemory), // chat-memory advisor
|
||||||
new SimpleLoggerAdvisor()
|
new SimpleLoggerAdvisor())
|
||||||
)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
logger.info("Initializing chatClient with simple logger advisor");
|
logger.info("Initializing chatClient with simple logger advisor");
|
||||||
|
|
||||||
chatClient = ChatClient.builder(chatModel)
|
chatClient = ChatClient.builder(chatModel)
|
||||||
.defaultAdvisors(
|
.defaultAdvisors(
|
||||||
new SimpleLoggerAdvisor()
|
new SimpleLoggerAdvisor())
|
||||||
)
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<ScenarioStep> steps = scenario.getSteps();
|
List<ScenarioStep> steps = scenario.getSteps();
|
||||||
String startStepId=scenario.getStartWithStepId();
|
String startStepId = scenario.getStartWithStepId();
|
||||||
|
|
||||||
ScenarioStep startStep = steps.stream().filter(step -> step.getStepId().equals(startStepId)).findFirst().orElse(null);
|
ScenarioStep startStep = steps.stream().filter(step -> step.getStepId().equals(startStepId)).findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
executeScenarioStep(startStep, scenarioExecution);
|
executeScenarioStep(startStep, scenarioExecution);
|
||||||
Integer usedTokens = (scenarioExecution.getUsedTokens() != null) ? scenarioExecution.getUsedTokens() : 0;
|
Integer usedTokens = (scenarioExecution.getUsedTokens() != null) ? scenarioExecution.getUsedTokens() : 0;
|
||||||
|
|
||||||
while (scenarioExecution.getNextStepId()!=null) {
|
while (scenarioExecution.getNextStepId() != null) {
|
||||||
ScenarioStep step = steps.stream().filter(s -> s.getStepId().equals(scenarioExecution.getNextStepId())).findFirst().orElse(null);
|
ScenarioStep step = steps.stream().filter(s -> s.getStepId().equals(scenarioExecution.getNextStepId()))
|
||||||
|
.findFirst().orElse(null);
|
||||||
executeScenarioStep(step, scenarioExecution);
|
executeScenarioStep(step, scenarioExecution);
|
||||||
|
|
||||||
if (scenarioExecution.getUsedTokens() != null && scenarioExecution.getUsedTokens() != 0) {
|
if (scenarioExecution.getUsedTokens() != null && scenarioExecution.getUsedTokens() != 0) {
|
||||||
usedTokens += scenarioExecution.getUsedTokens();
|
usedTokens += scenarioExecution.getUsedTokens();
|
||||||
|
|
||||||
scenarioExecution.setUsedTokens(0); //resetting value for next step if is not an AI step
|
scenarioExecution.setUsedTokens(0); // resetting value for next step if is not an AI step
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scenarioExecution.getLatestStepStatus() != null && scenarioExecution.getLatestStepStatus().equals("ERROR")){
|
if (scenarioExecution.getLatestStepStatus() != null
|
||||||
|
&& scenarioExecution.getLatestStepStatus().equals("ERROR")) {
|
||||||
logger.error("Error while executing step: " + step.getStepId());
|
logger.error("Error while executing step: " + step.getStepId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -234,13 +249,9 @@ public class ScenarioExecutionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void executeScenarioStep(ScenarioStep step, ScenarioExecution scenarioExecution) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void executeScenarioStep(ScenarioStep step, ScenarioExecution scenarioExecution){
|
|
||||||
logger.info("Start working on step: " + step.getName() + " with type: " + step.getType());
|
logger.info("Start working on step: " + step.getName() + " with type: " + step.getType());
|
||||||
StepSolver solver=new StepSolver();
|
StepSolver solver = new StepSolver();
|
||||||
switch (step.getType()) {
|
switch (step.getType()) {
|
||||||
case "ADVANCED_QUERY_AI":
|
case "ADVANCED_QUERY_AI":
|
||||||
solver = new AdvancedAIPromptSolver();
|
solver = new AdvancedAIPromptSolver();
|
||||||
@@ -282,44 +293,40 @@ public class ScenarioExecutionService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logger.info("Initializing step: " + step.getStepId());
|
logger.info("Initializing step: " + step.getStepId());
|
||||||
logger.info("Solving step: " + step.getStepId());
|
logger.info("Solving step: " + step.getStepId());
|
||||||
scenarioExecution.setCurrentStepId(step.getStepId());
|
scenarioExecution.setCurrentStepId(step.getStepId());
|
||||||
scenarioExecution.setCurrentStepDescription(step.getName());
|
scenarioExecution.setCurrentStepDescription(step.getName());
|
||||||
|
|
||||||
ScenarioExecution scenarioExecutionNew=scenarioExecution;
|
ScenarioExecution scenarioExecutionNew = scenarioExecution;
|
||||||
|
|
||||||
try{
|
try {
|
||||||
solver.init(step, scenarioExecution,
|
solver.init(step, scenarioExecution,
|
||||||
vectorStore,chatModel,chatClient,graphDriver,neo4JUitilityService
|
vectorStore, chatModel, chatClient, graphDriver, neo4JUitilityService, discoveryClient);
|
||||||
,discoveryClient);
|
|
||||||
|
|
||||||
scenarioExecutionNew = solver.solveStep();
|
scenarioExecutionNew = solver.solveStep();
|
||||||
|
|
||||||
logger.info("Step solved: " + step.getStepId());
|
logger.info("Step solved: " + step.getStepId());
|
||||||
logger.info("Next step: " + scenarioExecutionNew.getNextStepId());
|
logger.info("Next step: " + scenarioExecutionNew.getNextStepId());
|
||||||
|
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
logger.error("Error while solving step: " + step.getStepId() + " => " + e.getMessage());
|
logger.error("Error while solving step: " + step.getStepId() + " => " + e.getMessage());
|
||||||
scenarioExecutionNew.setNextStepId(null);
|
scenarioExecutionNew.setNextStepId(null);
|
||||||
scenarioExecutionNew.setLatestStepStatus("ERROR");
|
scenarioExecutionNew.setLatestStepStatus("ERROR");
|
||||||
scenarioExecutionNew.setLatestStepOutput(e.getMessage());
|
scenarioExecutionNew.setLatestStepOutput(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
scenarioExecutionRepository.save(scenarioExecutionNew);
|
scenarioExecutionRepository.save(scenarioExecutionNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScenarioOutput prepareScrenarioExecution(ScenarioExecutionInput scenarioExecutionInput) {
|
||||||
public ScenarioOutput prepareScrenarioExecution(ScenarioExecutionInput scenarioExecutionInput){
|
|
||||||
|
|
||||||
String scenarioId = scenarioExecutionInput.getScenario_id();
|
String scenarioId = scenarioExecutionInput.getScenario_id();
|
||||||
ScenarioOutput scenarioOutput = new ScenarioOutput();
|
ScenarioOutput scenarioOutput = new ScenarioOutput();
|
||||||
|
|
||||||
Optional<Scenario> o_scenario = scenarioRepository.findById(scenarioId);
|
Optional<Scenario> o_scenario = scenarioRepository.findById(scenarioId);
|
||||||
|
|
||||||
if(o_scenario.isPresent()){
|
if (o_scenario.isPresent()) {
|
||||||
Scenario scenario = o_scenario.get();
|
Scenario scenario = o_scenario.get();
|
||||||
|
|
||||||
logger.info("Executing scenario: " + scenario.getName());
|
logger.info("Executing scenario: " + scenario.getName());
|
||||||
@@ -328,43 +335,45 @@ public class ScenarioExecutionService {
|
|||||||
|
|
||||||
ScenarioExecution scenarioExecution = new ScenarioExecution();
|
ScenarioExecution scenarioExecution = new ScenarioExecution();
|
||||||
scenarioExecution.setScenario(scenario);
|
scenarioExecution.setScenario(scenario);
|
||||||
//prendi i file dalla cartella temporanea se è presente una chiave con name "MultiFileUpload"
|
// prendi i file dalla cartella temporanea se è presente una chiave con name
|
||||||
if(scenarioExecutionInput.getInputs().containsKey("MultiFileUpload")){
|
// "MultiFileUpload"
|
||||||
|
if (scenarioExecutionInput.getInputs().containsKey("MultiFileUpload")) {
|
||||||
folder_name = scenarioExecutionInput.getInputs().get("MultiFileUpload");
|
folder_name = scenarioExecutionInput.getInputs().get("MultiFileUpload");
|
||||||
if(folder_name!=null && !folder_name.equals("")){
|
if (folder_name != null && !folder_name.equals("")) {
|
||||||
try{
|
try {
|
||||||
String base64 = folderToBase64(folder_name);
|
String base64 = folderToBase64(folder_name);
|
||||||
scenarioExecutionInput.getInputs().put("MultiFileUpload", base64);
|
scenarioExecutionInput.getInputs().put("MultiFileUpload", base64);
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
logger.error("Error while converting folder to base64: " + e.getMessage());
|
logger.error("Error while converting folder to base64: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(scenarioExecutionInput.getInputs().containsKey("SingleFileUpload")){
|
if (scenarioExecutionInput.getInputs().containsKey("SingleFileUpload")) {
|
||||||
scenarioExecutionInput.getInputs().put("SingleFileUpload", uploadDir + folder_name + "/" + scenarioExecutionInput.getInputs().get("SingleFileUpload"));
|
scenarioExecutionInput.getInputs().put("SingleFileUpload",
|
||||||
|
uploadDir + folder_name + "/" + scenarioExecutionInput.getInputs().get("SingleFileUpload"));
|
||||||
}
|
}
|
||||||
scenarioExecution.setScenarioExecutionInput(scenarioExecutionInput);
|
scenarioExecution.setScenarioExecutionInput(scenarioExecutionInput);
|
||||||
|
|
||||||
try{
|
try {
|
||||||
if( SecurityContextHolder.getContext() != null
|
if (SecurityContextHolder.getContext() != null
|
||||||
&& SecurityContextHolder.getContext().getAuthentication() != null
|
&& SecurityContextHolder.getContext().getAuthentication() != null
|
||||||
&& SecurityContextHolder.getContext().getAuthentication().getPrincipal()!= null
|
&& SecurityContextHolder.getContext().getAuthentication().getPrincipal() != null) {
|
||||||
){
|
|
||||||
|
|
||||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
scenarioExecution.setExecutedByUserId(principal.getId().toString());
|
scenarioExecution.setExecutedByUserId(principal.getId().toString());
|
||||||
scenarioExecution.setExecutedByUsername(principal.getUsername());
|
scenarioExecution.setExecutedByUsername(principal.getUsername());
|
||||||
if(principal.getSelectedApplication()!=null){
|
if (principal.getSelectedApplication() != null) {
|
||||||
scenarioExecutionInput.getInputs().put("selected_application", principal.getSelectedApplication().getInternal_name());
|
scenarioExecutionInput.getInputs().put("selected_application",
|
||||||
|
principal.getSelectedApplication().getInternal_name());
|
||||||
}
|
}
|
||||||
scenarioExecutionInput.getInputs().put("selected_project", principal.getSelectedProject().getInternal_name());
|
scenarioExecutionInput.getInputs().put("selected_project",
|
||||||
|
principal.getSelectedProject().getInternal_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
logger.error("Error while saving user information in scenario execution: " + e.getMessage());
|
logger.error("Error while saving user information in scenario execution: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
scenarioExecutionRepository.save(scenarioExecution);
|
scenarioExecutionRepository.save(scenarioExecution);
|
||||||
|
|
||||||
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
scenarioOutput.setScenarioExecution_id(scenarioExecution.getId());
|
||||||
@@ -425,15 +434,13 @@ public class ScenarioExecutionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ChatModel createChatModel(AiModel aiModel) {
|
||||||
private ChatModel createChatModel(AiModel aiModel){
|
switch (aiModel.getApiProvider()) {
|
||||||
switch(aiModel.getApiProvider()){
|
|
||||||
case "AzureOpenAI":
|
case "AzureOpenAI":
|
||||||
OpenAIClientBuilder openAIClient = new OpenAIClientBuilder()
|
OpenAIClientBuilder openAIClient = new OpenAIClientBuilder()
|
||||||
.credential(new AzureKeyCredential(aiModel.getApiKey()))
|
.credential(new AzureKeyCredential(aiModel.getApiKey()))
|
||||||
.endpoint(aiModel.getEndpoint());
|
.endpoint(aiModel.getEndpoint());
|
||||||
|
|
||||||
|
|
||||||
AzureOpenAiChatOptions openAIChatOptions = AzureOpenAiChatOptions.builder()
|
AzureOpenAiChatOptions openAIChatOptions = AzureOpenAiChatOptions.builder()
|
||||||
.deploymentName(aiModel.getModel())
|
.deploymentName(aiModel.getModel())
|
||||||
.maxTokens(aiModel.getMaxTokens())
|
.maxTokens(aiModel.getMaxTokens())
|
||||||
@@ -445,8 +452,6 @@ public class ScenarioExecutionService {
|
|||||||
logger.info("AI model used: " + aiModel.getModel());
|
logger.info("AI model used: " + aiModel.getModel());
|
||||||
return azureOpenaichatModel;
|
return azureOpenaichatModel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case "OpenAI":
|
case "OpenAI":
|
||||||
OpenAiApi openAiApi = new OpenAiApi(aiModel.getApiKey());
|
OpenAiApi openAiApi = new OpenAiApi(aiModel.getApiKey());
|
||||||
OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder()
|
OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder()
|
||||||
@@ -455,24 +460,23 @@ public class ScenarioExecutionService {
|
|||||||
.maxTokens(aiModel.getMaxTokens())
|
.maxTokens(aiModel.getMaxTokens())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
OpenAiChatModel openaichatModel = new OpenAiChatModel(openAiApi,openAiChatOptions);
|
OpenAiChatModel openaichatModel = new OpenAiChatModel(openAiApi, openAiChatOptions);
|
||||||
logger.info("AI model used: " + aiModel.getModel());
|
logger.info("AI model used: " + aiModel.getModel());
|
||||||
return openaichatModel;
|
return openaichatModel;
|
||||||
|
|
||||||
|
|
||||||
case "GoogleGemini":
|
case "GoogleGemini":
|
||||||
OpenAIClientBuilder openAIClient2 = new OpenAIClientBuilder()
|
OpenAIClientBuilder openAIClient2 = new OpenAIClientBuilder()
|
||||||
.credential(new AzureKeyCredential(aiModel.getApiKey()))
|
.credential(new AzureKeyCredential(aiModel.getApiKey()))
|
||||||
.endpoint(aiModel.getEndpoint());
|
.endpoint(aiModel.getEndpoint());
|
||||||
|
|
||||||
|
|
||||||
AzureOpenAiChatOptions openAIChatOptions2 = AzureOpenAiChatOptions.builder()
|
AzureOpenAiChatOptions openAIChatOptions2 = AzureOpenAiChatOptions.builder()
|
||||||
.deploymentName(aiModel.getModel())
|
.deploymentName(aiModel.getModel())
|
||||||
.maxTokens(aiModel.getMaxTokens())
|
.maxTokens(aiModel.getMaxTokens())
|
||||||
.temperature(Double.valueOf(aiModel.getTemperature()))
|
.temperature(Double.valueOf(aiModel.getTemperature()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
AzureOpenAiChatModel azureOpenaichatModel2 = new AzureOpenAiChatModel(openAIClient2, openAIChatOptions2);
|
AzureOpenAiChatModel azureOpenaichatModel2 = new AzureOpenAiChatModel(openAIClient2,
|
||||||
|
openAIChatOptions2);
|
||||||
|
|
||||||
logger.info("AI model used : " + aiModel.getModel());
|
logger.info("AI model used : " + aiModel.getModel());
|
||||||
return azureOpenaichatModel2;
|
return azureOpenaichatModel2;
|
||||||
@@ -481,51 +485,206 @@ public class ScenarioExecutionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ScenarioExecution> getListExecutionScenarioByUser(){
|
/*
|
||||||
logger.info("getListProjectByUser function:");
|
* public List<ScenarioExecution> getListExecutionScenario(){
|
||||||
|
* logger.info("getListProjectByUser function:");
|
||||||
|
*
|
||||||
|
* List<ScenarioExecution> lstScenarioExecution = null;
|
||||||
|
*
|
||||||
|
* User principal = (User)
|
||||||
|
* SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
*
|
||||||
|
* if(principal.getSelectedApplication()!=null){
|
||||||
|
* lstScenarioExecution =
|
||||||
|
* scenarioExecutionRepository.getFromProjectAndAPP(principal.getId(),
|
||||||
|
* principal.getSelectedProject().getInternal_name(),
|
||||||
|
* principal.getSelectedApplication().getInternal_name(),
|
||||||
|
* Sort.by(Sort.Direction.DESC, "startDate"));
|
||||||
|
*
|
||||||
|
* }else{
|
||||||
|
* lstScenarioExecution =
|
||||||
|
* scenarioExecutionRepository.getFromProject(principal.getId(),
|
||||||
|
* principal.getSelectedProject().getInternal_name(),
|
||||||
|
* Sort.by(Sort.Direction.DESC, "startDate"));
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return lstScenarioExecution;
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
|
||||||
List<ScenarioExecution> lstScenarioExecution = null;
|
public Page<ScenarioExecution> getListExecutionScenarioOptional(int page, int size, String scenarioName,
|
||||||
|
String executedBy, LocalDate startDate) {
|
||||||
|
logger.info("getListExecutionScenarioOptional function:");
|
||||||
|
|
||||||
|
List<Criteria> criteriaList = new ArrayList<>();
|
||||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
|
||||||
if(principal.getSelectedApplication()!=null){
|
// Filtro per progetto selezionato
|
||||||
lstScenarioExecution = scenarioExecutionRepository.getFromProjectAndAPP(principal.getId(), principal.getSelectedProject().getInternal_name(), principal.getSelectedApplication().getInternal_name(), Sort.by(Sort.Direction.DESC, "startDate"));
|
if (principal.getSelectedProject() != null && principal.getSelectedProject().getId() != null) {
|
||||||
|
criteriaList.add(Criteria.where("scenarioExecutionInput.inputs.selected_project")
|
||||||
}else{
|
.is(principal.getSelectedProject().getInternal_name()));
|
||||||
lstScenarioExecution = scenarioExecutionRepository.getFromProject(principal.getId(), principal.getSelectedProject().getInternal_name(), Sort.by(Sort.Direction.DESC, "startDate"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lstScenarioExecution;
|
// Filtro per applicazione selezionata
|
||||||
|
if (principal.getSelectedApplication() != null && principal.getSelectedApplication().getId() != null) {
|
||||||
|
criteriaList.add(Criteria.where("scenarioExecutionInput.inputs.selected_application")
|
||||||
|
.is(principal.getSelectedApplication().getInternal_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String updateRating2(ScenarioExecution scenaExec){
|
// Filtro per nome scenario
|
||||||
logger.info("updateRating function:");
|
if (scenarioName != null) {
|
||||||
String result = "KO";
|
criteriaList.add(Criteria.where("scenarioExecutionInput.scenario.name").is(scenarioName));
|
||||||
try{
|
|
||||||
scenarioExecutionRepository.save(scenaExec);
|
|
||||||
result = "OK";
|
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Exception in updateRating: {}", e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
// Filtro per utente che ha eseguito
|
||||||
|
if (executedBy != null) {
|
||||||
|
criteriaList.add(Criteria.where("executedByUsername").is(executedBy));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String updateRating(String id, String rating){
|
// Filtro per data di inizio
|
||||||
logger.info("updateRating function:");
|
if (startDate != null) {
|
||||||
String result = "KO";
|
criteriaList.add(Criteria.where("startDate").gte(startDate));
|
||||||
try{
|
|
||||||
Optional<ScenarioExecution> o_scenarioExecution = scenarioExecutionRepository.findById(id);
|
|
||||||
if(o_scenarioExecution.isPresent()){
|
|
||||||
o_scenarioExecution.get().setRating(rating);
|
|
||||||
scenarioExecutionRepository.save(o_scenarioExecution.get());
|
|
||||||
result = "OK";
|
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
|
||||||
logger.error("Exception in updateRating: {}", e.getMessage());
|
// Costruisce la query solo con i criteri presenti
|
||||||
|
Criteria criteria = new Criteria();
|
||||||
|
if (!criteriaList.isEmpty()) {
|
||||||
|
criteria = new Criteria().andOperator(criteriaList.toArray(new Criteria[0]));
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
Query query = new Query(criteria);
|
||||||
|
long count = mongoTemplate.count(query, ScenarioExecution.class); // Conta i documenti senza paginazione
|
||||||
|
|
||||||
|
// Applica la paginazione solo per ottenere i risultati
|
||||||
|
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "startDate"));
|
||||||
|
query.with(pageable);
|
||||||
|
|
||||||
|
List<ScenarioExecution> results = mongoTemplate.find(query, ScenarioExecution.class);
|
||||||
|
|
||||||
|
return new PageImpl<>(results, pageable, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Page<ScenarioExecution> getFilteredExecutions(Map<String, Object> filters) {
|
||||||
|
logger.info("getFilteredExecutions function:");
|
||||||
|
|
||||||
|
List<Criteria> criteriaList = new ArrayList<>();
|
||||||
|
|
||||||
|
int page = 0;
|
||||||
|
int size = 10;
|
||||||
|
String sortField = "startDate";
|
||||||
|
int sortOrder = -1;
|
||||||
|
|
||||||
|
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
criteriaList.add(Criteria.where("execSharedMap.user_input.selected_project")
|
||||||
|
.is(principal.getSelectedProject().getInternal_name()));
|
||||||
|
criteriaList.add(Criteria.where("execSharedMap.user_input.selected_application")
|
||||||
|
.is(principal.getSelectedApplication().getInternal_name()));
|
||||||
|
// here:
|
||||||
|
// filtri
|
||||||
|
// here:
|
||||||
|
// here: vedi perchè non funziona link di view
|
||||||
|
// here: da sistemare filtro data a backend e i vari equals
|
||||||
|
// here: add ordinamento
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : filters.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
|
||||||
|
if ("page".equals(key)) {
|
||||||
|
page = (int) value;
|
||||||
|
} else if ("size".equals(key)) {
|
||||||
|
size = (int) value;
|
||||||
|
}else if ("sortField".equals(key)) {
|
||||||
|
if(value!=null) {
|
||||||
|
sortField = (String) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if("sortOrder".equals(key)){
|
||||||
|
if(value!=null) {
|
||||||
|
sortOrder = (int) value;
|
||||||
|
}
|
||||||
|
}else if (value instanceof Map) {
|
||||||
|
Map<String, Object> valueMap = (Map<String, Object>) value;
|
||||||
|
String operator = (String) valueMap.get("operator");
|
||||||
|
List<Map<String, Object>> constraints = (List<Map<String, Object>>) valueMap.get("constraints");
|
||||||
|
|
||||||
|
for (Map<String, Object> constraint : constraints) {
|
||||||
|
Object constraintValue = constraint.get("value");
|
||||||
|
String matchMode = (String) constraint.get("matchMode");
|
||||||
|
|
||||||
|
if (constraintValue != null && !constraintValue.toString().isEmpty()) {
|
||||||
|
switch (matchMode) {
|
||||||
|
case "contains":
|
||||||
|
if (key.equals("_id")) {
|
||||||
|
criteriaList.add(Criteria.where("_id").is(new ObjectId((String) constraintValue)));
|
||||||
|
} else {
|
||||||
|
criteriaList.add(Criteria.where(key).regex((String) constraintValue, "i"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "notContains":
|
||||||
|
criteriaList.add(Criteria.where(key).not().regex((String) constraintValue, "i"));
|
||||||
|
break;
|
||||||
|
case "dateIs":
|
||||||
|
criteriaList.add(Criteria.where(key).is(
|
||||||
|
LocalDate.parse(((String) constraintValue).substring(0, 10))));
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "dateIsNot":
|
||||||
|
criteriaList.add(Criteria.where(key).ne(Criteria.where(key).is(
|
||||||
|
LocalDate.parse(((String) constraintValue).substring(0, 10)))));
|
||||||
|
break;
|
||||||
|
case "dateBefore":
|
||||||
|
criteriaList.add(Criteria.where(key).lt(Criteria.where(key).is(
|
||||||
|
LocalDate.parse(((String) constraintValue).substring(0, 10)))));
|
||||||
|
break;
|
||||||
|
case "dateAfter":
|
||||||
|
criteriaList.add(Criteria.where(key).gt(Criteria.where(key).is(
|
||||||
|
LocalDate.parse(((String) constraintValue).substring(0, 10)))));
|
||||||
|
break;
|
||||||
|
case "equals":
|
||||||
|
criteriaList.add(Criteria.where(key).is(constraintValue));
|
||||||
|
break;
|
||||||
|
case "notEquals":
|
||||||
|
criteriaList.add(Criteria.where(key).ne(constraintValue));
|
||||||
|
break;
|
||||||
|
case "startsWith":
|
||||||
|
criteriaList.add(Criteria.where(key).regex("^" + constraintValue, "i"));
|
||||||
|
break;
|
||||||
|
case "endsWith":
|
||||||
|
criteriaList.add(Criteria.where(key).regex(constraintValue + "$", "i"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
criteriaList.add(Criteria.where(key).is(constraintValue));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (value instanceof String) {
|
||||||
|
criteriaList.add(Criteria.where(key).regex((String) value, "i"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Criteria criteria = new Criteria();
|
||||||
|
if (!criteriaList.isEmpty()) {
|
||||||
|
criteria = new Criteria().andOperator(criteriaList.toArray(new Criteria[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
Query query = new Query(criteria);
|
||||||
|
long count = mongoTemplate.count(query, ScenarioExecution.class);
|
||||||
|
|
||||||
|
Pageable pageable = null;
|
||||||
|
if(sortOrder == -1) {
|
||||||
|
pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, sortField));
|
||||||
|
}else {
|
||||||
|
pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.ASC, sortField));
|
||||||
|
}
|
||||||
|
query.with(pageable);
|
||||||
|
|
||||||
|
List<ScenarioExecution> results = mongoTemplate.find(query, ScenarioExecution.class);
|
||||||
|
|
||||||
|
return new PageImpl<>(results, pageable, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,17 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.olympus.hermione.models.Scenario;
|
import com.olympus.hermione.models.Scenario;
|
||||||
|
import com.olympus.hermione.models.ScenarioExecution;
|
||||||
import com.olympus.hermione.repository.ProjectRepository;
|
import com.olympus.hermione.repository.ProjectRepository;
|
||||||
|
import com.olympus.hermione.repository.ScenarioExecutionRepository;
|
||||||
import com.olympus.hermione.repository.ScenarioRepository;
|
import com.olympus.hermione.repository.ScenarioRepository;
|
||||||
import com.olympus.hermione.security.entity.User;
|
import com.olympus.hermione.security.entity.User;
|
||||||
import com.olympus.model.Project;
|
import com.olympus.model.Project;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -24,11 +28,24 @@ public class ScenarioService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ScenarioRepository scenarioRepo;
|
private ScenarioRepository scenarioRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ScenarioExecutionRepository scenarioExecutionRepository;
|
||||||
|
|
||||||
public List<Scenario> getListScenariosByProject(String project){
|
public List<Scenario> getListScenariosByProject(String project){
|
||||||
logger.info("getListProjectByUser function:");
|
logger.info("getListProjectByUser function:");
|
||||||
List<Scenario> lstScenarios = null;
|
List<Scenario> lstScenarios = null;
|
||||||
|
|
||||||
|
List<String> scenAccept = new ArrayList<String>();
|
||||||
|
scenAccept.add("Y");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
lstScenarios = scenarioRepo.findByAvailableForProjects_IdAndVisible(project, "Y");
|
|
||||||
|
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
if(user.getRole().name().equals("ADMIN")){
|
||||||
|
scenAccept.add("DRAFT");
|
||||||
|
}
|
||||||
|
lstScenarios = scenarioRepo.findByAvailableForProjects_IdAndVisibleIn(project, scenAccept);
|
||||||
|
//lstScenarios = scenarioRepo.findByAvailableForProjects_IdAndVisible(project, "Y");
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Exception ScenarioRepository:", e.getMessage());
|
logger.error("Exception ScenarioRepository:", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -41,8 +58,16 @@ public class ScenarioService {
|
|||||||
public List<Scenario> getListScenariosByApplication(String app){
|
public List<Scenario> getListScenariosByApplication(String app){
|
||||||
logger.info("getListProjectByUser function:");
|
logger.info("getListProjectByUser function:");
|
||||||
List<Scenario> lstScenarios = null;
|
List<Scenario> lstScenarios = null;
|
||||||
|
List<String> scenAccept = new ArrayList<String>();
|
||||||
|
scenAccept.add("Y");
|
||||||
try{
|
try{
|
||||||
lstScenarios = scenarioRepo.findByAvailableForApplications_IdAndVisible(app, "Y");
|
|
||||||
|
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
if(user.getRole().name().equals("ADMIN")){
|
||||||
|
scenAccept.add("DRAFT");
|
||||||
|
}
|
||||||
|
lstScenarios = scenarioRepo.findByAvailableForApplications_IdAndVisibleIn(app, scenAccept);
|
||||||
|
//
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Exception ScenarioRepository:", e.getMessage());
|
logger.error("Exception ScenarioRepository:", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -55,8 +80,16 @@ public class ScenarioService {
|
|||||||
public List<Scenario> getListScenariosCross(){
|
public List<Scenario> getListScenariosCross(){
|
||||||
logger.info("getListProjectByUser function:");
|
logger.info("getListProjectByUser function:");
|
||||||
List<Scenario> lstScenarios = null;
|
List<Scenario> lstScenarios = null;
|
||||||
|
|
||||||
|
List<String> scenAccept = new ArrayList<String>();
|
||||||
|
scenAccept.add("Y");
|
||||||
try{
|
try{
|
||||||
lstScenarios = scenarioRepo.findByAvailableForProjectsIsNullAndAvailableForApplicationsIsNullAndVisible("Y");
|
|
||||||
|
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
if(user.getRole().name().equals("ADMIN")){
|
||||||
|
scenAccept.add("DRAFT");
|
||||||
|
}
|
||||||
|
lstScenarios = scenarioRepo.findByAvailableForProjectsIsNullAndAvailableForApplicationsIsNullAndVisibleIn(scenAccept);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Exception ScenarioRepository:", e.getMessage());
|
logger.error("Exception ScenarioRepository:", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -72,10 +105,16 @@ public class ScenarioService {
|
|||||||
Scenario scenarioDefault = new Scenario();
|
Scenario scenarioDefault = new Scenario();
|
||||||
scenarioDefault.setName("Default");
|
scenarioDefault.setName("Default");
|
||||||
scenarioDefault.setId("");
|
scenarioDefault.setId("");
|
||||||
|
|
||||||
|
List<String> scenAccept = new ArrayList<String>();
|
||||||
|
scenAccept.add("Y");
|
||||||
try{
|
try{
|
||||||
|
|
||||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
lstScenarios = scenarioRepo.findByVisibleAndCategoryAndProjectOrApplication(user.getSelectedProject().getId(), user.getSelectedApplication().getId());
|
if(user.getRole().name().equals("ADMIN")){
|
||||||
|
scenAccept.add("DRAFT");
|
||||||
|
}
|
||||||
|
lstScenarios = scenarioRepo.findByVisibleInAndCategoryAndProjectOrApplication(user.getSelectedProject().getId(), user.getSelectedApplication().getId(), scenAccept);
|
||||||
lstScenarios.add(scenarioDefault);
|
lstScenarios.add(scenarioDefault);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
logger.error("Exception ScenarioRepository:", e.getMessage());
|
logger.error("Exception ScenarioRepository:", e.getMessage());
|
||||||
@@ -85,4 +124,20 @@ public class ScenarioService {
|
|||||||
return lstScenarios;
|
return lstScenarios;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String updateRating(String id, String rating) {
|
||||||
|
logger.info("updateRating function:");
|
||||||
|
String result = "KO";
|
||||||
|
try {
|
||||||
|
Optional<ScenarioExecution> o_scenarioExecution = scenarioExecutionRepository.findById(id);
|
||||||
|
if (o_scenarioExecution.isPresent()) {
|
||||||
|
o_scenarioExecution.get().setRating(rating);
|
||||||
|
scenarioExecutionRepository.save(o_scenarioExecution.get());
|
||||||
|
result = "OK";
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Exception in updateRating: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class DeleteDocTempSolver extends StepSolver {
|
|||||||
if(this.step.getAttributes().containsKey("rag_topk")){
|
if(this.step.getAttributes().containsKey("rag_topk")){
|
||||||
this.topk = (int) this.step.getAttributes().get("rag_topk");
|
this.topk = (int) this.step.getAttributes().get("rag_topk");
|
||||||
}else{
|
}else{
|
||||||
this.topk = 1000;
|
this.topk = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.step.getAttributes().containsKey("rag_threshold")){
|
if(this.step.getAttributes().containsKey("rag_threshold")){
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ScenarioExecutionRepository scenarioExecutionRepo;
|
private ScenarioExecutionRepository scenarioExecutionRepo;
|
||||||
|
|
||||||
Logger logger = (Logger) LoggerFactory.getLogger(BasicQueryRagSolver.class);
|
Logger logger = (Logger) LoggerFactory.getLogger(ExternalCodeGenieSolver.class);
|
||||||
|
|
||||||
private void loadParameters() {
|
private void loadParameters() {
|
||||||
logger.info("Loading parameters");
|
logger.info("Loading parameters");
|
||||||
@@ -104,8 +104,6 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
@Override
|
@Override
|
||||||
public ScenarioExecution solveStep() throws Exception {
|
public ScenarioExecution solveStep() throws Exception {
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
System.out.println("Solving step: " + this.step.getName());
|
System.out.println("Solving step: " + this.step.getName());
|
||||||
|
|
||||||
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
|
this.scenarioExecution.setCurrentStepId(this.step.getStepId());
|
||||||
@@ -149,7 +147,6 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
jsonResponse.get("token_type").toString() + " " + jsonResponse.get("access_token").toString());
|
jsonResponse.get("token_type").toString() + " " + jsonResponse.get("access_token").toString());
|
||||||
HttpEntity<String> request = new HttpEntity<>(requestBody.toString(), headers);
|
HttpEntity<String> request = new HttpEntity<>(requestBody.toString(), headers);
|
||||||
|
|
||||||
|
|
||||||
response = restTemplate.exchange(
|
response = restTemplate.exchange(
|
||||||
this.codegenie_base_url + "/execute",
|
this.codegenie_base_url + "/execute",
|
||||||
HttpMethod.POST,
|
HttpMethod.POST,
|
||||||
@@ -158,13 +155,16 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
|
|
||||||
jsonResponse = new JSONObject(response.getBody());
|
jsonResponse = new JSONObject(response.getBody());
|
||||||
|
|
||||||
/* response = restTemplate.exchange(
|
/*
|
||||||
//this.codegenie_base_url + "/execution_status/" + this.scenarioExecution.getId(),
|
* response = restTemplate.exchange(
|
||||||
this.codegenie_base_url + "/execution_status/679752f85189eb5621b48e17",
|
* //this.codegenie_base_url + "/execution_status/" +
|
||||||
HttpMethod.GET,
|
* this.scenarioExecution.getId(),
|
||||||
request,
|
* this.codegenie_base_url + "/execution_status/679752f85189eb5621b48e17",
|
||||||
String.class);
|
* HttpMethod.GET,
|
||||||
jsonResponse = new JSONObject(response.getBody());*/
|
* request,
|
||||||
|
* String.class);
|
||||||
|
* jsonResponse = new JSONObject(response.getBody());
|
||||||
|
*/
|
||||||
|
|
||||||
int maxTries = 500;
|
int maxTries = 500;
|
||||||
// Pool the status GET api until it return the SUCCESS or FAILED message
|
// Pool the status GET api until it return the SUCCESS or FAILED message
|
||||||
@@ -184,7 +184,7 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
|
|
||||||
response = restTemplate.exchange(
|
response = restTemplate.exchange(
|
||||||
this.codegenie_base_url + "/execution_status/" + this.scenarioExecution.getId(),
|
this.codegenie_base_url + "/execution_status/" + this.scenarioExecution.getId(),
|
||||||
//this.codegenie_base_url + "/execution_status/679752f85189eb5621b48e17",
|
// this.codegenie_base_url + "/execution_status/679752f85189eb5621b48e17",
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
request,
|
request,
|
||||||
String.class);
|
String.class);
|
||||||
@@ -218,8 +218,8 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
request = new HttpEntity<>(requestBody.toString(), headers);
|
request = new HttpEntity<>(requestBody.toString(), headers);
|
||||||
|
|
||||||
response = restTemplate.exchange(
|
response = restTemplate.exchange(
|
||||||
this.codegenie_base_url + "/execution_result/" +this.scenarioExecution.getId(),
|
this.codegenie_base_url + "/execution_result/" + this.scenarioExecution.getId(),
|
||||||
//this.codegenie_base_url + "/execution_result/679752f85189eb5621b48e17",
|
// this.codegenie_base_url + "/execution_result/679752f85189eb5621b48e17",
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
request,
|
request,
|
||||||
String.class);
|
String.class);
|
||||||
@@ -274,12 +274,17 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
this.scenarioExecution.getExecSharedMap().put("status",
|
this.scenarioExecution.getExecSharedMap().put("status",
|
||||||
"DONE");
|
"DONE");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
this.scenarioExecution.getExecSharedMap().put(this.codegenie_output_variable,
|
||||||
|
"Error while generating file");
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"codegenie execution failed with status: " + jsonResponse.get("status").toString());
|
"codegenie execution failed with status: " + jsonResponse.get("status").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.error("ERROR on pooling codegenies");
|
logger.error("ERROR on pooling codegenies");
|
||||||
|
this.scenarioExecution.getExecSharedMap().put(this.codegenie_output_variable,
|
||||||
|
"Error while generating file");
|
||||||
|
|
||||||
throw new Exception("codegenie execution failed with status: " + jsonResponse.get("status").toString());
|
throw new Exception("codegenie execution failed with status: " + jsonResponse.get("status").toString());
|
||||||
}
|
}
|
||||||
@@ -297,7 +302,7 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
|
|
||||||
response = restTemplate.exchange(
|
response = restTemplate.exchange(
|
||||||
this.codegenie_base_url + "/execution_consumption/" + this.scenarioExecution.getId(),
|
this.codegenie_base_url + "/execution_consumption/" + this.scenarioExecution.getId(),
|
||||||
//this.codegenie_base_url + "/execution_consumption/679752f85189eb5621b48e17",
|
// this.codegenie_base_url + "/execution_consumption/679752f85189eb5621b48e17",
|
||||||
HttpMethod.GET,
|
HttpMethod.GET,
|
||||||
request,
|
request,
|
||||||
String.class);
|
String.class);
|
||||||
@@ -309,11 +314,7 @@ public class ExternalCodeGenieSolver extends StepSolver {
|
|||||||
|
|
||||||
// scenarioExecutionRepo.save(this.scenarioExecution);
|
// scenarioExecutionRepo.save(this.scenarioExecution);
|
||||||
|
|
||||||
} catch (Exception e) {
|
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
||||||
logger.error("Error in codegenie execution: " + e.getMessage(), e);
|
|
||||||
this.scenarioExecution.getExecSharedMap().put("status",
|
|
||||||
"ERROR");
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.scenarioExecution;
|
return this.scenarioExecution;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,16 +36,18 @@ public class SummarizeDocSolver extends StepSolver {
|
|||||||
private String qai_system_prompt_template_chunk;
|
private String qai_system_prompt_template_chunk;
|
||||||
private String qai_path_file;
|
private String qai_path_file;
|
||||||
private String qai_output_variable;
|
private String qai_output_variable;
|
||||||
private int chunk_size_token;
|
private int max_chunk_size_token;
|
||||||
private String encoding_name;
|
private String encoding_name;
|
||||||
private double charMax;
|
|
||||||
private int tokenCount;
|
private int tokenCount;
|
||||||
private Optional<Encoding> encoding;
|
private Optional<Encoding> encoding;
|
||||||
private int percent_summarize;
|
private Double percent_chunk_length;
|
||||||
private Integer maxTokenChunk;
|
|
||||||
private String qai_custom_memory_id;
|
private String qai_custom_memory_id;
|
||||||
private Integer max_output_token;
|
private Integer max_output_token;
|
||||||
private String qai_system_prompt_template_minimum;
|
private Integer max_input_token_not_to_be_chunked;
|
||||||
|
private String qai_system_prompt_template_formatter;
|
||||||
|
private boolean isChunked = false;
|
||||||
|
private Double chunk_size_token_calc;
|
||||||
|
|
||||||
// private boolean qai_load_graph_schema=false;
|
// private boolean qai_load_graph_schema=false;
|
||||||
|
|
||||||
Logger logger = (Logger) LoggerFactory.getLogger(SummarizeDocSolver.class);
|
Logger logger = (Logger) LoggerFactory.getLogger(SummarizeDocSolver.class);
|
||||||
@@ -64,17 +66,18 @@ public class SummarizeDocSolver extends StepSolver {
|
|||||||
this.qai_output_variable = (String) this.step.getAttributes().get("qai_output_variable");
|
this.qai_output_variable = (String) this.step.getAttributes().get("qai_output_variable");
|
||||||
this.encoding_name = (String) this.step.getAttributes().get("encoding_name");
|
this.encoding_name = (String) this.step.getAttributes().get("encoding_name");
|
||||||
|
|
||||||
this.chunk_size_token = Integer.parseInt((String) this.step.getAttributes().get("chunk_size_token"));
|
this.max_chunk_size_token = Integer.parseInt((String) this.step.getAttributes().get("max_chunk_size_token"));
|
||||||
|
|
||||||
this.percent_summarize = Integer.parseInt((String) this.step.getAttributes().get("percent_summarize"));
|
this.percent_chunk_length = (Double) this.step.getAttributes().get("percent_chunk_length");
|
||||||
|
|
||||||
this.qai_custom_memory_id = (String) this.step.getAttributes().get("qai_custom_memory_id");
|
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.max_output_token = Integer.parseInt((String) this.step.getAttributes().get("max_output_token"));
|
||||||
|
|
||||||
this.qai_system_prompt_template_minimum = attributeParser
|
this.max_input_token_not_to_be_chunked = Integer.parseInt((String) this.step.getAttributes().get("max_input_token_not_to_be_chunked"));
|
||||||
.parse((String) this.step.getAttributes().get("qai_system_prompt_template_minimum"));
|
|
||||||
|
|
||||||
|
this.qai_system_prompt_template_formatter = attributeParser
|
||||||
|
.parse((String) this.step.getAttributes().get("qai_system_prompt_template_formatter"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,35 +99,37 @@ public class SummarizeDocSolver extends StepSolver {
|
|||||||
EncodingRegistry registry = Encodings.newDefaultEncodingRegistry();
|
EncodingRegistry registry = Encodings.newDefaultEncodingRegistry();
|
||||||
encoding = registry.getEncoding(this.encoding_name);
|
encoding = registry.getEncoding(this.encoding_name);
|
||||||
|
|
||||||
// Conta i token
|
|
||||||
// int tokenCount = encoding.get().encode(text).size();
|
|
||||||
tokenCount = encoding.get().countTokens(text);
|
tokenCount = encoding.get().countTokens(text);
|
||||||
int charCount = text.length();
|
logger.info("token count input: " + tokenCount);
|
||||||
|
|
||||||
// Stima media caratteri per token
|
// Calcolo della dimensione del chunk in token
|
||||||
// double charPerToken = (double) charCount / tokenCount;
|
chunk_size_token_calc = (Double)((double)tokenCount * percent_chunk_length);
|
||||||
|
if(chunk_size_token_calc>max_chunk_size_token){
|
||||||
|
chunk_size_token_calc = (double)max_chunk_size_token;
|
||||||
|
|
||||||
//Double output_char = (double) charCount * ((double) this.percent_summarize / 100.0);
|
}
|
||||||
Double min_output_token = (double) tokenCount * ((double) this.percent_summarize / 100.0);
|
// **Fase di Summarization**
|
||||||
String content = new String("");
|
String summarizedText = text;
|
||||||
content = this.qai_system_prompt_template.replace("max_number_token",
|
|
||||||
max_output_token.toString());
|
|
||||||
|
|
||||||
if (min_output_token < max_output_token) {
|
if(tokenCount > max_input_token_not_to_be_chunked){
|
||||||
content += this.qai_system_prompt_template_minimum.replace(
|
summarizedText = summarize(text);
|
||||||
"min_number_token",
|
|
||||||
min_output_token.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: " + content);
|
|
||||||
// Creazione dei messaggi per il modello AI
|
// Creazione dei messaggi per il modello AI
|
||||||
Message userMessage = new UserMessage(summarizedText);
|
Message userMessage = new UserMessage(summarizedText);
|
||||||
Message systemMessage = new SystemMessage(content);
|
Message systemMessage = null;
|
||||||
logger.info("template: " + systemMessage.getText());
|
|
||||||
|
int tokenCountSummary = encoding.get().countTokens(summarizedText);
|
||||||
|
|
||||||
|
if(isChunked && tokenCountSummary < max_output_token){
|
||||||
|
systemMessage = new SystemMessage(this.qai_system_prompt_template_formatter);
|
||||||
|
logger.info("template formatter: " + this.qai_system_prompt_template_formatter);
|
||||||
|
}else{
|
||||||
|
//here
|
||||||
|
systemMessage = new SystemMessage(this.qai_system_prompt_template);
|
||||||
|
logger.info("template: " + this.qai_system_prompt_template);
|
||||||
|
}
|
||||||
|
|
||||||
CallResponseSpec resp = chatClient.prompt()
|
CallResponseSpec resp = chatClient.prompt()
|
||||||
.messages(userMessage, systemMessage)
|
.messages(userMessage, systemMessage)
|
||||||
.advisors(advisor -> advisor
|
.advisors(advisor -> advisor
|
||||||
@@ -144,6 +149,9 @@ public class SummarizeDocSolver extends StepSolver {
|
|||||||
logger.info("Token usage information is not available.");
|
logger.info("Token usage information is not available.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tokenCount = encoding.get().countTokens(output);
|
||||||
|
logger.info("token count output: " + tokenCount);
|
||||||
|
|
||||||
// Salvataggio dell'output nel contesto di esecuzione
|
// Salvataggio dell'output nel contesto di esecuzione
|
||||||
this.scenarioExecution.getExecSharedMap().put(this.qai_output_variable, output);
|
this.scenarioExecution.getExecSharedMap().put(this.qai_output_variable, output);
|
||||||
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
this.scenarioExecution.setNextStepId(this.step.getNextStepId());
|
||||||
@@ -157,14 +165,15 @@ public class SummarizeDocSolver extends StepSolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String summarize(String text) {
|
private String summarize(String text) {
|
||||||
// Se il testo è già corto, non riassumere
|
|
||||||
logger.info("length: " + text.length());
|
logger.info("length: " + text.length());
|
||||||
Double chunk_size_text;
|
Double chunk_size_text;
|
||||||
|
|
||||||
|
tokenCount = encoding.get().countTokens(text);
|
||||||
int textLengthPlus = (int) (text.length() * 1.1);
|
int textLengthPlus = (int) (text.length() * 1.1);
|
||||||
int tokenCountPlus = (int) (tokenCount * 1.1);
|
int tokenCountPlus = (int) (tokenCount * 1.1);
|
||||||
// chunk_size_token/(ratio+10%)
|
|
||||||
// Double ratio = Math.floor((textLengthPlus / charMax) + 1);
|
Double ratio = Math.floor((tokenCountPlus / chunk_size_token_calc) + 1);
|
||||||
Double ratio = Math.floor((tokenCountPlus / chunk_size_token) + 1);
|
//Double ratio = Math.floor((tokenCountPlus / chunk_size_token) + 1);
|
||||||
if (ratio == 1) {
|
if (ratio == 1) {
|
||||||
return text;
|
return text;
|
||||||
} else {
|
} else {
|
||||||
@@ -175,21 +184,19 @@ public class SummarizeDocSolver extends StepSolver {
|
|||||||
List<String> chunks = chunkText(text, chunk_size_text.intValue());
|
List<String> chunks = chunkText(text, chunk_size_text.intValue());
|
||||||
List<String> summarizedChunks = new ArrayList<>();
|
List<String> summarizedChunks = new ArrayList<>();
|
||||||
|
|
||||||
Double maxTokenChunkD = Math.ceil(chunk_size_token / ratio);
|
|
||||||
maxTokenChunk = maxTokenChunkD.intValue();
|
|
||||||
|
|
||||||
// Riassumere ogni chunk singolarmente
|
// Riassumere ogni chunk singolarmente
|
||||||
for (String chunk : chunks) {
|
for (String chunk : chunks) {
|
||||||
logger.info("chunk length: " + chunk.length());
|
logger.info("chunk length: " + chunk.length());
|
||||||
summarizedChunks.add(summarizeChunk(chunk));
|
summarizedChunks.add(summarizeChunk(chunk));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isChunked = true;
|
||||||
// Unire i riassunti
|
// Unire i riassunti
|
||||||
String summarizedText = String.join(" ", summarizedChunks);
|
String summarizedText = String.join(" ", summarizedChunks);
|
||||||
int tokenCountSummarizedText = encoding.get().countTokens(summarizedText);
|
int tokenCountSummarizedText = encoding.get().countTokens(summarizedText);
|
||||||
|
|
||||||
// Se il riassunto è ancora troppo lungo, applicare ricorsione
|
// Se il riassunto è ancora troppo lungo, applicare ricorsione
|
||||||
if (tokenCountSummarizedText > chunk_size_token) {
|
if (tokenCountSummarizedText > max_output_token) {
|
||||||
return summarize(summarizedText);
|
return summarize(summarizedText);
|
||||||
} else {
|
} else {
|
||||||
return summarizedText;
|
return summarizedText;
|
||||||
@@ -208,21 +215,12 @@ public class SummarizeDocSolver extends StepSolver {
|
|||||||
|
|
||||||
// Metodo di riassunto per singolo chunk
|
// Metodo di riassunto per singolo chunk
|
||||||
private String summarizeChunk(String chunk) {
|
private String summarizeChunk(String chunk) {
|
||||||
String content = new String("");
|
|
||||||
|
|
||||||
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 chunkMessage = new UserMessage(chunk);
|
||||||
Message systemMessage = new SystemMessage(
|
Message systemMessage = new SystemMessage(
|
||||||
content);
|
this.qai_system_prompt_template_chunk);
|
||||||
|
|
||||||
logger.info("template chunk: " + content);
|
logger.info("template chunk: " + this.qai_system_prompt_template_chunk);
|
||||||
|
|
||||||
CallResponseSpec resp = chatClient.prompt()
|
CallResponseSpec resp = chatClient.prompt()
|
||||||
.messages(chunkMessage, systemMessage)
|
.messages(chunkMessage, systemMessage)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ spring.ai.vectorstore.chroma.collection-name=olympus
|
|||||||
spring.servlet.multipart.max-file-size=10MB
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
spring.servlet.multipart.max-request-size=10MB
|
||||||
|
|
||||||
file.upload-dir=C:\\mnt\\hermione_storage\\documents\\file_input_scenarios\\
|
file.upload-dir=/mnt/hermione_storage/documents/file_input_scenarios/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user