generated from oracle-devrel/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
532 additions
and
159 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
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
2 changes: 1 addition & 1 deletion
2
...kend/backend/ClientConfigurationBean.java → ...ckend/config/ClientConfigurationBean.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
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
2 changes: 1 addition & 1 deletion
2
...enai/backend/backend/WebSocketConfig.java → ...ckend/backend/config/WebSocketConfig.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
4 changes: 1 addition & 3 deletions
4
...enai/backend/backend/GenAIController.java → ...d/backend/controller/GenAIController.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
66 changes: 66 additions & 0 deletions
66
...in/java/dev/victormartin/oci/genai/backend/backend/controller/PDFConvertorController.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,66 @@ | ||
package dev.victormartin.oci.genai.backend.backend.controller; | ||
|
||
|
||
import dev.victormartin.oci.genai.backend.backend.service.OCIGenAIService; | ||
import dev.victormartin.oci.genai.backend.backend.service.PDFConvertorService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MaxUploadSizeExceededException; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.File; | ||
|
||
@RestController | ||
public class PDFConvertorController { | ||
Logger log = LoggerFactory.getLogger(PDFConvertorController.class); | ||
|
||
@Value("${storage.path}") | ||
String storagePath; | ||
|
||
@Value("${genai.summarization_model_id}") | ||
String summarizationModelId; | ||
|
||
@Autowired | ||
OCIGenAIService ociGenAIService; | ||
|
||
@Autowired | ||
PDFConvertorService pdfConvertorService; | ||
|
||
@Autowired | ||
SummaryController summaryController; | ||
|
||
@PostMapping("/api/upload") | ||
public String fileUploading(@RequestParam("file") MultipartFile multipartFile) { | ||
String filename = StringUtils.cleanPath(multipartFile.getOriginalFilename()); | ||
log.info("File uploaded {} {} bytes ({})", filename, multipartFile.getSize(), multipartFile.getContentType()); | ||
try { | ||
if (filename.contains("..")) { | ||
throw new Exception("Filename contains invalid path sequence"); | ||
} | ||
if (multipartFile.getBytes().length > (1024 * 1024)) { | ||
throw new Exception("File size exceeds maximum limit"); | ||
} | ||
String fileDestinationPath = StringUtils.cleanPath(storagePath); | ||
File file = new File(fileDestinationPath + File.separator + filename); | ||
multipartFile.transferTo(file); | ||
log.info("File destination path: {}", file.getAbsolutePath()); | ||
String convertedText = pdfConvertorService.convert(file.getAbsolutePath()); | ||
String summaryText = ociGenAIService.summaryText(convertedText, summarizationModelId); | ||
log.info("Summary text: {}(...)", summaryText.substring(0, 40)); | ||
summaryController.handleSummary(summaryText); | ||
return summaryText; | ||
} catch (MaxUploadSizeExceededException maxUploadSizeExceededException) { | ||
log.error(maxUploadSizeExceededException.getMessage()); | ||
throw new RuntimeException(maxUploadSizeExceededException); | ||
} catch (Exception e) { | ||
log.error(e.getMessage()); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
...rc/main/java/dev/victormartin/oci/genai/backend/backend/controller/SummaryController.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,33 @@ | ||
package dev.victormartin.oci.genai.backend.backend.controller; | ||
|
||
import com.oracle.bmc.model.BmcException; | ||
import dev.victormartin.oci.genai.backend.backend.InvalidPromptRequest; | ||
import dev.victormartin.oci.genai.backend.backend.dao.Answer; | ||
import dev.victormartin.oci.genai.backend.backend.dao.Prompt; | ||
import dev.victormartin.oci.genai.backend.backend.data.Interaction; | ||
import dev.victormartin.oci.genai.backend.backend.data.InteractionRepository; | ||
import dev.victormartin.oci.genai.backend.backend.service.OCIGenAIService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.simp.annotation.SendToUser; | ||
import org.springframework.messaging.simp.annotation.SubscribeMapping; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.util.HtmlUtils; | ||
|
||
import java.util.Date; | ||
|
||
@Controller | ||
public class SummaryController { | ||
Logger logger = LoggerFactory.getLogger(SummaryController.class); | ||
|
||
@SendToUser("/queue/summary") | ||
public Answer handleSummary(String summary) { | ||
logger.info("handleSummary"); | ||
return new Answer(summary , ""); | ||
} | ||
|
||
} |
Oops, something went wrong.