Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to docker file and filtering of models in client #29

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM --platform=linux/amd64 node:18-slim AS builder

WORKDIR /usr/src/app

RUN mkdir -p ./src \
&& mkdir -p ./scripts \
&& mkdir -p ./staged-themes
RUN mkdir -p ./src
RUN mkdir -p ./scripts
RUN mkdir -p ./staged-themes

COPY src/ ./src/
COPY staged-themes/ ./staged-themes
Expand All @@ -18,8 +17,8 @@ RUN npm install
RUN ojet build web --release

FROM --platform=linux/amd64 nginx:1.23-alpine-slim

COPY --from=builder /usr/src/app/web/* /usr/share/nginx/html/
RUN rm -rf /usr/share/nginx/html/*
COPY --from=builder /usr/src/app/web/ /usr/share/nginx/html/

EXPOSE 80

Expand Down
42 changes: 38 additions & 4 deletions app/src/components/content/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ComponentProps } from "preact";
import { useEffect, useRef } from "preact/hooks";
import "oj-c/radioset";
import "oj-c/form-layout";
import "oj-c/select-single";
import { CRadiosetElement } from "oj-c/radioset";
import "ojs/ojlistitemlayout";
import "ojs/ojhighlighttext";
import MutableArrayDataProvider = require("ojs/ojmutablearraydataprovider");

type ServiceTypeVal = "text" | "summary" | "sim";
Expand Down Expand Up @@ -60,7 +60,16 @@ export const Settings = (props: Props) => {
throw new Error(`Response status: ${response.status}`);
}
const json = await response.json();
modelDP.current.data = json;
const result = json.filter((model: any) => {
if (
// model.capabilities.includes("FINE_TUNE") &&
model.capabilities.includes("TEXT_GENERATION") &&
model.vendor == "cohere" &&
model.version > 15
)
return model;
});
modelDP.current.data = result;
} catch (error: any) {
console.log(
"Java service not available for fetching list of Models: ",
Expand All @@ -72,6 +81,29 @@ export const Settings = (props: Props) => {
useEffect(() => {
fetchModels();
}, []);

const modelTemplate = (item: any) => {
return (
<oj-list-item-layout class="oj-listitemlayout-padding-off">
<span class="oj-typography-body-md oj-text-color-primary">
<oj-highlight-text
text={item.item.data.name}
match-text={item.searchText}
></oj-highlight-text>
</span>
<span
slot="secondary"
class="oj-typography-body-sm oj-text-color-secondary"
>
<oj-highlight-text
text={JSON.stringify(item.item.data.capabilities)}
match-text={item.searchText}
></oj-highlight-text>
</span>
</oj-list-item-layout>
);
};

return (
<div class="oj-sm-margin-4x">
<h2 class="oj-typography-heading-sm">AI service types</h2>
Expand Down Expand Up @@ -103,7 +135,9 @@ export const Settings = (props: Props) => {
labelHint={"Model"}
itemText={"name"}
onvalueChanged={props.modelIdChange}
></oj-c-select-single>
>
<template slot="itemTemplate" render={modelTemplate}></template>
</oj-c-select-single>
</oj-c-form-layout>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
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.data.InteractionType;
import dev.victormartin.oci.genai.backend.backend.service.OCIGenAIService;
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 java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -18,72 +12,83 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.util.HtmlUtils;

import java.util.Date;
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.data.InteractionType;
import dev.victormartin.oci.genai.backend.backend.service.OCIGenAIService;

@Controller
public class PromptController {
Logger logger = LoggerFactory.getLogger(PromptController.class);

@Value("${genai.chat_model_id}")
private String hardcodedChatModelId;
Logger logger = LoggerFactory.getLogger(PromptController.class);

@Value("${genai.chat_model_id}")
private String hardcodedChatModelId;

@Autowired
private final InteractionRepository interactionRepository;
@Autowired
private final InteractionRepository interactionRepository;

@Autowired
@Autowired
OCIGenAIService genAI;

public PromptController(InteractionRepository interactionRepository, OCIGenAIService genAI) {
this.interactionRepository = interactionRepository;
this.genAI = genAI;
}
public PromptController(InteractionRepository interactionRepository, OCIGenAIService genAI) {
this.interactionRepository = interactionRepository;
this.genAI = genAI;
}

@MessageMapping("/prompt")
@SendToUser("/queue/answer")
public Answer handlePrompt(Prompt prompt) {
String promptEscaped = HtmlUtils.htmlEscape(prompt.content());
String activeModel = (prompt.modelId() == null) ? hardcodedChatModelId : prompt.modelId();
logger.info("Prompt " + promptEscaped + " received, on model " + activeModel);

Interaction interaction = new Interaction();
interaction.setType(InteractionType.CHAT);
interaction.setConversationId(prompt.conversationId());
interaction.setDatetimeRequest(new Date());
interaction.setModelId(activeModel);
interaction.setRequest(promptEscaped);
Interaction saved = interactionRepository.save(interaction);
try {
if (prompt.content().isEmpty()) {
throw new InvalidPromptRequest();
}
// if (prompt.modelId() == null ||
// !prompt.modelId().startsWith("ocid1.generativeaimodel.")) { throw new
// InvalidPromptRequest(); }
saved.setDatetimeResponse(new Date());
String responseFromGenAI = genAI.resolvePrompt(promptEscaped, activeModel);
saved.setResponse(responseFromGenAI);
interactionRepository.save(saved);
return new Answer(responseFromGenAI, "");

@MessageMapping("/prompt")
@SendToUser("/queue/answer")
public Answer handlePrompt(Prompt prompt) {
String promptEscaped = HtmlUtils.htmlEscape(prompt.content());
logger.info("Prompt " + promptEscaped + " received, on model " + prompt.modelId() + " but using hardcoded one" +
" " + hardcodedChatModelId);
Interaction interaction = new Interaction();
interaction.setType(InteractionType.CHAT);
interaction.setConversationId(prompt.conversationId());
interaction.setDatetimeRequest(new Date());
interaction.setModelId(hardcodedChatModelId);
interaction.setRequest(promptEscaped);
Interaction saved = interactionRepository.save(interaction);
try {
if (prompt.content().isEmpty()) {
throw new InvalidPromptRequest();
}
// if (prompt.modelId() == null ||
// !prompt.modelId().startsWith("ocid1.generativeaimodel.")) { throw new
// InvalidPromptRequest(); }
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("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;
logger.error(errorMessage);
saved.setErrorMessage(errorMessage);
interactionRepository.save(saved);
return new Answer("", errorMessage);
} catch (InvalidPromptRequest exception) {
int statusCode = HttpStatus.BAD_REQUEST.value();
String errorMessage = statusCode + " Invalid Prompt ";
logger.error(errorMessage);
saved.setErrorMessage(errorMessage);
interactionRepository.save(saved);
return new Answer("", errorMessage);
}
}
} catch (BmcException exception) {
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;
logger.error(errorMessage);
saved.setErrorMessage(errorMessage);
interactionRepository.save(saved);
return new Answer("", errorMessage);
} catch (InvalidPromptRequest exception) {
int statusCode = HttpStatus.BAD_REQUEST.value();
String errorMessage = statusCode + " Invalid Prompt ";
logger.error(errorMessage);
saved.setErrorMessage(errorMessage);
interactionRepository.save(saved);
return new Answer("", errorMessage);
}
}

}