Aggiungi supporto per diversi client di chat e modifica la gestione degli endpoint nel solver delle query avanzate
This commit is contained in:
@@ -20,5 +20,6 @@ public class AiModel {
|
|||||||
private String apiKey;
|
private String apiKey;
|
||||||
private boolean isDefault = false;
|
private boolean isDefault = false;
|
||||||
private boolean isCanvasDefault = false;
|
private boolean isCanvasDefault = false;
|
||||||
|
private String full_path_endpoint;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.ai.chat.client.ChatClient.CallResponseSpec;
|
|
||||||
import org.springframework.ai.document.Document;
|
import org.springframework.ai.document.Document;
|
||||||
import org.springframework.ai.vectorstore.SearchRequest;
|
import org.springframework.ai.vectorstore.SearchRequest;
|
||||||
import org.springframework.ai.vectorstore.SearchRequest.Builder;
|
import org.springframework.ai.vectorstore.SearchRequest.Builder;
|
||||||
|
|
||||||
|
import com.olympus.hermione.client.AzureOpenApiChatClient;
|
||||||
|
import com.olympus.hermione.client.GoogleGeminiChatClient;
|
||||||
|
import com.olympus.hermione.client.OlympusChatClient;
|
||||||
|
import com.olympus.hermione.client.OlympusChatClientResponse;
|
||||||
import com.olympus.hermione.models.ScenarioExecution;
|
import com.olympus.hermione.models.ScenarioExecution;
|
||||||
import com.olympus.hermione.utility.AttributeParser;
|
import com.olympus.hermione.utility.AttributeParser;
|
||||||
|
|
||||||
@@ -72,16 +75,17 @@ public class AdvancedQueryRagSolver extends StepSolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(this.step.getAttributes().containsKey("rephrase_prompt")){
|
if(this.step.getAttributes().containsKey("rephrase_prompt")){
|
||||||
this.rephrasePrompt = (String) this.step.getAttributes().get("rephrase_prompt");
|
this.rephrasePrompt = attributeParser.parse((String)this.step.getAttributes().get("rephrase_prompt"));
|
||||||
}else{
|
}else{
|
||||||
this.rephrasePrompt = "Please rewrite the following query to be more efficent in a similarity search context : " + this.query;
|
this.rephrasePrompt = "Please rewrite the following query to be more efficent in a similarity search context : " + this.query;
|
||||||
|
this.rephrasePrompt += "\n\n The output must be a single query and nothing else.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.step.getAttributes().containsKey("multi_phrase_prompt")){
|
if(this.step.getAttributes().containsKey("multi_phrase_prompt")){
|
||||||
this.MultiPhrasePrompt = (String) this.step.getAttributes().get("multi_phrase_prompt");
|
this.MultiPhrasePrompt = attributeParser.parse((String)this.step.getAttributes().get("multi_phrase_prompt"));
|
||||||
}else{
|
}else{
|
||||||
this.MultiPhrasePrompt = "Please rewrite the following query in 3 different way that could be used to perform a similarity search in a RAG scenario: " + this.query;
|
this.MultiPhrasePrompt = "Please rewrite the following query in 3 different way that could be used to perform a similarity search in a RAG scenario: " + this.query;
|
||||||
this.MultiPhrasePrompt += "\n\n The output must be a list of 3 different queries, one per line and nothing else.";
|
this.MultiPhrasePrompt += "\n\n The output must be a list of 3 different queries, one per line and nothing else. Do not put line numbers, just the queries.";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.outputField = (String) this.step.getAttributes().get("rag_output_variable");
|
this.outputField = (String) this.step.getAttributes().get("rag_output_variable");
|
||||||
@@ -109,22 +113,33 @@ public class AdvancedQueryRagSolver extends StepSolver {
|
|||||||
logParameters();
|
logParameters();
|
||||||
String elaboratedQuery = this.query;
|
String elaboratedQuery = this.query;
|
||||||
|
|
||||||
|
OlympusChatClient chatClient = null;
|
||||||
|
|
||||||
|
if ( scenarioExecution.getScenario().getAiModel().getApiProvider().equals("AzureOpenAI")) {
|
||||||
|
chatClient = new AzureOpenApiChatClient();
|
||||||
|
}
|
||||||
|
if ( scenarioExecution.getScenario().getAiModel().getApiProvider().equals("GoogleGemini")) {
|
||||||
|
chatClient = new GoogleGeminiChatClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
chatClient.init(scenarioExecution.getScenario().getAiModel().getFull_path_endpoint(),
|
||||||
|
scenarioExecution.getScenario().getAiModel().getApiKey(),
|
||||||
|
scenarioExecution.getScenario().getAiModel().getMaxTokens());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if( this.enableRephrase ){
|
if( this.enableRephrase ){
|
||||||
|
|
||||||
CallResponseSpec resp = chatClient.prompt()
|
OlympusChatClientResponse resp = chatClient.getChatCompletion(this.rephrasePrompt);
|
||||||
.user(this.rephrasePrompt)
|
elaboratedQuery = resp.getContent();
|
||||||
.call();
|
|
||||||
|
|
||||||
elaboratedQuery = resp.content();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( this.enableMultiPhrase ){
|
if( this.enableMultiPhrase ){
|
||||||
|
|
||||||
CallResponseSpec resp = chatClient.prompt()
|
OlympusChatClientResponse resp = chatClient.getChatCompletion(this.MultiPhrasePrompt);
|
||||||
.user(this.MultiPhrasePrompt)
|
elaboratedQuery = resp.getContent();
|
||||||
.call();
|
|
||||||
|
|
||||||
elaboratedQuery = resp.content();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Document> docs = new ArrayList<Document>();
|
List<Document> docs = new ArrayList<Document>();
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class OlynmpusChatClientSolver extends StepSolver{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
chatClient.init(scenarioExecution.getScenario().getAiModel().getEndpoint(),
|
chatClient.init(scenarioExecution.getScenario().getAiModel().getFull_path_endpoint(),
|
||||||
scenarioExecution.getScenario().getAiModel().getApiKey(),
|
scenarioExecution.getScenario().getAiModel().getApiKey(),
|
||||||
scenarioExecution.getScenario().getAiModel().getMaxTokens());
|
scenarioExecution.getScenario().getAiModel().getMaxTokens());
|
||||||
String userText = this.qai_user_input;
|
String userText = this.qai_user_input;
|
||||||
|
|||||||
Reference in New Issue
Block a user