Skip to content

Commit

Permalink
Merge pull request #22 from Marcel2511/master
Browse files Browse the repository at this point in the history
Pull Request for the Result of the "Integrationsseminar"
  • Loading branch information
TaminoFischer authored Nov 11, 2024
2 parents cc7810f + d7d3816 commit 9f09674
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '21'
distribution: 'temurin'
settings-path: ${{ github.workspace }}

Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ build/

### VS Code ###
.vscode/

82 changes: 57 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<version>3.3.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>de.dhbw.woped</groupId>
Expand All @@ -16,7 +16,7 @@
<description>WoPed webservice p2t</description>

<properties>
<java.version>11</java.version>
<java.version>21</java.version>
<sonar.organization>woped</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
Expand All @@ -32,6 +32,16 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -42,8 +52,14 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>4.0.0.4121</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -155,6 +171,21 @@
<artifactId>xml-apis</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -172,29 +203,30 @@
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy_nlptools.wordnet.dict</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy todir="${basedir}/target/src/main/resources">
<fileset dir="${basedir}/src/main/resources"
includes="**/*"/>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>copy_nlptools.wordnet.dict</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy todir="${basedir}/target/src/main/resources">
<fileset dir="${basedir}/src/main/resources"
includes="**/*"/>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.22.8</version>
<version>2.43.0</version>
<configuration>
<formats>
<format>
Expand All @@ -218,7 +250,7 @@
<importOrder/>
<removeUnusedImports/>
<googleJavaFormat>
<version>1.8</version>
<version>1.17.0</version>
<style>GOOGLE</style>
<reflowLongStrings>true</reflowLongStrings>
<groupArtifact>com.google.googlejavaformat:google-java-format</groupArtifact>
Expand All @@ -230,12 +262,12 @@
<id>spotless-check</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
32 changes: 32 additions & 0 deletions src/main/java/de/dhbw/woped/process2text/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.dhbw.woped.process2text.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig {

private static final Logger logger = LoggerFactory.getLogger(WebConfig.class);

@Bean
@Primary
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
logger.info("Applying CORS configuration");
registry
.addMapping("/**")
.allowedOrigins("http://localhost:4200", "http://localhost:3000")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,92 @@
package de.dhbw.woped.process2text.controller;

import de.dhbw.woped.process2text.model.process.OpenAiApiDTO;
import de.dhbw.woped.process2text.service.P2TLLMService;
import de.dhbw.woped.process2text.service.P2TService;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

/**
* Controller class to handle HTTP requests related to process-to-text translation. Provides
* endpoints to translate process models into human-readable text.
*/
@CrossOrigin(origins = "http://localhost:4200")
@RestController
@Slf4j
public class P2TController {

Logger logger = LoggerFactory.getLogger(P2TController.class);
private static final Logger logger = LoggerFactory.getLogger(P2TController.class);

@Autowired P2TService p2tService;
@Autowired private P2TService p2tService;
@Autowired private P2TLLMService llmService;

/**
* Endpoint to translate a process model into human-readable text.
*
* @param body The process model in plain text format.
* @return The translated text.
*/
@ApiOperation(value = "Translate a process model into human readable text.")
@PostMapping(value = "/generateText", consumes = "text/plain", produces = "text/plain")
protected String generateText(@RequestBody String body) {
if (logger
.isDebugEnabled()) { // required so that body.replaceAll is only invoked in case the body is
// logged
logger.debug(body.replaceAll("[\n\r\t]", "_"));
if (logger.isDebugEnabled()) {
logger.debug("Received body: " + body.replaceAll("[\n\r\t]", "_"));
}
return p2tService.generateText(body);
String response = p2tService.generateText(body);
logger.debug("Response: " + response);
return response;
}

/**
* Endpoint to translate a process model into human-readable text using OpenAI's Large Language
* Model.
*
* @param body The process model in plain text format.
* @param apiKey The API key for OpenAI.
* @param prompt The prompt to guide the translation.
* @param gptModel The GPT model to be used for translation.
* @return The translated text.
*/
@ApiOperation(
value =
"Translate a process model into human readable text using one of OpenAIs Large Language Models")
@PostMapping(value = "/generateTextLLM", consumes = "text/plain", produces = "text/plain")
protected String generateTextLLM(
@RequestBody String body,
@RequestParam(required = true) String apiKey,
@RequestParam(required = true) String prompt,
@RequestParam(required = true) String gptModel) {
logger.debug(
"Received request with apiKey: {}, prompt: {}, gptModel: {}, body: {}",
apiKey,
prompt,
gptModel,
body.replaceAll("[\n\r\t]", "_"));
OpenAiApiDTO openAiApiDTO = new OpenAiApiDTO(apiKey, gptModel, prompt);
try {
String response = llmService.callLLM(body, openAiApiDTO);
logger.debug("LLM Response: " + response);
return response;
} catch (ResponseStatusException e) {
logger.error("Error processing LLM request", e);
throw e;
}
}

/**
* Endpoint to retrieve the list of available GPT models.
*
* @param apiKey The API key for OpenAI.
* @return A list of model names as strings.
*/
@GetMapping("/gptModels")
public List<String> getGptModels(@RequestParam(required = true) String apiKey) {
return llmService.getGptModels(apiKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.dhbw.woped.process2text.model.process;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/** Data Transfer Object to hold OpenAI API related information. */
@Data
@Setter
@Getter
@AllArgsConstructor
public class OpenAiApiDTO {

private String apiKey;
private String gptModel;
private String prompt;
}
Loading

0 comments on commit 9f09674

Please sign in to comment.