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.
Merge pull request #21 from oracle-devrel/add-summary-from-text
add summary from text, add interaction to database for all scenarios,…
- Loading branch information
Showing
15 changed files
with
304 additions
and
83 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
77 changes: 77 additions & 0 deletions
77
...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,77 @@ | ||
package dev.victormartin.oci.genai.backend.backend.controller; | ||
|
||
import com.oracle.bmc.model.BmcException; | ||
import dev.victormartin.oci.genai.backend.backend.dao.Answer; | ||
import dev.victormartin.oci.genai.backend.backend.dao.SummaryRequest; | ||
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.data.InteractionType; | ||
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.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.util.HtmlUtils; | ||
|
||
import java.util.Date; | ||
|
||
@RestController | ||
public class SummaryController { | ||
Logger logger = LoggerFactory.getLogger(SummaryController.class); | ||
|
||
@Value("${genai.summarization_model_id}") | ||
String summarizationModelId; | ||
|
||
@Autowired | ||
OCIGenAIService ociGenAIService; | ||
|
||
@Autowired | ||
private InteractionRepository interactionRepository; | ||
|
||
@PostMapping("/api/genai/summary") | ||
public Answer postSummaryText(@RequestBody SummaryRequest summaryRequest, | ||
@RequestHeader("conversationID") String conversationId, | ||
@RequestHeader("modelId") String modelId) { | ||
logger.info("postSummaryText()"); | ||
String contentEscaped = HtmlUtils.htmlEscape(summaryRequest.content()); | ||
logger.info("contentEscaped: {}...", contentEscaped.substring(0, 50)); | ||
Interaction interaction = new Interaction(); | ||
interaction.setType(InteractionType.SUMMARY_TEXT); | ||
interaction.setConversationId(conversationId); | ||
interaction.setDatetimeRequest(new Date()); | ||
interaction.setModelId(summarizationModelId); | ||
interaction.setRequest(contentEscaped); | ||
Interaction saved = interactionRepository.save(interaction); | ||
try { | ||
String summaryText = ociGenAIService.summaryText(contentEscaped, summarizationModelId); | ||
saved.setDatetimeResponse(new Date()); | ||
saved.setResponse(summaryText); | ||
interactionRepository.save(saved); | ||
logger.info("summaryText: {}...", summaryText.substring(0, 50)); | ||
Answer answer = new Answer(); | ||
answer.setContent(summaryText); | ||
answer.setErrorMessage(""); | ||
return answer; | ||
} catch (BmcException e) { | ||
String unmodifiedMessage = e.getUnmodifiedMessage(); | ||
int statusCode = e.getStatusCode(); | ||
String errorMessage = statusCode + " " + unmodifiedMessage; | ||
logger.error(errorMessage); | ||
saved.setErrorMessage(errorMessage); | ||
interactionRepository.save(saved); | ||
Answer answer = new Answer("", errorMessage); | ||
return answer; | ||
} catch (Exception e) { | ||
String errorMessage = e.getLocalizedMessage(); | ||
logger.error(errorMessage); | ||
saved.setErrorMessage(errorMessage); | ||
interactionRepository.save(saved); | ||
Answer answer = new Answer("", errorMessage); | ||
return answer; | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
backend/src/main/java/dev/victormartin/oci/genai/backend/backend/dao/SummaryRequest.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,4 @@ | ||
package dev.victormartin.oci.genai.backend.backend.dao; | ||
|
||
public record SummaryRequest(String content) { | ||
} |
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
5 changes: 5 additions & 0 deletions
5
backend/src/main/java/dev/victormartin/oci/genai/backend/backend/data/InteractionType.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,5 @@ | ||
package dev.victormartin.oci.genai.backend.backend.data; | ||
|
||
public enum InteractionType { | ||
CHAT, SUMMARY_FILE, SUMMARY_TEXT | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.