Skip to content

Commit

Permalink
Merge pull request #19 from oracle-devrel/fix-summarization
Browse files Browse the repository at this point in the history
Fix summarization
  • Loading branch information
WSPluta authored Jun 27, 2024
2 parents 7bc583d + 82d2136 commit 945a851
Show file tree
Hide file tree
Showing 28 changed files with 354 additions and 291 deletions.
27 changes: 19 additions & 8 deletions K8S.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ npx zx scripts/kustom.mjs
### Kubernetes Deployment

```bash
export KUBECONFIG="deploy/terraform/generated/kubeconfig"
export KUBECONFIG="$(pwd)/deploy/terraform/generated/kubeconfig"
```

```bash
Expand All @@ -129,28 +129,39 @@ kubectl apply -k deploy/k8s/overlays/prod
Run `get deploy` a few times:

```bash
kubectl get deploy
kubectl get deploy -n backend
```

Wait for all deployments to be `Ready` and `Available`.

```
NAME READY UP-TO-DATE AVAILABLE AGE
backend 1/1 1 1 3m28s
web 1/1 1 1 3m21s
NAME READY UP-TO-DATE AVAILABLE AGE
backend 1/1 1 1 3m28s
ingress-nginx-controller 1/1 1 1 3m17s
web 1/1 1 1 3m21s
```

Access your application:

```bash
echo $(kubectl get service \
-n ingress-nginx \
-n backend \
-o jsonpath='{.items[?(@.spec.type=="LoadBalancer")].status.loadBalancer.ingress[0].ip}')
```

> This command will list the services on the `ingress-nginx` namespace and filter for the Load Balancer. If the response is an empty string, wait a bit and execute the command again. The Load Balancer takes a bit of time to create the Public IP address.
> This command will list the Load Balancer services on the `backend` namespace. If the response is an empty string, wait a bit and execute the command again. The Load Balancer takes a bit of time to create the Public IP address.
Take the Public IP to your browser.
Paste the Public IP address on your browser and test your new Generative AI website deployed in Kubernetes.

Remember to visit SQL Developer Web on the OCI Console for your Oracle Database and run some queries to investigate the historical of prompts.

```sql
SELECT * FROM interactions;
```

```bash
cd ../..
```

## Clean up

Expand Down
2 changes: 1 addition & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'dev.victormartin.oci.genai.backend'
version = '0.0.3'
version = '0.0.5'

java {
sourceCompatibility = '17'
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.oracle.bmc.generativeai.requests.ListModelsRequest;
import com.oracle.bmc.generativeai.responses.ListModelsResponse;
import dev.victormartin.oci.genai.backend.backend.dao.GenAiModel;
import dev.victormartin.oci.genai.backend.backend.service.GenerativeAiClientService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -23,17 +24,14 @@ public class GenAIController {
private String COMPARTMENT_ID;

@Autowired
private GenerativeAiClient generativeAiClient;

// repository

// constructor
private GenerativeAiClientService generativeAiClientService;

@GetMapping("/api/genai/models")
public List<GenAiModel> getModels() {
logger.info("getModels()");
ListModelsRequest listModelsRequest = ListModelsRequest.builder().compartmentId(COMPARTMENT_ID).build();
ListModelsResponse response = generativeAiClient.listModels(listModelsRequest);
GenerativeAiClient client = generativeAiClientService.getClient();
ListModelsResponse response = client.listModels(listModelsRequest);
return response.getModelCollection().getItems().stream().map(m -> {
List<String> capabilities = m.getCapabilities().stream().map(ModelCapability::getValue).collect(Collectors.toList());
GenAiModel model = new GenAiModel(m.getId(),m.getDisplayName(), m.getVendor(), m.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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.service.OCIGenAIService;
import dev.victormartin.oci.genai.backend.backend.service.PDFConvertorService;
import org.slf4j.Logger;
Expand Down Expand Up @@ -32,11 +34,8 @@ public class PDFConvertorController {
@Autowired
PDFConvertorService pdfConvertorService;

@Autowired
SummaryController summaryController;

@PostMapping("/api/upload")
public String fileUploading(@RequestParam("file") MultipartFile multipartFile) {
public Answer fileUploading(@RequestParam("file") MultipartFile multipartFile) {
String filename = StringUtils.cleanPath(multipartFile.getOriginalFilename());
log.info("File uploaded {} {} bytes ({})", filename, multipartFile.getSize(), multipartFile.getContentType());
try {
Expand All @@ -53,14 +52,27 @@ public String fileUploading(@RequestParam("file") MultipartFile multipartFile) {
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;
Answer answer = new Answer(summaryText, "");
return answer;
} catch (MaxUploadSizeExceededException maxUploadSizeExceededException) {
log.error(maxUploadSizeExceededException.getMessage());
throw new RuntimeException(maxUploadSizeExceededException);
} catch (BmcException exception) {
log.error("Message: {}", exception.getMessage());
log.error("Original Message: {}", exception.getOriginalMessage());
log.error("Unmodified Message: {}", exception.getUnmodifiedMessage());
log.error("Service Details: {}", exception.getServiceDetails());
log.error("Status Code: {}", exception.getStatusCode());
String unmodifiedMessage = exception.getUnmodifiedMessage();
int statusCode = exception.getStatusCode();
String errorMessage = statusCode + " " + unmodifiedMessage;
log.error(errorMessage);
Answer answer = new Answer("", errorMessage);
return answer;
} catch (Exception e) {
log.error(e.getMessage());
throw new RuntimeException(e);
Answer answer = new Answer("", e.getMessage());
return answer;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class PromptController {
@Value("${genai.chat_model_id}")
private String hardcodedChatModelId;

@Value("${genai.summarization_model_id}")
private String hardcodedSummarizationModelId;

@Autowired
private final InteractionRepository interactionRepository;

Expand All @@ -53,19 +50,23 @@ public Answer handlePrompt(Prompt prompt) {
interaction.setRequest(promptEscaped);
Interaction saved = interactionRepository.save(interaction);
try {
if (prompt.content() == null || prompt.content().length() < 1) {
if (prompt.content().isEmpty()) {
throw new InvalidPromptRequest();
}
// if (prompt.modelId() == null ||
// !prompt.modelId().startsWith("ocid1.generativeaimodel.")) { throw new
// InvalidPromptRequest(); }
String responseFromGenAI = genAI.request(promptEscaped, hardcodedChatModelId);
String responseFromGenAI = genAI.resolvePrompt(promptEscaped, hardcodedChatModelId);
saved.setDatetimeResponse(new Date());
saved.setResponse(responseFromGenAI);
interactionRepository.save(saved);
return new Answer(responseFromGenAI, "");
} catch (BmcException exception) {
logger.error(exception.getOriginalMessage());
logger.error("Message: {}", exception.getMessage());
logger.error("Original Message: {}", exception.getOriginalMessage());
logger.error("Unmodified Message: {}", exception.getUnmodifiedMessage());
logger.error("Service Details: {}", exception.getServiceDetails());
logger.error("Status Code: {}", exception.getStatusCode());
String unmodifiedMessage = exception.getUnmodifiedMessage();
int statusCode = exception.getStatusCode();
String errorMessage = statusCode + " " + unmodifiedMessage;
Expand Down
Loading

0 comments on commit 945a851

Please sign in to comment.