Merge branch 'master' into 'prof_users'
merge master into prof users 1 See merge request olympus_ai/hermione!2
This commit is contained in:
28
azure-pipelines.yml
Normal file
28
azure-pipelines.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
# Maven
|
||||
# Build your Java project and run tests with Apache Maven.
|
||||
# Add steps that analyze code, save build artifacts, deploy, and more:
|
||||
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
|
||||
|
||||
trigger:
|
||||
- master
|
||||
|
||||
pool:
|
||||
vmImage: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- task: DownloadSecureFile@1
|
||||
name: mvnSettings
|
||||
displayName: 'Download Maven settings'
|
||||
inputs:
|
||||
secureFile: 'maven-azuredevops-settings.xml'
|
||||
- task: Maven@3
|
||||
inputs:
|
||||
mavenPomFile: 'pom.xml'
|
||||
goals: 'deploy'
|
||||
options: '-s $(mvnSettings.secureFilePath)'
|
||||
mavenAuthenticateFeed: true
|
||||
publishJUnitResults: true
|
||||
testResultsFiles: '**/TEST-*.xml'
|
||||
javaHomeOption: 'JDKVersion'
|
||||
jdkVersionOption: '1.21'
|
||||
mavenVersionOption: 'Default'
|
||||
23
pom.xml
23
pom.xml
@@ -28,7 +28,8 @@
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>
|
||||
<!--<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>-->
|
||||
<spring-ai.version>1.0.0-M2</spring-ai.version>
|
||||
<spring-cloud.version>2023.0.3</spring-cloud.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
@@ -49,6 +50,10 @@
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-azure-openai</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.neo4j.driver</groupId>
|
||||
<artifactId>neo4j-java-driver</artifactId>
|
||||
@@ -97,7 +102,11 @@
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>ST4</artifactId>
|
||||
@@ -157,6 +166,16 @@
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>olympus-artifact</id>
|
||||
<url>https://pkgs.dev.azure.com/andreaterzani/0c74b81e-5138-49d7-89fd-d1154707a917/_packaging/olympus-artifact/maven/v1</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.olympus.hermione.configurations;
|
||||
|
||||
import org.springframework.ai.azure.openai.AzureOpenAiEmbeddingModel;
|
||||
import org.springframework.ai.embedding.EmbeddingModel;
|
||||
import org.springframework.ai.openai.OpenAiEmbeddingModel;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class HermioneConfig {
|
||||
|
||||
private final OpenAiEmbeddingModel myServiceLib1;
|
||||
private final AzureOpenAiEmbeddingModel myServiceLib2;
|
||||
|
||||
// Autowiring beans from both libraries
|
||||
public HermioneConfig(OpenAiEmbeddingModel myServiceLib1, AzureOpenAiEmbeddingModel myServiceLib2) {
|
||||
this.myServiceLib1 = myServiceLib1;
|
||||
this.myServiceLib2 = myServiceLib2;
|
||||
}
|
||||
|
||||
// Re-declaring and marking one as primary
|
||||
@Bean
|
||||
@Primary
|
||||
public EmbeddingModel primaryMyService() {
|
||||
return myServiceLib1; // Choose the one you want as primary
|
||||
}
|
||||
|
||||
// Optionally declare the other bean without primary
|
||||
@Bean
|
||||
public EmbeddingModel secondaryMyService() {
|
||||
return myServiceLib2; // The other one
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,21 @@
|
||||
package com.olympus.hermione.controllers;
|
||||
|
||||
import com.olympus.dto.ClassDetailedInfo;
|
||||
import com.olympus.dto.FileSimpleInfo;
|
||||
import com.olympus.dto.FileSimpleInfoRequest;
|
||||
import com.olympus.dto.MethodDetailedInfo;
|
||||
import com.olympus.dto.TreeNode;
|
||||
import com.olympus.feign.SourceCodeModule;
|
||||
import com.olympus.hermione.services.SourceCodeService;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@@ -16,10 +26,25 @@ public class ApplicationBrowserController {
|
||||
@Autowired
|
||||
private SourceCodeModule sourceCodeModule;
|
||||
|
||||
|
||||
@GetMapping("/source-viewer/getApplicationTreeNode")
|
||||
public TreeNode getApplicationNode(@RequestParam() String applicationName){
|
||||
return sourceCodeModule.getTreeFromNode(applicationName,"application");
|
||||
}
|
||||
|
||||
@GetMapping("/source-module/getClassDetailedInfo")
|
||||
public ClassDetailedInfo getClassDetailedInfo(@RequestParam() String className){
|
||||
return sourceCodeModule.getClassDetailedInfo(className);
|
||||
}
|
||||
|
||||
@GetMapping("/source-module/getMethodDetailedInfo")
|
||||
public MethodDetailedInfo getMethodDetailedInfo(@RequestParam() String methodName){
|
||||
return sourceCodeModule.getMethodDetailedInfo(methodName);
|
||||
}
|
||||
|
||||
@PostMapping("/source-module/getFileSimpleInfo")
|
||||
public FileSimpleInfo getFileSimpleInfo(@RequestBody FileSimpleInfoRequest fileinfo){
|
||||
return sourceCodeModule.getFileSimpleInfo(fileinfo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
23
src/main/java/com/olympus/hermione/models/AiModel.java
Normal file
23
src/main/java/com/olympus/hermione/models/AiModel.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.olympus.hermione.models;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Document(collection = "chat_model")
|
||||
@Getter @Setter
|
||||
public class AiModel {
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
private String endpoint;
|
||||
private String apiProvider;
|
||||
private String model;
|
||||
private Float temperature;
|
||||
private Integer maxTokens;
|
||||
private String apiKey;
|
||||
private boolean isDefault = false;
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public class Scenario {
|
||||
private String startWithStepId;
|
||||
private List<ScenarioStep> steps;
|
||||
private List<ScenarioInputs> inputs;
|
||||
private String modelId;
|
||||
@DocumentReference
|
||||
private List<Project> availableForProjects;
|
||||
@DocumentReference
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.olympus.hermione.repository;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import com.olympus.hermione.models.AiModel;
|
||||
|
||||
@Repository
|
||||
public interface AiModelRepository extends MongoRepository<AiModel, String>{
|
||||
Optional <AiModel> findByIsDefault(Boolean isDefault);
|
||||
}
|
||||
@@ -8,13 +8,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Configuration
|
||||
public class CorsConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${ariadne.fe.url}")
|
||||
private String ariadne_frontend_url;
|
||||
@Value("${hermione.fe.url}")
|
||||
private String hermione_frontend_url;
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins(ariadne_frontend_url)
|
||||
.allowedOrigins(hermione_frontend_url)
|
||||
.allowedHeaders("*")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE","OPTIONS");
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ 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.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.olympus.hermione.dto.CanvasExecutionInput;
|
||||
@@ -20,8 +21,13 @@ import com.olympus.hermione.dto.CanvasOutput;
|
||||
@Service
|
||||
public class CanvasExecutionService {
|
||||
|
||||
|
||||
private final ChatModel chatModel;
|
||||
|
||||
@Autowired
|
||||
ChatModel chatModel;
|
||||
public CanvasExecutionService(@Qualifier("openAiChatModel") ChatModel chatModel) {
|
||||
this.chatModel = chatModel;
|
||||
}
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(CanvasExecutionService.class);
|
||||
|
||||
|
||||
@@ -5,13 +5,17 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.azure.openai.AzureOpenAiChatModel;
|
||||
import org.springframework.ai.azure.openai.AzureOpenAiChatOptions;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
||||
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
|
||||
import org.springframework.ai.chat.memory.ChatMemory;
|
||||
import org.springframework.ai.chat.memory.InMemoryChatMemory;
|
||||
import org.springframework.ai.chat.model.ChatModel;
|
||||
|
||||
import org.springframework.ai.openai.OpenAiChatModel;
|
||||
import org.springframework.ai.openai.OpenAiChatOptions;
|
||||
import org.springframework.ai.openai.api.OpenAiApi;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
@@ -20,9 +24,11 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import com.olympus.hermione.dto.ScenarioExecutionInput;
|
||||
import com.olympus.hermione.dto.ScenarioOutput;
|
||||
import com.olympus.hermione.models.AiModel;
|
||||
import com.olympus.hermione.models.Scenario;
|
||||
import com.olympus.hermione.models.ScenarioExecution;
|
||||
import com.olympus.hermione.models.ScenarioStep;
|
||||
import com.olympus.hermione.repository.AiModelRepository;
|
||||
import com.olympus.hermione.repository.ScenarioExecutionRepository;
|
||||
import com.olympus.hermione.repository.ScenarioRepository;
|
||||
import com.olympus.hermione.stepSolvers.AdvancedAIPromptSolver;
|
||||
@@ -35,6 +41,13 @@ import com.olympus.hermione.stepSolvers.StepSolver;
|
||||
import org.neo4j.driver.Driver;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.azure.ai.openai.OpenAIClient;
|
||||
import com.azure.ai.openai.OpenAIClientBuilder;
|
||||
import com.azure.core.credential.AzureKeyCredential;
|
||||
|
||||
|
||||
|
||||
|
||||
@Service
|
||||
public class ScenarioExecutionService {
|
||||
|
||||
@@ -44,14 +57,17 @@ public class ScenarioExecutionService {
|
||||
@Autowired
|
||||
private ScenarioExecutionRepository scenarioExecutionRepository;
|
||||
|
||||
@Autowired
|
||||
private AiModelRepository aiModelRepository;
|
||||
|
||||
@Autowired
|
||||
VectorStore vectorStore;
|
||||
|
||||
@Autowired
|
||||
DiscoveryClient discoveryClient;
|
||||
|
||||
@Autowired
|
||||
ChatModel chatModel;
|
||||
//@Autowired
|
||||
//ChatModel chatModel;
|
||||
|
||||
@Autowired
|
||||
Driver graphDriver;
|
||||
@@ -60,7 +76,7 @@ public class ScenarioExecutionService {
|
||||
Neo4JUitilityService neo4JUitilityService;
|
||||
|
||||
private ChatClient chatClient;
|
||||
|
||||
private ChatModel chatModel;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ScenarioExecutionService.class);
|
||||
|
||||
@@ -111,7 +127,15 @@ public class ScenarioExecutionService {
|
||||
scenarioExecution.setExecSharedMap(execSharedMap);
|
||||
scenarioExecutionRepository.save(scenarioExecution);
|
||||
|
||||
//TODO: Chatmodel should be initialized with the scenario specific infos
|
||||
//TODO: should be initialized with the scenario specific infos
|
||||
Optional<AiModel> o_aiModel;
|
||||
if(scenario.getModelId() != null){
|
||||
o_aiModel = aiModelRepository.findById(scenario.getModelId());
|
||||
}else {
|
||||
o_aiModel = aiModelRepository.findByIsDefault(true);
|
||||
}
|
||||
AiModel aiModel = o_aiModel.get();
|
||||
ChatModel chatModel = createChatModel(aiModel);
|
||||
|
||||
if(scenario.isUseChatMemory()){
|
||||
logger.info("Initializing chatClient with chat-memory advisor");
|
||||
@@ -225,4 +249,39 @@ public class ScenarioExecutionService {
|
||||
return scenarioOutput;
|
||||
}
|
||||
|
||||
|
||||
private ChatModel createChatModel(AiModel aiModel){
|
||||
switch(aiModel.getApiProvider()){
|
||||
case "AzureOpenAI":
|
||||
OpenAIClient openAIClient = new OpenAIClientBuilder()
|
||||
.credential(new AzureKeyCredential(aiModel.getApiKey()))
|
||||
.endpoint(aiModel.getEndpoint())
|
||||
.buildClient();
|
||||
AzureOpenAiChatOptions openAIChatOptions = AzureOpenAiChatOptions.builder()
|
||||
.withDeploymentName(aiModel.getModel())
|
||||
.withTemperature(aiModel.getTemperature())
|
||||
.withMaxTokens(aiModel.getMaxTokens())
|
||||
.build();
|
||||
|
||||
AzureOpenAiChatModel azureOpenaichatModel = new AzureOpenAiChatModel(openAIClient, openAIChatOptions);
|
||||
logger.info("AI model used: " + aiModel.getModel());
|
||||
return azureOpenaichatModel;
|
||||
|
||||
case "OpenAI":
|
||||
OpenAiApi openAiApi = new OpenAiApi(aiModel.getApiKey());
|
||||
OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder()
|
||||
.withModel(aiModel.getModel())
|
||||
.withTemperature(aiModel.getTemperature())
|
||||
.withMaxTokens(aiModel.getMaxTokens())
|
||||
.build();
|
||||
|
||||
OpenAiChatModel openaichatModel = new OpenAiChatModel(openAiApi,openAiChatOptions);
|
||||
logger.info("AI model used: " + aiModel.getModel());
|
||||
return openaichatModel;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported AI model: " + aiModel.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ spring.ai.openai.api-key=sk-proj-j3TFJ0h348DIzMrYYfyUT3BlbkFJjk4HMc8A2ux2Asg8Y7H
|
||||
spring.ai.openai.chat.options.model=gpt-4o-mini
|
||||
spring.main.allow-circular-references=true
|
||||
|
||||
spring.ai.azure.openai.api-key=YOUR_API_KEY
|
||||
spring.ai.azure.openai.endpoint=YOUR_ENDPOINT
|
||||
spring.ai.azure.openai.chat.options.deployment-name=gpt-4o
|
||||
spring.ai.azure.openai.chat.options.temperature=0.7
|
||||
|
||||
neo4j.uri=neo4j+s://e17e6f08.databases.neo4j.io:7687
|
||||
neo4j.username=neo4j
|
||||
neo4j.password=8SrSqQ3q6q9PQNWtN9ozqSQfGce4lfh_n6kKz2JIubQ
|
||||
@@ -28,5 +33,6 @@ logging.level.org.springframework.ai.chat.client.advisor=DEBUG
|
||||
eureka.client.serviceUrl.defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
|
||||
eureka.instance.preferIpAddress: true
|
||||
|
||||
hermione.fe.url = *
|
||||
ariadne.fe.url = *
|
||||
hermione.fe.url =
|
||||
|
||||
java-parser-module.url: http://java-parser-module-service.olympus.svc.cluster.local:8080
|
||||
Reference in New Issue
Block a user