-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Marcel2511/master
Pull Request for the Result of the "Integrationsseminar"
- Loading branch information
Showing
12 changed files
with
463 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,3 @@ build/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/de/dhbw/woped/process2text/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; | ||
} | ||
} |
77 changes: 70 additions & 7 deletions
77
src/main/java/de/dhbw/woped/process2text/controller/P2TController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/de/dhbw/woped/process2text/model/process/OpenAiApiDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.