diff --git a/.assets/CheckstyleReportExample.png b/.assets/CheckstyleReportExample.png new file mode 100644 index 0000000..c8ebb9d Binary files /dev/null and b/.assets/CheckstyleReportExample.png differ diff --git a/.github/workflows/ci.yaml b/.github/workflows/build-and-push.yaml similarity index 100% rename from .github/workflows/ci.yaml rename to .github/workflows/build-and-push.yaml diff --git a/.github/workflows/reporting.yaml b/.github/workflows/reporting.yaml new file mode 100644 index 0000000..12b1fa1 --- /dev/null +++ b/.github/workflows/reporting.yaml @@ -0,0 +1,46 @@ +name: Publish Report + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + publish_report: + permissions: write-all + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 21 + uses: actions/setup-java@v2 + with: + java-version: '21' + distribution: 'adopt' + + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + + - name: Build and generate report + run: | + mvn -B site + + - name: Push Checkstyle results + uses: jwgmeligmeyling/checkstyle-github-action@master + with: + path: '**/checkstyle-result.xml' + + - name: Publish report + uses: actions/upload-artifact@v4 + with: + name: Upload Report + path: target/site \ No newline at end of file diff --git a/README.md b/README.md index 6acdeaf..ffc8d14 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,29 @@ # Quarkus LLM Routing Service -Quarkus Service that allows for the routing to different RAG sources and LLMs +Quarkus Service that allows for the routing to different RAG sources and LLMs. ## Architecture ![](.assets/Routing%20Service.drawio.png) -### Chat Bot Message Architecture +### Components -The `assistant/chat/streaming` will be the main use endpoint. In which we specify the a message to our chat and the name of an assistant. +* **Assistants** - An assistant is the top level component that describes how all the components below are connected. +* **Content Retrievers**- Content Retrievers is the RAG(Retrieval-Augmented Generation) connection info used to retrieve data that will be included in the message to the LLM + * **Embedding Models**- These are generally the model used to convert data that is stored/retrieved from a vector database, which is a common pattern for RAG Datasources +* **LLMs**- The connection information to the Runtime Serving Environment hosting the Large Language Model +* **AI Services** - The component orchestrating the calls to the Content Retrievers and LLMs +> [!NOTE] +> Currently working on finding a less restrictive way than `AI Services` in which to perform the orchestration of our calls + +## Chat Bot Endpoints + +### Assistant + +The `assistant/chat/streaming` is the primary entrypoint into the application. This used to specify an assistant + +**Example Message** ```json { "message": "User Message", @@ -17,95 +31,183 @@ The `assistant/chat/streaming` will be the main use endpoint. In which we specif } ``` -Available Assistants by default: -- default_ocp -- default_rhel -- default_rho_2025_faq -- default_ansible -- default_rhoai +#### Default Assistants +The following assistants are loaded into the application by default using liquibase and [changeLog File](src/main/resources/db/changeLog.yml): -The `/chatbot/chat/stream` allows for connections to be specified directly through the UI +| Assistant Name | Description | +|---------------------------|--------------------------------------------------| +| default_ocp | Default assistant for OpenShift Container Platform (OCP) | +| default_rhel | Default assistant for Red Hat Enterprise Linux (RHEL) | +| default_rho_2025_faq | Default assistant for RHO 2025 FAQ | +| default_ansible | Default assistant for Ansible automation | +| default_rhoai | Default assistant for RHO AI | +| default_assistant | General default assistant | + +### Direct Chat + +The `/chatbot/chat/stream` endpoint allows for connections to be specified directly, and can be used for initial testing of connections. ```json - { - message: "User Message", - context: "Message history", - retriverRequest: { - index: "weveIndex", - scheme: "weveSchem", - host: "weavHost.com", - apiKey: "xxx", - } - modelRequest { - modelType: "servingRuntime", - apiKey: "xxxxx", - modelName: "mistral-instruct", - } +{ + "message": "User Message", + "context": "Message history", + "retriverRequest": { + "index": "weveIndex", + "scheme": "weveScheme", + "host": "weavHost.com", + "apiKey": "xxx" + }, + "modelRequest": { + "modelType": "servingRuntime", + "apiKey": "xxxxx", + "modelName": "mistral-instruct" } +} ``` -## Assistant Workflow +## Local Development -The main workflow will be through assistants. These will be created by administrators and once created can be accessed by users. +Use the following commands to run locally: -```json - { - message: "User Message", - context: "Message history", - assistantName: "Name of Assistant", - assistantId: "Id of Assistant" // Ignored in name is provided - } +```sh +mvn clean install +# Setting the profile to to use the `application-local.properties` as explained below +mvn quarkus:dev -Dquarkus.profile=local ``` +> [!TIP] +> Recommended that properties below are set in the `application-local.properties` file which is get ignored. This will prevent any accidental check-ins of secret information -> Important: This is assuming access to a default weaviate db with the correct indexes populated. +### LLM Connection -Test Curl Command: -```json -curl -X 'POST' 'http://localhost:8080/assistant/chat/streaming' -H 'Content-Type: application/json' -d '{ - "message": "What is this product?", - "assistantName": "default_rhoai" -}' -N +The following properties should be set in order to connect to properly connect to your LLM running on an OpenAI instance: +```properties +openai.default.url=/v1 +openai.default.apiKey= # If Required +openai.default.modelName= ``` -## Install Locally +> [!TIP] +> The `default_assistant` can be used without having to configure a rag data source + +### Weaviate Setup -To install locally run: +The default assistants all assume a connection to a Weaviate DB for RAG purposes. + +A locally hosted Weaviate can be deployed and used, more information found [here(TBD)](documentation/WEAVIATE_SETUP.md) + +If a remote instance of weaviate exist on an OpenShift cluster and has the correct indexes, that instance can be used with the following port forward commands: ```sh -mvn clean install -mvn quarkus:dev +oc project $PROJECT +oc port-forward service/weaviate-vector-db 8086:8080 50051:50051 ``` -Need to login to Openshift using `oc login` and run the following command to port forward the vector DB +Once forwarded the following values can be changed + +```properties +weaviate.default.scheme=http +weaviate.default.host=localhost:8086 +weaviate.default.apiKey= +``` + +> If using the App of Apps repo the API key is retrieved from autogenerated secret `weaviate-api-key-secret` + +## Embedding Model + +Currently the supported models are added to the resources folder and [loaded directly](src/main/java/com/redhat/composer/config/retriever/embeddingmodel/NomicLocalEmbeddingModelClient.java). We would like to move this logic to pull these models using maven as seen [here](https://docs.langchain4j.dev/category/embedding-models) + +> [!IMPORTANT] +> The embedding model is too large to check into our repo. +> Download it from [huggingface](https://huggingface.co/nomic-ai/nomic-embed-text-v1/resolve/main/onnx/model_quantized.onnx?download=true) or [here](https://drive.google.com/drive/folders/1jZe0cEw8p_E-fghd6IFPjwiabDNAhtp7?usp=drive_link) if internal to RH. +> Then add it to `resources/embedding/nomic` with the name `model.onnx`, it should be gitignored if done correctly. + +## Local Curl + +If the LLM Connection has been setup correctly the following curl command should stream a response from your LLM ```sh -oc port-forward service/weaviate-vector-db 8086:8080 50051:50051 +curl -X 'POST' 'http://localhost:8080/assistant/chat/streaming' -H 'Content-Type: application/json' -d '{ + "message": "What is this product?", + "assistantName": "default_assistant" +}' -N ``` -## Test Locally +The `assistantName` can be swapped out for other assistants inside of the table above, but the other assistants will required a connection to a weaviate db with the correct indexes. The App Of Apps repository contains a [validation script](https://github.com/redhat-composer-ai/appOfApps/blob/main/data-ingestion/weaviate/validation.sh) that can be used to show which indexes currently exist. -The following curl command should return a streaming output answering based on the default Rag/LLM settings (set in the properties file) +## Admin Flow -`curl -X POST -H "Content-Type: application/json" -d '{"message":"What is a route?"}' http://localhost:8080/chatbot/chat/streaming -N` +Information about the creation/updating of Assistants, ContentRetrievers, and LLMs can be found in the [admin flow docs](documentation/ADMIN_WORKFLOW.MD) -> Note: There are endpoint for testing each of the specific components +## Contributing -## Embedding Model +We welcome contributions from the community\! Here's how you can get involved: + +**1. Find an Issue:** + + * Check the [issue tracker](https://github.com/redhat-composer-ai/quarkus-llm-router/issues) or [jira board](https://issues.redhat.com/secure/RapidBoard.jspa?projectKey=REDSAIA&rapidView=20236) for open issues that interest you. + * If you find a bug or have a feature request, please open a new issue with a clear description. + +> [!NOTE] +> Currently this project is primarlly tracking using Red Hat's internal Jira. + +**2. Fork the Repository:** + + * Fork this repository to your own GitHub account. + +**3. Create a Branch:** + + * Create a new branch for your changes. Use a descriptive name that reflects the issue or feature you're working on (e.g., `fix-issue-123` or `add-new-feature`). + +**4. Make Changes:** + + * Make your desired changes to the codebase. + * Follow the existing code style and conventions. + * Write clear commit messages that explain the purpose of your changes. + +**5. Test Your Changes:** + + * Thoroughly test your changes to ensure they work as expected. + * If there are existing tests, make sure they all pass. Consider adding new tests to cover your changes. + +**6. Code Style and Formatting:** + + * Ensure your code adheres to the project's established code style guidelines. + * This project uses Checkstyle's automated code formatting tools. Your code must pass these checks before it can be merged. + + +> [!TIP] +> Checkstyle can be run locally using `mvn site` which creates a report page under `target/site`. +> +> It is also recommended that you use a checkstyle tool in your IDE such as this [VS Code Plugin](https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-checkstyle) in order order to adhear to guidelines as you code. + +**7. Open a Pull Request:** + + * Push your branch to your forked repository. + * Open a pull request to the main repository. + * In the pull request description, clearly explain the changes you've made and reference the related issue (if applicable). + * Validate that all automate checks are passing + +**8. Review Process:** + + * Your pull request will be reviewed by the project maintainers. + * Feel free to ping in our general slack channel asking for approval/assistants + * Be prepared to address any feedback or questions. + * Once your code has passed all automated checks and received at least one approval from a maintainer, it will be merged. -IMPORTANT: The embedding modes is to large to check into our repo. So you need to download from the following link and put it in `resources/embedding/nomic`. -https://drive.google.com/drive/folders/1jZe0cEw8p_E-fghd6IFPjwiabDNAhtp7?usp=drive_link +**Important Notes:** -We need to figure out a better way to handel this in the future (or put this on github) + * All code contributions must pass automated code scanning checks before they can be merged. + * At least one approval from a maintainer is required for all pull requests. -## Code Standards +**Thank you for your contributions\!** -### OWasp Security Scanning +### Security Scanning -The [OWASP Dependency-Check Plugin](https://owasp.org/www-project-dependency-check/) can be run using the following command: +The [OWASP Dependency-Check Plugin](https://owasp.org/www-project-dependency-check/) not required to pass but is included, we ask that the scanner be run if any changes are made to the dependencies. ```sh mvn validate -P security-scanner diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml new file mode 100644 index 0000000..cbdf916 --- /dev/null +++ b/checkstyle-suppressions.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..d00b19a --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,440 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/documentation/ADMIN_WORKFLOW.MD b/documentation/ADMIN_WORKFLOW.MD index 828ebb2..fc9cb3c 100644 --- a/documentation/ADMIN_WORKFLOW.MD +++ b/documentation/ADMIN_WORKFLOW.MD @@ -22,3 +22,6 @@ Backend includes the ability to dynamically create Assistants, Rag Connections, "description": "Example of a rag connection" } ``` + +> [!NOTE] +> This document is a work in progress. diff --git a/documentation/WEAVIATE_SETUP.md b/documentation/WEAVIATE_SETUP.md new file mode 100644 index 0000000..9ee1c40 --- /dev/null +++ b/documentation/WEAVIATE_SETUP.md @@ -0,0 +1,5 @@ +# Weaviate Setup + +Information about setting up a local weaviate can be found [here](https://weaviate.io/developers/weaviate/quickstart/local). + +More to come on local data ingestion. diff --git a/pom.xml b/pom.xml index 8b67b4e..dafae10 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,8 @@ 0.35.0 0.21.0.CR1 1.6.2 + 11.1.0 + 3.6.0 @@ -140,6 +142,29 @@ + + + + + org.apache.maven.plugins + maven-site-plugin + 4.0.0-M16 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.6.0 + + + com.puppycrawl.tools + checkstyle + 10.20.1 + + + + + + ${quarkus.platform.group-id} @@ -192,7 +217,25 @@ ${maven.home} - + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${checkstyle-maven-plugin.version} + + checkstyle.xml + checkstyle-suppressions.xml + + + + + check + + + + @@ -209,5 +252,47 @@ true + + + + security-scanner + + + + org.owasp + dependency-check-maven + ${owasp-dependency-check-plugin.version} + + + + check + + + + + + 7 + + ${project.basedir}/dependency-cpe-suppression.xml + + + + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${checkstyle-maven-plugin.version} + + checkstyle.xml + checkstyle-suppressions.xml + + + + diff --git a/src/main/java/com/redhat/composer/api/AssistantAdminAPI.java b/src/main/java/com/redhat/composer/api/AssistantAdminApi.java similarity index 58% rename from src/main/java/com/redhat/composer/api/AssistantAdminAPI.java rename to src/main/java/com/redhat/composer/api/AssistantAdminApi.java index 68ec838..d270f09 100644 --- a/src/main/java/com/redhat/composer/api/AssistantAdminAPI.java +++ b/src/main/java/com/redhat/composer/api/AssistantAdminApi.java @@ -3,7 +3,7 @@ import java.util.List; import com.redhat.composer.model.mongo.AssistantEntity; -import com.redhat.composer.model.mongo.LLMConnectionEntity; +import com.redhat.composer.model.mongo.LlmConnectionEntity; import com.redhat.composer.model.mongo.RetrieverConnectionEntity; import com.redhat.composer.model.request.AssistantCreationRequest; import com.redhat.composer.model.request.LLMRequest; @@ -17,42 +17,72 @@ import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; +/** + * Admin API for Creating and Managing Assistants. + */ @Path("/admin/assistant") @Authenticated -public class AssistantAdminAPI { +public class AssistantAdminApi { @Inject AssistantInfoService assistantService; + /** + * Create a LLM Connection. + * @param request the LLMRequest + * @return the LLMConnectionEntity + */ @POST @Path("llm") - public LLMConnectionEntity createLLM(LLMRequest request) { - return assistantService.createLLMConnection(request); + public LlmConnectionEntity createLlm(LLMRequest request) { + return assistantService.createLlmConnection(request); } + /** + * Get all LLM Connections. + * @return the list of LLMConnectionEntity + */ @GET @Path("llm") - public List getLLMs() { - return assistantService.getLLMConnections(); + public List getLlms() { + return assistantService.getLlmConnections(); } + /** + * Create a Retriever Connection. + * @param request the RetrieverRequest + * @return the RetrieverConnectionEntity + */ @POST @Path("retrieverConnection") public RetrieverConnectionEntity createRetrieverConnection(RetrieverRequest request) { return assistantService.createRetrieverConnectionEntity(request); } + /** + * Get all Retriever Connections. + * @return the list of RetrieverConnectionEntity + */ @GET @Path("retrieverConnection") public List getRetrieverConnection() { return assistantService.getRetrieverConnections(); } + /** + * Create an Assistant. + * @param request the AssistantCreationRequest + * @return the AssistantEntity + */ @POST public AssistantEntity createAssistant(AssistantCreationRequest request) { return assistantService.createAssistant(request); } + /** + * Get all Assistants. + * @return the list of AssistantResponse + */ @GET public List getAssistant() { return assistantService.getAssistant(); diff --git a/src/main/java/com/redhat/composer/api/AssistantApi.java b/src/main/java/com/redhat/composer/api/AssistantApi.java index 74aa839..96e7aa6 100644 --- a/src/main/java/com/redhat/composer/api/AssistantApi.java +++ b/src/main/java/com/redhat/composer/api/AssistantApi.java @@ -13,6 +13,9 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.core.MediaType; +/** + * Assistant API for Chatting using assistants. + */ @Path("/assistant/chat") @Authenticated public class AssistantApi { @@ -23,11 +26,16 @@ public class AssistantApi { ChatBotService chatBotService; + /** + * Chat with an assistant. + * @param input the AssistantChatRequest + * @return the Multi of String + */ @POST @Path("streaming") @Consumes(MediaType.APPLICATION_JSON) public Multi chat(AssistantChatRequest input) { - return chatBotService.chat(input); + return chatBotService.chat(input); } } diff --git a/src/main/java/com/redhat/composer/api/ChatBotAPI.java b/src/main/java/com/redhat/composer/api/ChatBotApi.java similarity index 68% rename from src/main/java/com/redhat/composer/api/ChatBotAPI.java rename to src/main/java/com/redhat/composer/api/ChatBotApi.java index 1d153a0..581e946 100644 --- a/src/main/java/com/redhat/composer/api/ChatBotAPI.java +++ b/src/main/java/com/redhat/composer/api/ChatBotApi.java @@ -13,21 +13,28 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.core.MediaType; +/** + * ChatBotAPI for Chatting using ChatBots. + */ @Path("/chatbot/chat") @Authenticated -public class ChatBotAPI { +public class ChatBotApi { - Logger log = Logger.getLogger(ChatBotAPI.class); + Logger log = Logger.getLogger(ChatBotApi.class); @Inject ChatBotService chatBotService; - + /** + * Chat with a ChatBot. + * @param input ChatBotRequest infromation + * @return Streamed response + */ @POST @Path("streaming") @Consumes(MediaType.APPLICATION_JSON) public Multi chat(ChatBotRequest input) { - return chatBotService.chat(input); + return chatBotService.chat(input); } } diff --git a/src/main/java/com/redhat/composer/api/EmbeddingAPI.java b/src/main/java/com/redhat/composer/api/EmbeddingApi.java similarity index 69% rename from src/main/java/com/redhat/composer/api/EmbeddingAPI.java rename to src/main/java/com/redhat/composer/api/EmbeddingApi.java index 6fa0da2..cfe844c 100644 --- a/src/main/java/com/redhat/composer/api/EmbeddingAPI.java +++ b/src/main/java/com/redhat/composer/api/EmbeddingApi.java @@ -12,20 +12,26 @@ import jakarta.ws.rs.core.MediaType; /** - * Api For Testing Embedding + * Api For Testing Embedding. */ @Path("/embedding") @Authenticated -public class EmbeddingAPI { +public class EmbeddingApi { @Inject EmbeddingService embeddingService; + /** + * Embedd a string. + * @param text the text to embedd + * @param embeddingType the type of embedding to use + * @return the embedded string + */ @POST @Path("{embeddingType}") @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public String embeddString(String text, @PathParam("embeddingType") String embeddingType) { - return embeddingService.embedding(text,embeddingType).toString(); + return embeddingService.embedding(text, embeddingType).toString(); } } diff --git a/src/main/java/com/redhat/composer/api/LlmAPI.java b/src/main/java/com/redhat/composer/api/LlmApi.java similarity index 72% rename from src/main/java/com/redhat/composer/api/LlmAPI.java rename to src/main/java/com/redhat/composer/api/LlmApi.java index a9b492d..140c6ee 100644 --- a/src/main/java/com/redhat/composer/api/LlmAPI.java +++ b/src/main/java/com/redhat/composer/api/LlmApi.java @@ -22,12 +22,12 @@ import jakarta.ws.rs.core.MediaType; /** - * Api For Testing Embedding + * Api For Testing the LLM. */ @Path("/llm") -public class LlmAPI { +public class LlmApi { - Logger log = Logger.getLogger(LlmAPI.class); + Logger log = Logger.getLogger(LlmApi.class); @Inject SynchronousModelFactory synchronousModelFactory; @@ -35,6 +35,12 @@ public class LlmAPI { @Inject StreamingModelFactory streamingModelFactory; + /** + * Generate a response for a message. + * @param request the LLMRequest + * @param message message from LLM + * @return the response + */ @POST @Path("/generate") @Authenticated @@ -48,6 +54,12 @@ public String syncRequest(LLMRequest request, @QueryParam("message") String mess return llm.generate(message); } + /** + * Generate a response for a message. + * @param request the LLMRequest + * @param message streaming message from LLM + * @return the response + */ @POST @Path("/generate/streaming") public Multi streamingRequest(LLMRequest request, @QueryParam("message") String message) { @@ -64,27 +76,6 @@ public Multi streamingRequest(LLMRequest request, @QueryParam("message") return response; } - - // Don't think we want to use this. - @POST - @Produces(MediaType.SERVER_SENT_EVENTS) - @RestStreamElementType("text/plain") - @Path("/generate/streaming/sse") - public Multi streamingRequestSSE(LLMRequest request, @QueryParam("message") String message) { - log.info("Generating response for message: " + message); - if (request == null) { - request = new LLMRequest(); - } - StreamingBaseModel model = streamingModelFactory.getModel(request.getModelType()); - - StreamingChatLanguageModel llm = model.getChatModel(request); - Assistant assistant = AiServices.create(Assistant.class, llm); - - Multi response = assistant.chat(message); - return response; - } - - interface Assistant { Multi chat(String message); } diff --git a/src/main/java/com/redhat/composer/api/VectorRetriverAPI.java b/src/main/java/com/redhat/composer/api/VectorRetriverApi.java similarity index 62% rename from src/main/java/com/redhat/composer/api/VectorRetriverAPI.java rename to src/main/java/com/redhat/composer/api/VectorRetriverApi.java index 9bfe3e7..2a23191 100644 --- a/src/main/java/com/redhat/composer/api/VectorRetriverAPI.java +++ b/src/main/java/com/redhat/composer/api/VectorRetriverApi.java @@ -16,11 +16,11 @@ import jakarta.ws.rs.QueryParam; /** - * Api For Testing Store Retrievers + * Api For Testing Store Retrievers. */ @Path("/retriver") @Authenticated -public class VectorRetriverAPI { +public class VectorRetriverApi { @Inject RetrieveService retrieveService; @@ -28,21 +28,25 @@ public class VectorRetriverAPI { @Inject MapperUtil mapperUtil; + /** + * Retrieve sources. + * @param request the RetrieverRequest + * @param message the message + * @return the list of SourceResponse + */ @POST @Path("/sources") - public List retrieveSources(RetrieverRequest request, @QueryParam("message") String message) { - return retrieveService.retrieveContent(request, message).stream().map(VectorRetriverAPI::toSourceResponse).toList(); - } - - @POST - @Path("/sources/metadata") - public List> retrieveSourceMetadata(RetrieverRequest request, @QueryParam("message") String message) { - return retrieveService.retrieveContent(request, message) - .stream() - .map(content -> content.textSegment().metadata().toMap()) // Accessing metadata inside textSegment - .toList(); + public List retrieveSources(RetrieverRequest request, + @QueryParam("message") String message) { + return retrieveService.retrieveContent(request, message).stream() + .map(VectorRetriverApi::toSourceResponse).toList(); } + /** + * Retrieve sources. + * @param content the Content returned from the retriever + * @return source info + */ public static SourceResponse toSourceResponse(Content content) { SourceResponse response = new SourceResponse(); response.setContent(content.textSegment().text()); diff --git a/src/main/java/com/redhat/composer/api/validation/OIDCValidationAPI.java b/src/main/java/com/redhat/composer/api/validation/OidcValidationApi.java similarity index 84% rename from src/main/java/com/redhat/composer/api/validation/OIDCValidationAPI.java rename to src/main/java/com/redhat/composer/api/validation/OidcValidationApi.java index cdf2b91..7cdce56 100644 --- a/src/main/java/com/redhat/composer/api/validation/OIDCValidationAPI.java +++ b/src/main/java/com/redhat/composer/api/validation/OidcValidationApi.java @@ -1,6 +1,5 @@ package com.redhat.composer.api.validation; -import java.util.Map; import java.util.Set; import io.quarkus.security.Authenticated; @@ -9,9 +8,12 @@ import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; +/** + * OIDCValidationAPI. + */ @Path("/auth") @Authenticated -public class OIDCValidationAPI { +public class OidcValidationApi { @Inject SecurityIdentity securityIdentity; @@ -26,7 +28,7 @@ public String getPrincipal() { @GET @Path("roles") - public Set getRoles() { + public Set getRoles() { return securityIdentity.getRoles(); } diff --git a/src/main/java/com/redhat/composer/api/validation/SteramingValidationAPI.java b/src/main/java/com/redhat/composer/api/validation/SteramingValidationAPI.java deleted file mode 100644 index 343478c..0000000 --- a/src/main/java/com/redhat/composer/api/validation/SteramingValidationAPI.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.redhat.composer.api.validation; - -import java.util.Random; - -import org.jboss.resteasy.reactive.RestStreamElementType; - -import io.quarkus.security.Authenticated; -import io.smallrye.mutiny.Multi; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; - -@Path("/streaming") -@Authenticated -public class SteramingValidationAPI { - - - @Path("basic") - public Multi streamBasic() { - return Multi.createFrom().ticks().every(java.time.Duration.ofSeconds(1)) - .onItem().transform(n -> getRandomLetter()); - } - - - @GET - @Path("basic") - public String getBasic() { - return "Hello"; - } - - private String getRandomLetter() { - Random r = new Random(); - return String.valueOf((char) (r.nextInt(26) + 'a')); - } - -} diff --git a/src/main/java/com/redhat/composer/config/llm/aiservices/AIServicesFactory.java b/src/main/java/com/redhat/composer/config/llm/aiservices/AiServicesFactory.java similarity index 66% rename from src/main/java/com/redhat/composer/config/llm/aiservices/AIServicesFactory.java rename to src/main/java/com/redhat/composer/config/llm/aiservices/AiServicesFactory.java index ddfc07d..b535ae6 100644 --- a/src/main/java/com/redhat/composer/config/llm/aiservices/AIServicesFactory.java +++ b/src/main/java/com/redhat/composer/config/llm/aiservices/AiServicesFactory.java @@ -2,8 +2,11 @@ import jakarta.enterprise.context.ApplicationScoped; +/** + * Factory for AI Services. + */ @ApplicationScoped -public class AIServicesFactory { +public class AiServicesFactory { public static final String MISTRAL7B_AI_SERVICE = "mistral7b"; @@ -11,10 +14,15 @@ public class AIServicesFactory { public static final String HEALTHCARE_SERVICE = "healthcare"; - public Class getAiService(String aiServiceType) { + /** + * Get the AI service class. + * @param aiServiceType the AI service type + * @return the AI service class + */ + public Class getAiService(String aiServiceType) { switch (aiServiceType) { case MISTRAL7B_AI_SERVICE: - return Mistral7BAiService.class; + return Mistral7bAiService.class; case HEALTHCARE_SERVICE: return HealthCareService.class; default: diff --git a/src/main/java/com/redhat/composer/config/llm/aiservices/BaseAIService.java b/src/main/java/com/redhat/composer/config/llm/aiservices/BaseAIService.java deleted file mode 100644 index b5365b8..0000000 --- a/src/main/java/com/redhat/composer/config/llm/aiservices/BaseAIService.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.redhat.composer.config.llm.aiservices; - -import dev.langchain4j.service.TokenStream; -import io.quarkiverse.langchain4j.RegisterAiService; -import io.smallrye.mutiny.Multi; - -/** - * Mistral7BAiService - */ -public interface BaseAIService { - - // TokenStream should be used when possible - TokenStream chatToken(String context, String input); - - Multi chatStream(String context, String input); - -} \ No newline at end of file diff --git a/src/main/java/com/redhat/composer/config/llm/aiservices/BaseAiService.java b/src/main/java/com/redhat/composer/config/llm/aiservices/BaseAiService.java new file mode 100644 index 0000000..40e7f20 --- /dev/null +++ b/src/main/java/com/redhat/composer/config/llm/aiservices/BaseAiService.java @@ -0,0 +1,27 @@ +package com.redhat.composer.config.llm.aiservices; + +import dev.langchain4j.service.TokenStream; +import io.smallrye.mutiny.Multi; + +/** + * Base AI Service Interface. + */ +public interface BaseAiService { + + /** + * Returns TokenStream given input. + * @param context Context information such as chat history and source information + * @param input User Message + * @return the TokenStream + */ + TokenStream chatToken(String context, String input); + + /** + * Returns a Multi of String given input. + * @param context Context information such as chat history and source information + * @param input User Message + * @return the Multi of String + */ + Multi chatStream(String context, String input); + +} \ No newline at end of file diff --git a/src/main/java/com/redhat/composer/config/llm/aiservices/HealthCareService.java b/src/main/java/com/redhat/composer/config/llm/aiservices/HealthCareService.java index 6444d1e..b15ea11 100644 --- a/src/main/java/com/redhat/composer/config/llm/aiservices/HealthCareService.java +++ b/src/main/java/com/redhat/composer/config/llm/aiservices/HealthCareService.java @@ -6,16 +6,15 @@ import io.smallrye.mutiny.Multi; /** - * Mistral7BAiService + * Mistral7BAiService. */ +public interface HealthCareService extends BaseAiService { -public interface HealthCareService extends BaseAIService { - - final static String systemMessage = """ + static final String systemMessage = """ You are a helpful, respectful and honest assistant answering questions about healthcare. -"""; + """; - final static String userMessage =""" + static final String userMessage = """ {context} @@ -24,16 +23,22 @@ public interface HealthCareService extends BaseAIService { Question: {input} <|eot_id|> <|start_header_id|>assistant<|end_header_id|> -"""; - - @SystemMessage(systemMessage) - @UserMessage(userMessage) - TokenStream chatToken(String context, String input); - - - - @SystemMessage(systemMessage) - @UserMessage(userMessage) - Multi chatStream(String context, String input); + """; + + /** + * Returns TokenStream given input. + * @param context Context information such as chat history and source information + */ + @SystemMessage(systemMessage) + @UserMessage(userMessage) + TokenStream chatToken(String context, String input); + + + /** + * Returns a Multi of String given input. + */ + @SystemMessage(systemMessage) + @UserMessage(userMessage) + Multi chatStream(String context, String input); } \ No newline at end of file diff --git a/src/main/java/com/redhat/composer/config/llm/aiservices/Mistral7BAiService.java b/src/main/java/com/redhat/composer/config/llm/aiservices/Mistral7bAiService.java similarity index 59% rename from src/main/java/com/redhat/composer/config/llm/aiservices/Mistral7BAiService.java rename to src/main/java/com/redhat/composer/config/llm/aiservices/Mistral7bAiService.java index 2a3e79c..46662af 100644 --- a/src/main/java/com/redhat/composer/config/llm/aiservices/Mistral7BAiService.java +++ b/src/main/java/com/redhat/composer/config/llm/aiservices/Mistral7bAiService.java @@ -5,13 +5,14 @@ import dev.langchain4j.service.UserMessage; import io.smallrye.mutiny.Multi; + /** - * Mistral7BAiService + * Mistral7BAiService. */ +@SuppressWarnings("LineLengthCheck") +public interface Mistral7bAiService extends BaseAiService { -public interface Mistral7BAiService extends BaseAIService { - - final static String systemMessage = """ + static final String systemMessage = """ You are a helpful, respectful and honest assistant answering questions about products from the company called Red Hat. You will be given a question you need to answer about this product. If a question is about a specific product you will be given the product name and version, and references to provide you with additional information. @@ -21,9 +22,9 @@ public interface Mistral7BAiService extends BaseAIService { Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information. -"""; + """; - final static String userMessage =""" + static final String userMessage = """ {context} @@ -32,16 +33,27 @@ public interface Mistral7BAiService extends BaseAIService { Question: {input} <|eot_id|> <|start_header_id|>assistant<|end_header_id|> -"""; - - @SystemMessage(systemMessage) - @UserMessage(userMessage) - TokenStream chatToken(String context, String input); - - - - @SystemMessage(systemMessage) - @UserMessage(userMessage) - Multi chatStream(String context, String input); + """; + + /** + * Returns TokenStream given input. + * @param context Context information such as chat history and source information + * @param input User Message + * @return the TokenStream + */ + @SystemMessage(systemMessage) + @UserMessage(userMessage) + TokenStream chatToken(String context, String input); + + + /** + * Returns a Multi of String given input. + * @param context Context information such as chat history and source information + * @param input User Message + * @return the Multi of String + */ + @SystemMessage(systemMessage) + @UserMessage(userMessage) + Multi chatStream(String context, String input); } \ No newline at end of file diff --git a/src/main/java/com/redhat/composer/config/llm/models/streaming/OpenAIStreamingModel.java b/src/main/java/com/redhat/composer/config/llm/models/streaming/OpenAiStreamingModel.java similarity index 51% rename from src/main/java/com/redhat/composer/config/llm/models/streaming/OpenAIStreamingModel.java rename to src/main/java/com/redhat/composer/config/llm/models/streaming/OpenAiStreamingModel.java index dba2143..b9eb6f8 100644 --- a/src/main/java/com/redhat/composer/config/llm/models/streaming/OpenAIStreamingModel.java +++ b/src/main/java/com/redhat/composer/config/llm/models/streaming/OpenAiStreamingModel.java @@ -3,7 +3,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.logging.Logger; -import com.redhat.composer.config.retriever.contentRetriever.WeaviateContentRetrieverClient; +import com.redhat.composer.config.retriever.contentretriever.WeaviateContentRetrieverClient; import com.redhat.composer.model.request.LLMRequest; import dev.langchain4j.model.chat.StreamingChatLanguageModel; @@ -11,13 +11,15 @@ import dev.langchain4j.model.openai.OpenAiStreamingChatModel.OpenAiStreamingChatModelBuilder; import jakarta.enterprise.context.ApplicationScoped; - +/** + * OpenAI Streaming Model. + */ @ApplicationScoped -public class OpenAIStreamingModel extends StreamingBaseModel { +public class OpenAiStreamingModel extends StreamingBaseModel { Logger log = Logger.getLogger(WeaviateContentRetrieverClient.class); - @ConfigProperty( name = "openai.default.url") + @ConfigProperty(name = "openai.default.url") private String mistralDefaultUrl; @ConfigProperty(name = "openai.default.apiKey") @@ -29,28 +31,35 @@ public class OpenAIStreamingModel extends StreamingBaseModel { @ConfigProperty(name = "openai.default.temp") private double openaiDefaultTemp; - + /** + * Get the Chat Model. + * @param request the LLMRequest + * @return the StreamingChatLanguageModel + */ public StreamingChatLanguageModel getChatModel(LLMRequest request) { - log.info("Attempting to create OpenAI Streaming Chat Model at: " + request.getUrl() + " with model name: " + request.getModelName()); + + log.info("Attempting to create OpenAI Streaming Chat Model at: " + request.getUrl() + + " with model name: " + request.getModelName()); + OpenAiStreamingChatModelBuilder builder = OpenAiStreamingChatModel.builder(); - builder.baseUrl(request.getUrl() == null ? mistralDefaultUrl : request.getUrl()); - builder.apiKey(request.getApiKey() == null ? mistralDefaultApiKey : request.getApiKey()); - - builder.modelName(request.getModelName() == null ? mistralDefaultModelName : request.getModelName()); - - // TODO: Add all the following to the request - builder.temperature(openaiDefaultTemp); - - // TODO: Fill all this out - // if (modelName != null) { - // builder.modelName(modelName); - // } - // if (maxTokens != null) { - // builder.maxTokens(maxTokens); - // } - // if (safePrompt != null) { - // builder.safePrompt(safePrompt); - // } + builder.baseUrl(request.getUrl() == null ? mistralDefaultUrl : request.getUrl()); + builder.apiKey(request.getApiKey() == null ? mistralDefaultApiKey : request.getApiKey()); + + builder.modelName(request.getModelName() == null ? mistralDefaultModelName : request.getModelName()); + + // TODO: Add all the following to the request + builder.temperature(openaiDefaultTemp); + + // TODO: Fill all this out + // if (modelName != null) { + // builder.modelName(modelName); + // } + // if (maxTokens != null) { + // builder.maxTokens(maxTokens); + // } + // if (safePrompt != null) { + // builder.safePrompt(safePrompt); + // } return builder.build(); } diff --git a/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingBaseModel.java b/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingBaseModel.java index c652890..6581542 100644 --- a/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingBaseModel.java +++ b/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingBaseModel.java @@ -6,9 +6,17 @@ import dev.langchain4j.model.chat.StreamingChatLanguageModel; +/** + * Streaming Base Model. + */ public class StreamingBaseModel { + /** + * Get Chat Model. + * @param request the LLMRequest + * @return the StreamingChatLanguageModel + */ public StreamingChatLanguageModel getChatModel(LLMRequest request) { - throw new NotImplementedException("Not implemented"); + throw new NotImplementedException("Not implemented"); } } diff --git a/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingModelFactory.java b/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingModelFactory.java index e0b0091..f2b4fac 100644 --- a/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingModelFactory.java +++ b/src/main/java/com/redhat/composer/config/llm/models/streaming/StreamingModelFactory.java @@ -3,24 +3,32 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +/** + * Streaming Model Factory. + */ @ApplicationScoped public class StreamingModelFactory { @Inject - OpenAIStreamingModel openAIModel; + OpenAiStreamingModel openAiModel; public static final String OPENAI_MODEL = "openai"; // TODO: Make this configurable public static final String DEFAULT_MODEL = OPENAI_MODEL; + /** + * Get the model. + * @param modelType the model type + * @return the model + */ public StreamingBaseModel getModel(String modelType) { - if(modelType == null) { + if (modelType == null) { modelType = DEFAULT_MODEL; } switch (modelType) { case OPENAI_MODEL: - return openAIModel; + return openAiModel; default: throw new RuntimeException("Model type not found: " + modelType); } diff --git a/src/main/java/com/redhat/composer/config/llm/models/synchronous/OpenAIModel.java b/src/main/java/com/redhat/composer/config/llm/models/synchronous/OpenAiModel.java similarity index 70% rename from src/main/java/com/redhat/composer/config/llm/models/synchronous/OpenAIModel.java rename to src/main/java/com/redhat/composer/config/llm/models/synchronous/OpenAiModel.java index c26fffb..8444d5b 100644 --- a/src/main/java/com/redhat/composer/config/llm/models/synchronous/OpenAIModel.java +++ b/src/main/java/com/redhat/composer/config/llm/models/synchronous/OpenAiModel.java @@ -9,11 +9,13 @@ import dev.langchain4j.model.openai.OpenAiChatModel.OpenAiChatModelBuilder; import jakarta.enterprise.context.ApplicationScoped; - +/** + * OpenAI Model. + */ @ApplicationScoped -public class OpenAIModel extends SynchronousBaseModel { +public class OpenAiModel extends SynchronousBaseModel { - @ConfigProperty( name = "openai.default.url") + @ConfigProperty(name = "openai.default.url") private String mistralDefaultUrl; @ConfigProperty(name = "openai.default.apiKey") @@ -26,6 +28,11 @@ public class OpenAIModel extends SynchronousBaseModel { private double openaiDefaultTemp; + /** + * Get the Chat Model. + * @param request the LLMRequest + * @return the ChatLanguageModel + */ public ChatLanguageModel getChatModel(LLMRequest request) { OpenAiChatModelBuilder builder = OpenAiChatModel.builder(); builder.baseUrl(request.getUrl() == null ? mistralDefaultUrl : request.getUrl()); @@ -36,16 +43,16 @@ public ChatLanguageModel getChatModel(LLMRequest request) { // TODO: Add all the following to the request builder.temperature(openaiDefaultTemp); - // Model names can be derived from MistralAiChatModelName enum - // if (modelName != null) { - // builder.modelName(modelName); - // } - // if (maxTokens != null) { - // builder.maxTokens(maxTokens); - // } - // if (safePrompt != null) { - // builder.safePrompt(safePrompt); - // } + // Model names can be derived from MistralAiChatModelName enum + // if (modelName != null) { + // builder.modelName(modelName); + // } + // if (maxTokens != null) { + // builder.maxTokens(maxTokens); + // } + // if (safePrompt != null) { + // builder.safePrompt(safePrompt); + // } return builder.build(); } diff --git a/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousBaseModel.java b/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousBaseModel.java index a3e0d3c..479ef7d 100644 --- a/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousBaseModel.java +++ b/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousBaseModel.java @@ -6,9 +6,17 @@ import dev.langchain4j.model.chat.ChatLanguageModel; +/** + * Synchronous Base Model. + */ public class SynchronousBaseModel { + /** + * Get Chat Model. + * @param request the LLMRequest + * @return the ChatLanguageModel + */ public ChatLanguageModel getChatModel(LLMRequest request) { - throw new NotImplementedException("Not implemented"); + throw new NotImplementedException("Not implemented"); } } diff --git a/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousModelFactory.java b/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousModelFactory.java index 804bee3..3d438ce 100644 --- a/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousModelFactory.java +++ b/src/main/java/com/redhat/composer/config/llm/models/synchronous/SynchronousModelFactory.java @@ -3,24 +3,32 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +/** + * Synchronous Model Factory. + */ @ApplicationScoped public class SynchronousModelFactory { @Inject - OpenAIModel openAIModel; + OpenAiModel openAiModel; public static final String OPENAI_MODEL = "openai"; public static final String DEFAULT_MODEL = OPENAI_MODEL; + /** + * Get the model. + * @param modelType the model type + * @return the model + */ public SynchronousBaseModel getModel(String modelType) { - if(modelType == null) { + if (modelType == null) { modelType = DEFAULT_MODEL; } switch (modelType) { case OPENAI_MODEL: - return openAIModel; + return openAiModel; default: throw new RuntimeException("Model type not found: " + modelType); } diff --git a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/BaseContentRetrieverClient.java b/src/main/java/com/redhat/composer/config/retriever/contentretriever/BaseContentRetrieverClient.java similarity index 61% rename from src/main/java/com/redhat/composer/config/retriever/contentRetriever/BaseContentRetrieverClient.java rename to src/main/java/com/redhat/composer/config/retriever/contentretriever/BaseContentRetrieverClient.java index 018083a..815b181 100644 --- a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/BaseContentRetrieverClient.java +++ b/src/main/java/com/redhat/composer/config/retriever/contentretriever/BaseContentRetrieverClient.java @@ -1,23 +1,35 @@ -package com.redhat.composer.config.retriever.contentRetriever; +package com.redhat.composer.config.retriever.contentretriever; -import com.redhat.composer.config.retriever.embeddingModel.EmbeddingModelFactory; +import com.redhat.composer.config.retriever.embeddingmodel.EmbeddingModelFactory; import com.redhat.composer.model.request.RetrieverRequest; import dev.langchain4j.model.embedding.EmbeddingModel; import dev.langchain4j.rag.content.retriever.ContentRetriever; import jakarta.inject.Inject; +/** + * Base Content Retriever Client. + */ public class BaseContentRetrieverClient { @Inject EmbeddingModelFactory embeddingModelFactory; - - public ContentRetriever getContentRetriever(RetrieverRequest request){ + /** + * Get Content Retriever. + * @param request the RetrieverRequest + * @return ContentRetriever + */ + public ContentRetriever getContentRetriever(RetrieverRequest request) { throw new UnsupportedOperationException("Unimplemented method 'getContentRetriever'"); } - protected EmbeddingModel getEmbeddingModel(String embeddingType){ + /** + * Get Embedding Model. + * @param embeddingType the String + * @return EmbeddingModel + */ + protected EmbeddingModel getEmbeddingModel(String embeddingType) { return embeddingModelFactory.getEmbeddingModel(embeddingType); } diff --git a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/ContentRetrieverClientFactory.java b/src/main/java/com/redhat/composer/config/retriever/contentretriever/ContentRetrieverClientFactory.java similarity index 70% rename from src/main/java/com/redhat/composer/config/retriever/contentRetriever/ContentRetrieverClientFactory.java rename to src/main/java/com/redhat/composer/config/retriever/contentretriever/ContentRetrieverClientFactory.java index 3cdde7a..b324411 100644 --- a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/ContentRetrieverClientFactory.java +++ b/src/main/java/com/redhat/composer/config/retriever/contentretriever/ContentRetrieverClientFactory.java @@ -1,10 +1,13 @@ -package com.redhat.composer.config.retriever.contentRetriever; +package com.redhat.composer.config.retriever.contentretriever; import com.redhat.composer.model.enums.ContentRetrieverType; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +/** + * Factory for Content Retriever Clients. + */ @ApplicationScoped public class ContentRetrieverClientFactory { @@ -14,10 +17,16 @@ public class ContentRetrieverClientFactory { @Inject Neo4jContentRetrieverClient neo4jContentRetrieverClient; - final static ContentRetrieverType DEFAULT_CONTENT_RETRIEVER = ContentRetrieverType.WEAVIATE; + static final ContentRetrieverType DEFAULT_CONTENT_RETRIEVER = ContentRetrieverType.WEAVIATE; + + /** + * Get the Content Retriever Client. + * @param contentRetrieverType the ContentRetrieverType + * @return the Content Retriever Client + */ public BaseContentRetrieverClient getContentRetrieverClient(ContentRetrieverType contentRetrieverType) { - if(contentRetrieverType == null) { + if (contentRetrieverType == null) { contentRetrieverType = DEFAULT_CONTENT_RETRIEVER; } diff --git a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/Neo4jContentRetrieverClient.java b/src/main/java/com/redhat/composer/config/retriever/contentretriever/Neo4jContentRetrieverClient.java similarity index 82% rename from src/main/java/com/redhat/composer/config/retriever/contentRetriever/Neo4jContentRetrieverClient.java rename to src/main/java/com/redhat/composer/config/retriever/contentretriever/Neo4jContentRetrieverClient.java index 3860df0..a37d1ee 100644 --- a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/Neo4jContentRetrieverClient.java +++ b/src/main/java/com/redhat/composer/config/retriever/contentretriever/Neo4jContentRetrieverClient.java @@ -1,4 +1,4 @@ -package com.redhat.composer.config.retriever.contentRetriever; +package com.redhat.composer.config.retriever.contentretriever; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.neo4j.driver.AuthTokens; @@ -17,19 +17,27 @@ import jakarta.inject.Inject; import jakarta.inject.Singleton; +/** + * Neo4j Content Retriever Client. + */ @Singleton public class Neo4jContentRetrieverClient extends BaseContentRetrieverClient { - @ConfigProperty( name = "neo4j.default.url") + @ConfigProperty(name = "neo4j.default.url") private String neo4jUrl; - @ConfigProperty( name = "neo4j.default.username") + @ConfigProperty(name = "neo4j.default.username") private String neo4jUser; - @ConfigProperty( name = "neo4j.default.password") + @ConfigProperty(name = "neo4j.default.password") private String neo4jPassword; @Inject SynchronousModelFactory synchronousModelFactory; + /** + * Get the Content Retriever. + * @param request the RetrieverRequest + * @return the Content Retriever + */ public ContentRetriever getContentRetriever(RetrieverRequest request) { Driver driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUser, neo4jPassword)); diff --git a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/WeaviateContentRetrieverClient.java b/src/main/java/com/redhat/composer/config/retriever/contentretriever/WeaviateContentRetrieverClient.java similarity index 72% rename from src/main/java/com/redhat/composer/config/retriever/contentRetriever/WeaviateContentRetrieverClient.java rename to src/main/java/com/redhat/composer/config/retriever/contentretriever/WeaviateContentRetrieverClient.java index 9ba2797..5e566cf 100644 --- a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/WeaviateContentRetrieverClient.java +++ b/src/main/java/com/redhat/composer/config/retriever/contentretriever/WeaviateContentRetrieverClient.java @@ -1,9 +1,9 @@ -package com.redhat.composer.config.retriever.contentRetriever; +package com.redhat.composer.config.retriever.contentretriever; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.logging.Logger; -import com.redhat.composer.config.retriever.contentRetriever.custom.WeaviateEmbeddingStoreCustom; +import com.redhat.composer.config.retriever.contentretriever.custom.WeaviateEmbeddingStoreCustom; import com.redhat.composer.model.request.RetrieverRequest; import com.redhat.composer.model.request.retriever.WeaviateRequest; @@ -12,15 +12,18 @@ import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever; import jakarta.inject.Singleton; +/** + * Weaviate Content Retriever Client. + */ @Singleton public class WeaviateContentRetrieverClient extends BaseContentRetrieverClient { Logger log = Logger.getLogger(WeaviateContentRetrieverClient.class); - @ConfigProperty( name = "weaviate.default.scheme") + @ConfigProperty(name = "weaviate.default.scheme") private String weaviateScheme; - @ConfigProperty( name = "weaviate.default.host") + @ConfigProperty(name = "weaviate.default.host") private String weaviateHost; @ConfigProperty(name = "weaviate.default.apiKey") @@ -32,9 +35,14 @@ public class WeaviateContentRetrieverClient extends BaseContentRetrieverClient { @ConfigProperty(name = "weaviate.default.textKey") private String weaviateTextKey; + /** + * Get the Content Retriever. + * @param request the RetrieverRequest + * @return the Content Retriever + */ public ContentRetriever getContentRetriever(RetrieverRequest request) { WeaviateRequest weaviateRequest = (WeaviateRequest) request.getBaseRetrieverRequest(); - if(weaviateRequest == null) { + if (weaviateRequest == null) { weaviateRequest = new WeaviateRequest(); } String scheme = weaviateRequest.getScheme() != null ? weaviateRequest.getScheme() : weaviateScheme; @@ -47,16 +55,16 @@ public ContentRetriever getContentRetriever(RetrieverRequest request) { log.info("Attempting to connect to Weaviate at " + scheme + "://" + host + " with index " + index); WeaviateEmbeddingStoreCustom store = WeaviateEmbeddingStoreCustom.builder() - .scheme(scheme) - .host(host) - .apiKey(apiKey) - .metadataFieldName("") - // .metadataFieldName(null) - .metadataKeys(weaviateRequest.getMetadataFields()) - .objectClass(index) - .avoidDups(true) - .textFieldName(textKey) - .build(); + .scheme(scheme) + .host(host) + .apiKey(apiKey) + .metadataFieldName("") + // .metadataFieldName(null) + .metadataKeys(weaviateRequest.getMetadataFields()) + .objectClass(index) + .avoidDups(true) + .textFieldName(textKey) + .build(); // Retrieve the embedding model @@ -66,9 +74,9 @@ public ContentRetriever getContentRetriever(RetrieverRequest request) { // Create the content retriever ContentRetriever contentRetriever = EmbeddingStoreContentRetriever.builder() - .embeddingStore(store) - .embeddingModel(embeddingModel) - .build(); + .embeddingStore(store) + .embeddingModel(embeddingModel) + .build(); return contentRetriever; } diff --git a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/custom/WeaviateEmbeddingStoreCustom.java b/src/main/java/com/redhat/composer/config/retriever/contentretriever/custom/WeaviateEmbeddingStoreCustom.java similarity index 99% rename from src/main/java/com/redhat/composer/config/retriever/contentRetriever/custom/WeaviateEmbeddingStoreCustom.java rename to src/main/java/com/redhat/composer/config/retriever/contentretriever/custom/WeaviateEmbeddingStoreCustom.java index 0584bd5..9ca5046 100644 --- a/src/main/java/com/redhat/composer/config/retriever/contentRetriever/custom/WeaviateEmbeddingStoreCustom.java +++ b/src/main/java/com/redhat/composer/config/retriever/contentretriever/custom/WeaviateEmbeddingStoreCustom.java @@ -1,4 +1,4 @@ -package com.redhat.composer.config.retriever.contentRetriever.custom; +package com.redhat.composer.config.retriever.contentretriever.custom; import dev.langchain4j.data.document.Metadata; import dev.langchain4j.data.embedding.Embedding; @@ -37,6 +37,7 @@ * Represents the Weaviate vector database. * Current implementation assumes the cosine distance metric is used. */ +@SuppressWarnings("all") public class WeaviateEmbeddingStoreCustom implements EmbeddingStore { private static final String ADDITIONALS = "_additional"; diff --git a/src/main/java/com/redhat/composer/config/retriever/embeddingModel/BaseLocalEmbeddingModelClient.java b/src/main/java/com/redhat/composer/config/retriever/embeddingmodel/BaseLocalEmbeddingModelClient.java similarity index 79% rename from src/main/java/com/redhat/composer/config/retriever/embeddingModel/BaseLocalEmbeddingModelClient.java rename to src/main/java/com/redhat/composer/config/retriever/embeddingmodel/BaseLocalEmbeddingModelClient.java index cd90388..303ccc3 100644 --- a/src/main/java/com/redhat/composer/config/retriever/embeddingModel/BaseLocalEmbeddingModelClient.java +++ b/src/main/java/com/redhat/composer/config/retriever/embeddingmodel/BaseLocalEmbeddingModelClient.java @@ -1,14 +1,19 @@ -package com.redhat.composer.config.retriever.embeddingModel; +package com.redhat.composer.config.retriever.embeddingmodel; import java.util.concurrent.Executor; import dev.langchain4j.model.embedding.onnx.AbstractInProcessEmbeddingModel; import dev.langchain4j.model.embedding.onnx.OnnxBertBiEncoder; - +/** + * Base Local Embedding Model Client. + */ public class BaseLocalEmbeddingModelClient extends AbstractInProcessEmbeddingModel { - // Add explicit constructor + /** + * Constructor. + * @param executor the Executor + */ public BaseLocalEmbeddingModelClient(Executor executor) { super(executor); } diff --git a/src/main/java/com/redhat/composer/config/retriever/embeddingModel/EmbeddingModelFactory.java b/src/main/java/com/redhat/composer/config/retriever/embeddingmodel/EmbeddingModelFactory.java similarity index 74% rename from src/main/java/com/redhat/composer/config/retriever/embeddingModel/EmbeddingModelFactory.java rename to src/main/java/com/redhat/composer/config/retriever/embeddingmodel/EmbeddingModelFactory.java index 2f6fb6c..7f3a64d 100644 --- a/src/main/java/com/redhat/composer/config/retriever/embeddingModel/EmbeddingModelFactory.java +++ b/src/main/java/com/redhat/composer/config/retriever/embeddingmodel/EmbeddingModelFactory.java @@ -1,9 +1,12 @@ -package com.redhat.composer.config.retriever.embeddingModel; +package com.redhat.composer.config.retriever.embeddingmodel; import dev.langchain4j.model.embedding.EmbeddingModel; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +/** + * Embedding Model Factory. + */ @ApplicationScoped public class EmbeddingModelFactory { @@ -13,8 +16,13 @@ public class EmbeddingModelFactory { public static final String DEFAULT_EMBEDDING = NOMIC_EMBEDDING; + /** + * Get the Embedding Model. + * @param embeddingType the String + * @return the Embedding Model + */ public EmbeddingModel getEmbeddingModel(String embeddingType) { - if(embeddingType == null) { + if (embeddingType == null) { embeddingType = DEFAULT_EMBEDDING; } switch (embeddingType) { diff --git a/src/main/java/com/redhat/composer/config/retriever/embeddingModel/NomicLocalEmbeddingModelClient.java b/src/main/java/com/redhat/composer/config/retriever/embeddingmodel/NomicLocalEmbeddingModelClient.java similarity index 52% rename from src/main/java/com/redhat/composer/config/retriever/embeddingModel/NomicLocalEmbeddingModelClient.java rename to src/main/java/com/redhat/composer/config/retriever/embeddingmodel/NomicLocalEmbeddingModelClient.java index 9027ba6..a949016 100644 --- a/src/main/java/com/redhat/composer/config/retriever/embeddingModel/NomicLocalEmbeddingModelClient.java +++ b/src/main/java/com/redhat/composer/config/retriever/embeddingmodel/NomicLocalEmbeddingModelClient.java @@ -1,14 +1,17 @@ -package com.redhat.composer.config.retriever.embeddingModel; +package com.redhat.composer.config.retriever.embeddingmodel; import dev.langchain4j.model.embedding.onnx.OnnxBertBiEncoder; import dev.langchain4j.model.embedding.onnx.PoolingMode; import io.smallrye.mutiny.infrastructure.Infrastructure; import jakarta.inject.Singleton; +/** + * Nomic Local Embedding Model Client. + */ @Singleton public class NomicLocalEmbeddingModelClient extends BaseLocalEmbeddingModelClient { - private final static String MODEL_FOLDER = "embeddings/nomic/"; + private static final String MODEL_FOLDER = "embeddings/nomic/"; private static final OnnxBertBiEncoder MODEL = loadFromJar( @@ -17,14 +20,21 @@ public class NomicLocalEmbeddingModelClient extends BaseLocalEmbeddingModelClien PoolingMode.CLS ); - public NomicLocalEmbeddingModelClient() { - super(Infrastructure.getDefaultExecutor()); - } - - - @Override - protected OnnxBertBiEncoder model() { - return MODEL; - } + /** + * Constructor. + */ + public NomicLocalEmbeddingModelClient() { + super(Infrastructure.getDefaultExecutor()); + } + + + /** + * Get the Model Folder. + * @return the Model Folder + */ + @Override + protected OnnxBertBiEncoder model() { + return MODEL; + } } diff --git a/src/main/java/com/redhat/composer/model/enums/ContentRetrieverType.java b/src/main/java/com/redhat/composer/model/enums/ContentRetrieverType.java index c23f889..a9e0a25 100644 --- a/src/main/java/com/redhat/composer/model/enums/ContentRetrieverType.java +++ b/src/main/java/com/redhat/composer/model/enums/ContentRetrieverType.java @@ -1,27 +1,35 @@ package com.redhat.composer.model.enums; +/** + * Content Retriever Type. + */ public enum ContentRetrieverType { - WEAVIATE("weaviate"), - NEO4J("neo4j"); + WEAVIATE("weaviate"), + NEO4J("neo4j"); - private final String type; + private final String type; - ContentRetrieverType(String type) { - this.type = type; - } + ContentRetrieverType(String type) { + this.type = type; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - public static ContentRetrieverType fromString(String type) { - for (ContentRetrieverType retrieverType : ContentRetrieverType.values()) { - if (retrieverType.getType().equalsIgnoreCase(type)) { - return retrieverType; - } - } - throw new IllegalArgumentException("No constant with type " + type + " found"); + /** + * Get the Content Retriever Type from String. + * @param type string representation of the type + * @return the ContentRetrieverType + */ + public static ContentRetrieverType fromString(String type) { + for (ContentRetrieverType retrieverType : ContentRetrieverType.values()) { + if (retrieverType.getType().equalsIgnoreCase(type)) { + return retrieverType; + } } + throw new IllegalArgumentException("No constant with type " + type + " found"); + } } diff --git a/src/main/java/com/redhat/composer/model/mongo/BaseEntity.java b/src/main/java/com/redhat/composer/model/mongo/BaseEntity.java index 552bb4a..c25c537 100644 --- a/src/main/java/com/redhat/composer/model/mongo/BaseEntity.java +++ b/src/main/java/com/redhat/composer/model/mongo/BaseEntity.java @@ -7,6 +7,9 @@ import io.quarkus.mongodb.panache.PanacheMongoEntity; +/** + * BaseEntity. + */ public class BaseEntity extends PanacheMongoEntity { diff --git a/src/main/java/com/redhat/composer/model/mongo/LLMConnectionEntity.java b/src/main/java/com/redhat/composer/model/mongo/LlmConnectionEntity.java similarity index 80% rename from src/main/java/com/redhat/composer/model/mongo/LLMConnectionEntity.java rename to src/main/java/com/redhat/composer/model/mongo/LlmConnectionEntity.java index 8676fdd..b40f4de 100644 --- a/src/main/java/com/redhat/composer/model/mongo/LLMConnectionEntity.java +++ b/src/main/java/com/redhat/composer/model/mongo/LlmConnectionEntity.java @@ -6,8 +6,13 @@ import io.quarkus.mongodb.panache.common.MongoEntity; +/** + * LlmConnectionEntity + */ +// CHECKSTYLE +@SuppressWarnings("all") @MongoEntity(collection = "llm_connection") -public class LLMConnectionEntity extends BaseEntity { +public class LlmConnectionEntity extends BaseEntity { private String name; @@ -20,10 +25,10 @@ public class LLMConnectionEntity extends BaseEntity { private String modelName; - public LLMConnectionEntity() { + public LlmConnectionEntity() { } - public LLMConnectionEntity(String name, String description, String modelType, String url, String apiKey, String modelName) { + public LlmConnectionEntity(String name, String description, String modelType, String url, String apiKey, String modelName) { this.name = name; this.description = description; this.modelType = modelType; @@ -80,32 +85,32 @@ public void setModelName(String modelName) { this.modelName = modelName; } - public LLMConnectionEntity name(String name) { + public LlmConnectionEntity name(String name) { setName(name); return this; } - public LLMConnectionEntity description(String description) { + public LlmConnectionEntity description(String description) { setDescription(description); return this; } - public LLMConnectionEntity modelType(String modelType) { + public LlmConnectionEntity modelType(String modelType) { setModelType(modelType); return this; } - public LLMConnectionEntity url(String url) { + public LlmConnectionEntity url(String url) { setUrl(url); return this; } - public LLMConnectionEntity apiKey(String apiKey) { + public LlmConnectionEntity apiKey(String apiKey) { setApiKey(apiKey); return this; } - public LLMConnectionEntity modelName(String modelName) { + public LlmConnectionEntity modelName(String modelName) { setModelName(modelName); return this; } diff --git a/src/main/java/com/redhat/composer/model/mongo/RetrieverConnectionEntity.java b/src/main/java/com/redhat/composer/model/mongo/RetrieverConnectionEntity.java index d06c740..04cc8b2 100644 --- a/src/main/java/com/redhat/composer/model/mongo/RetrieverConnectionEntity.java +++ b/src/main/java/com/redhat/composer/model/mongo/RetrieverConnectionEntity.java @@ -4,11 +4,14 @@ import org.apache.commons.lang3.builder.EqualsBuilder; -import com.redhat.composer.model.mongo.contentRetrieverEntites.BaseRetrieverConnectionEntity; +import com.redhat.composer.model.mongo.contentretrieverentites.BaseRetrieverConnectionEntity; import io.quarkus.mongodb.panache.common.MongoEntity; - +/** + * RetrieverConnectionEntity + */ +@SuppressWarnings("all") @MongoEntity(collection = "retriever_connection") public class RetrieverConnectionEntity extends BaseEntity { diff --git a/src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/Neo4JEntity.java b/src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/Neo4JEntity.java deleted file mode 100644 index b559c50..0000000 --- a/src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/Neo4JEntity.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.redhat.composer.model.mongo.contentRetrieverEntites; - -import org.bson.codecs.pojo.annotations.BsonDiscriminator; - -@BsonDiscriminator("neo4j") -public class Neo4JEntity extends BaseRetrieverConnectionEntity { - -} diff --git a/src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/BaseRetrieverConnectionEntity.java b/src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/BaseRetrieverConnectionEntity.java similarity index 63% rename from src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/BaseRetrieverConnectionEntity.java rename to src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/BaseRetrieverConnectionEntity.java index 3a0c0ba..ae99ca4 100644 --- a/src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/BaseRetrieverConnectionEntity.java +++ b/src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/BaseRetrieverConnectionEntity.java @@ -1,21 +1,36 @@ -package com.redhat.composer.model.mongo.contentRetrieverEntites; +package com.redhat.composer.model.mongo.contentretrieverentites; + import org.bson.codecs.pojo.annotations.BsonDiscriminator; import com.redhat.composer.model.enums.ContentRetrieverType; +/** + * Base Retriever Connection Entity. + */ +@SuppressWarnings("all") @BsonDiscriminator public class BaseRetrieverConnectionEntity { ContentRetrieverType contentRetrieverType; - + /** + * Constructor. + */ public BaseRetrieverConnectionEntity() { } + /** + * Constructor. + * @param contentRetrieverType the ContentRetrieverType + */ public BaseRetrieverConnectionEntity(ContentRetrieverType contentRetrieverType) { this.contentRetrieverType = contentRetrieverType; } + /** + * Get the Content Retriever Type. + * @return the ContentRetrieverType + */ public ContentRetrieverType getContentRetrieverType() { return this.contentRetrieverType; } @@ -24,6 +39,11 @@ public void setContentRetrieverType(ContentRetrieverType contentRetrieverType) { this.contentRetrieverType = contentRetrieverType; } + /** + * Set the Content Retriever Type. + * @param contentRetrieverType the ContentRetrieverType + * @return BaseRetrieverConnectionEntity + */ public BaseRetrieverConnectionEntity contentRetrieverType(ContentRetrieverType contentRetrieverType) { setContentRetrieverType(contentRetrieverType); return this; diff --git a/src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/Neo4jEntity.java b/src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/Neo4jEntity.java new file mode 100644 index 0000000..38aa0e6 --- /dev/null +++ b/src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/Neo4jEntity.java @@ -0,0 +1,12 @@ +package com.redhat.composer.model.mongo.contentretrieverentites; + +import org.bson.codecs.pojo.annotations.BsonDiscriminator; + +/** + * Neo4J Entity. + */ +@SuppressWarnings("all") +@BsonDiscriminator("neo4j") +public class Neo4jEntity extends BaseRetrieverConnectionEntity { + +} diff --git a/src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/WeaviateConnectionEntity.java b/src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/WeaviateConnectionEntity.java similarity index 93% rename from src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/WeaviateConnectionEntity.java rename to src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/WeaviateConnectionEntity.java index ee31ba5..a292a8e 100644 --- a/src/main/java/com/redhat/composer/model/mongo/contentRetrieverEntites/WeaviateConnectionEntity.java +++ b/src/main/java/com/redhat/composer/model/mongo/contentretrieverentites/WeaviateConnectionEntity.java @@ -1,4 +1,4 @@ -package com.redhat.composer.model.mongo.contentRetrieverEntites; +package com.redhat.composer.model.mongo.contentretrieverentites; import org.apache.commons.lang3.builder.EqualsBuilder; import org.bson.codecs.pojo.annotations.BsonDiscriminator; @@ -8,6 +8,10 @@ import java.util.List; import java.util.Objects; +/** + * Weaviate Connection Entity. + */ +@SuppressWarnings("all") @BsonDiscriminator("weaviate") public class WeaviateConnectionEntity extends BaseRetrieverConnectionEntity { @@ -25,7 +29,6 @@ public class WeaviateConnectionEntity extends BaseRetrieverConnectionEntity { String apiKey; - public WeaviateConnectionEntity() { contentRetrieverType = ContentRetrieverType.WEAVIATE; } @@ -110,7 +113,7 @@ public WeaviateConnectionEntity apiKey(String apiKey) { @Override public boolean equals(Object o) { - return EqualsBuilder.reflectionEquals(this, o); + return EqualsBuilder.reflectionEquals(this, o); } @Override diff --git a/src/main/java/com/redhat/composer/model/request/AssistantChatRequest.java b/src/main/java/com/redhat/composer/model/request/AssistantChatRequest.java index d157a40..e9d4952 100644 --- a/src/main/java/com/redhat/composer/model/request/AssistantChatRequest.java +++ b/src/main/java/com/redhat/composer/model/request/AssistantChatRequest.java @@ -1,8 +1,10 @@ package com.redhat.composer.model.request; + import java.util.Objects; import org.apache.commons.lang3.builder.EqualsBuilder; +@SuppressWarnings("all") public class AssistantChatRequest{ private String message = ""; diff --git a/src/main/java/com/redhat/composer/model/request/AssistantCreationRequest.java b/src/main/java/com/redhat/composer/model/request/AssistantCreationRequest.java index e8da730..63ed20e 100644 --- a/src/main/java/com/redhat/composer/model/request/AssistantCreationRequest.java +++ b/src/main/java/com/redhat/composer/model/request/AssistantCreationRequest.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder; +@SuppressWarnings("all") public class AssistantCreationRequest { String name; diff --git a/src/main/java/com/redhat/composer/model/request/ChatBotRequest.java b/src/main/java/com/redhat/composer/model/request/ChatBotRequest.java index 33362bf..95ed2fe 100644 --- a/src/main/java/com/redhat/composer/model/request/ChatBotRequest.java +++ b/src/main/java/com/redhat/composer/model/request/ChatBotRequest.java @@ -3,6 +3,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder; +@SuppressWarnings("all") public class ChatBotRequest{ private String message = ""; diff --git a/src/main/java/com/redhat/composer/model/request/LLMRequest.java b/src/main/java/com/redhat/composer/model/request/LLMRequest.java index 1b46b59..d692ed3 100644 --- a/src/main/java/com/redhat/composer/model/request/LLMRequest.java +++ b/src/main/java/com/redhat/composer/model/request/LLMRequest.java @@ -6,6 +6,7 @@ import com.redhat.composer.config.llm.models.streaming.StreamingModelFactory; +@SuppressWarnings("all") public class LLMRequest { private String name; diff --git a/src/main/java/com/redhat/composer/model/request/RetrieverRequest.java b/src/main/java/com/redhat/composer/model/request/RetrieverRequest.java index a16b710..d50f251 100644 --- a/src/main/java/com/redhat/composer/model/request/RetrieverRequest.java +++ b/src/main/java/com/redhat/composer/model/request/RetrieverRequest.java @@ -5,6 +5,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder; +@SuppressWarnings("all") public class RetrieverRequest { BaseRetrieverRequest baseRetrieverRequest; diff --git a/src/main/java/com/redhat/composer/model/request/retriever/BaseRetrieverRequest.java b/src/main/java/com/redhat/composer/model/request/retriever/BaseRetrieverRequest.java index 894af54..891af7a 100644 --- a/src/main/java/com/redhat/composer/model/request/retriever/BaseRetrieverRequest.java +++ b/src/main/java/com/redhat/composer/model/request/retriever/BaseRetrieverRequest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +@SuppressWarnings("all") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "contentRetrieverType", visible = true) @JsonSubTypes({ @JsonSubTypes.Type(value = WeaviateRequest.class, name = "weaviate"), diff --git a/src/main/java/com/redhat/composer/model/request/retriever/Neo4JRequest.java b/src/main/java/com/redhat/composer/model/request/retriever/Neo4JRequest.java index bdd57ad..eb0f7ed 100644 --- a/src/main/java/com/redhat/composer/model/request/retriever/Neo4JRequest.java +++ b/src/main/java/com/redhat/composer/model/request/retriever/Neo4JRequest.java @@ -1,5 +1,6 @@ package com.redhat.composer.model.request.retriever; +@SuppressWarnings("all") public class Neo4JRequest extends BaseRetrieverRequest { diff --git a/src/main/java/com/redhat/composer/model/request/retriever/WeaviateRequest.java b/src/main/java/com/redhat/composer/model/request/retriever/WeaviateRequest.java index 9752fdd..1557932 100644 --- a/src/main/java/com/redhat/composer/model/request/retriever/WeaviateRequest.java +++ b/src/main/java/com/redhat/composer/model/request/retriever/WeaviateRequest.java @@ -7,6 +7,7 @@ import com.redhat.composer.model.enums.ContentRetrieverType; +@SuppressWarnings("all") public class WeaviateRequest extends BaseRetrieverRequest { // Key of the value containing the text used for retrieval and passed into the LLM diff --git a/src/main/java/com/redhat/composer/model/response/AssistantResponse.java b/src/main/java/com/redhat/composer/model/response/AssistantResponse.java index a4195f3..efb0bad 100644 --- a/src/main/java/com/redhat/composer/model/response/AssistantResponse.java +++ b/src/main/java/com/redhat/composer/model/response/AssistantResponse.java @@ -5,12 +5,13 @@ import org.apache.commons.lang3.builder.EqualsBuilder; import com.redhat.composer.model.mongo.AssistantEntity; -import com.redhat.composer.model.mongo.LLMConnectionEntity; +import com.redhat.composer.model.mongo.LlmConnectionEntity; import com.redhat.composer.model.mongo.RetrieverConnectionEntity; +@SuppressWarnings("all") public class AssistantResponse extends AssistantEntity { - private LLMConnectionEntity llmConnection; + private LlmConnectionEntity llmConnection; private RetrieverConnectionEntity retrieverConnection; @@ -18,16 +19,16 @@ public AssistantResponse() { } - public AssistantResponse(LLMConnectionEntity llmConnection, RetrieverConnectionEntity retrieverConnection) { + public AssistantResponse(LlmConnectionEntity llmConnection, RetrieverConnectionEntity retrieverConnection) { this.llmConnection = llmConnection; this.retrieverConnection = retrieverConnection; } - public LLMConnectionEntity getLlmConnection() { + public LlmConnectionEntity getLlmConnection() { return this.llmConnection; } - public void setLlmConnection(LLMConnectionEntity llmConnection) { + public void setLlmConnection(LlmConnectionEntity llmConnection) { this.llmConnection = llmConnection; } @@ -39,7 +40,7 @@ public void setRetrieverConnection(RetrieverConnectionEntity retrieverConnection this.retrieverConnection = retrieverConnection; } - public AssistantResponse llmConnection(LLMConnectionEntity llmConnection) { + public AssistantResponse llmConnection(LlmConnectionEntity llmConnection) { setLlmConnection(llmConnection); return this; } diff --git a/src/main/java/com/redhat/composer/model/response/ContentResponse.java b/src/main/java/com/redhat/composer/model/response/ContentResponse.java index 85f148f..d0c803d 100644 --- a/src/main/java/com/redhat/composer/model/response/ContentResponse.java +++ b/src/main/java/com/redhat/composer/model/response/ContentResponse.java @@ -8,7 +8,7 @@ import dev.langchain4j.rag.content.Content; - +@SuppressWarnings("all") public class ContentResponse { @JsonProperty("content") diff --git a/src/main/java/com/redhat/composer/model/response/SourceResponse.java b/src/main/java/com/redhat/composer/model/response/SourceResponse.java index 0b60cb0..374a3e1 100644 --- a/src/main/java/com/redhat/composer/model/response/SourceResponse.java +++ b/src/main/java/com/redhat/composer/model/response/SourceResponse.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.builder.EqualsBuilder; +@SuppressWarnings("all") public class SourceResponse { private String content; diff --git a/src/main/java/com/redhat/composer/repositories/AssistantRepository.java b/src/main/java/com/redhat/composer/repositories/AssistantRepository.java index 14a14fa..a3ffae8 100644 --- a/src/main/java/com/redhat/composer/repositories/AssistantRepository.java +++ b/src/main/java/com/redhat/composer/repositories/AssistantRepository.java @@ -5,11 +5,19 @@ import io.quarkus.mongodb.panache.PanacheMongoRepository; import jakarta.enterprise.context.ApplicationScoped; +/** + * Assistant Repository. + */ @ApplicationScoped public class AssistantRepository implements PanacheMongoRepository { - + + /** + * Find an Assistant by name. + * @param name the name of the Assistant + * @return the AssistantEntity + */ public AssistantEntity findByName(String name) { - return find("name", name).firstResult(); - } + return find("name", name).firstResult(); + } } diff --git a/src/main/java/com/redhat/composer/services/AssistantInfoService.java b/src/main/java/com/redhat/composer/services/AssistantInfoService.java index 290ae5a..b4b08fa 100644 --- a/src/main/java/com/redhat/composer/services/AssistantInfoService.java +++ b/src/main/java/com/redhat/composer/services/AssistantInfoService.java @@ -6,7 +6,7 @@ import org.bson.types.ObjectId; import com.redhat.composer.model.mongo.AssistantEntity; -import com.redhat.composer.model.mongo.LLMConnectionEntity; +import com.redhat.composer.model.mongo.LlmConnectionEntity; import com.redhat.composer.model.mongo.RetrieverConnectionEntity; import com.redhat.composer.model.request.AssistantCreationRequest; import com.redhat.composer.model.request.LLMRequest; @@ -17,31 +17,45 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -// TODO: Set up MapStruct service or something -// https://mapstruct.org/ - +/** + * AssistantInfoService. + */ @ApplicationScoped public class AssistantInfoService { @Inject MapperUtil mapperUtil; + /** + * Create an Assistant. + * @param request the AssistantCreationRequest + * @return the AssistantEntity + */ public AssistantEntity createAssistant(AssistantCreationRequest request) { AssistantEntity assistant = new AssistantEntity(); + LlmConnectionEntity llm = (LlmConnectionEntity) LlmConnectionEntity.findByIdOptional( + new ObjectId(request.getLlmConnectionId())) + .orElseThrow(() -> new IllegalArgumentException("LLM Connection not found")); - LLMConnectionEntity llm = (LLMConnectionEntity) LLMConnectionEntity.findByIdOptional(new ObjectId(request.getLlmConnectionId())).orElseThrow(() -> new IllegalArgumentException("LLM Connection not found")); + assistant.setLlmConnectionId(llm.id); + if (request.getRetrieverConnectionId() != null) { - RetrieverConnectionEntity retriever = (RetrieverConnectionEntity) RetrieverConnectionEntity.findByIdOptional(new ObjectId(request.getRetrieverConnectionId())).orElseThrow(() -> new IllegalArgumentException("Retriever Connection not found")); + RetrieverConnectionEntity retriever = (RetrieverConnectionEntity) RetrieverConnectionEntity + .findByIdOptional(new ObjectId(request.getRetrieverConnectionId())) + .orElseThrow(() -> new IllegalArgumentException("Retriever Connection not found")); assistant.setRetrieverConnectionId(retriever.id); } assistant.setName(request.getName()); assistant.setDisplayName(request.getDisplayName()); assistant.setDescription(request.getDescription()); - assistant.setLlmConnectionId(llm.id); assistant.persist(); return assistant; } + /** + * Get all Assistants. + * @return a list of AssistantResponse + */ public List getAssistant() { Stream stream = AssistantEntity.streamAll(); return stream.map(entity -> { @@ -50,13 +64,18 @@ public List getAssistant() { response.setName(entity.getName()); response.setDisplayName(entity.getDisplayName()); response.setDescription(entity.getDescription()); - response.setLlmConnection(LLMConnectionEntity.findById(entity.getLlmConnectionId())); + response.setLlmConnection(LlmConnectionEntity.findById(entity.getLlmConnectionId())); response.setRetrieverConnection(RetrieverConnectionEntity.findById(entity.getRetrieverConnectionId())); return response; } ).toList(); } + /** + * Create a RetrieverConnectionEntity. + * @param request the RetrieverRequest + * @return the RetrieverConnectionEntity + */ public RetrieverConnectionEntity createRetrieverConnectionEntity(RetrieverRequest request) { RetrieverConnectionEntity entity = mapperUtil.toEntity(request); entity.persist(); @@ -66,9 +85,14 @@ public RetrieverConnectionEntity createRetrieverConnectionEntity(RetrieverReques public List getRetrieverConnections() { return RetrieverConnectionEntity.listAll(); } - - public LLMConnectionEntity createLLMConnection(LLMRequest request) { - LLMConnectionEntity entity = new LLMConnectionEntity(); + + /** + * Create a LLMConnectionEntity. + * @param request the LLMRequest + * @return the LLMConnectionEntity + */ + public LlmConnectionEntity createLlmConnection(LLMRequest request) { + LlmConnectionEntity entity = new LlmConnectionEntity(); entity.setName(request.getName()); entity.setDescription(request.getDescription()); entity.setUrl(request.getUrl()); @@ -78,8 +102,12 @@ public LLMConnectionEntity createLLMConnection(LLMRequest request) { return entity; } - public List getLLMConnections() { - return LLMConnectionEntity.listAll(); + /** + * Get all LLMConnections. + * @return a list of LlmConnectionEntity + */ + public List getLlmConnections() { + return LlmConnectionEntity.listAll(); } } diff --git a/src/main/java/com/redhat/composer/services/ChatBotService.java b/src/main/java/com/redhat/composer/services/ChatBotService.java index 748d5d9..28eebb4 100644 --- a/src/main/java/com/redhat/composer/services/ChatBotService.java +++ b/src/main/java/com/redhat/composer/services/ChatBotService.java @@ -1,17 +1,14 @@ package com.redhat.composer.services; -import java.util.ArrayList; -import java.util.List; - import org.jboss.logging.Logger; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.redhat.composer.config.llm.aiservices.AIServicesFactory; -import com.redhat.composer.config.llm.aiservices.BaseAIService; +import com.redhat.composer.config.llm.aiservices.AiServicesFactory; +import com.redhat.composer.config.llm.aiservices.BaseAiService; import com.redhat.composer.config.llm.models.streaming.StreamingModelFactory; import com.redhat.composer.model.mongo.AssistantEntity; -import com.redhat.composer.model.mongo.LLMConnectionEntity; +import com.redhat.composer.model.mongo.LlmConnectionEntity; import com.redhat.composer.model.mongo.RetrieverConnectionEntity; import com.redhat.composer.model.request.AssistantChatRequest; import com.redhat.composer.model.request.ChatBotRequest; @@ -20,7 +17,6 @@ import com.redhat.composer.util.mappers.MapperUtil; import dev.langchain4j.model.chat.StreamingChatLanguageModel; -import dev.langchain4j.rag.content.Content; import dev.langchain4j.service.AiServices; import io.opentelemetry.api.trace.Span; import io.quarkus.runtime.util.StringUtil; @@ -28,6 +24,9 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +/** + * ChatBotService class. + */ @ApplicationScoped public class ChatBotService { @@ -37,7 +36,7 @@ public class ChatBotService { StreamingModelFactory modelTemplateFactory; @Inject - AIServicesFactory aiServicesFactory; + AiServicesFactory aiServicesFactory; @Inject RetrieveService ragService; @@ -51,18 +50,26 @@ public class ChatBotService { @Inject ObjectMapper objectMapper; + /** + * Chat with an assistant. + * @param request the AssistantChatRequest + * @return stream of chat response + */ public Multi chat(AssistantChatRequest request) { AssistantEntity assistant; - if(!StringUtil.isNullOrEmpty(request.getAssistantName())) { - assistant = assistantRepository.findByName(request.getAssistantName()); - } else if(!StringUtil.isNullOrEmpty(request.getAssistantId())) { + if (!StringUtil.isNullOrEmpty(request.getAssistantName())) { + assistant = assistantRepository.findByName(request.getAssistantName()); + } else if (!StringUtil.isNullOrEmpty(request.getAssistantId())) { assistant = AssistantEntity.findById(request.getAssistantId()); } else { throw new RuntimeException("Assistant Name or ID Required"); } - LLMConnectionEntity llmConnection = LLMConnectionEntity.findById(assistant.getLlmConnectionId()); - RetrieverConnectionEntity retrieverConnection = RetrieverConnectionEntity.findById(assistant.getRetrieverConnectionId()); + + LlmConnectionEntity llmConnection = LlmConnectionEntity.findById(assistant.getLlmConnectionId()); + + RetrieverConnectionEntity retrieverConnection = RetrieverConnectionEntity + .findById(assistant.getRetrieverConnectionId()); ChatBotRequest chatBotRequest = new ChatBotRequest(); chatBotRequest.setMessage(request.getMessage()); @@ -73,6 +80,11 @@ public Multi chat(AssistantChatRequest request) { return chat(chatBotRequest); } + /** + * Chat with a model. + * @param request the ChatBotRequest + * @return stream of chat response + */ public Multi chat(ChatBotRequest request) { String traceId = Span.current().getSpanContext().getTraceId(); @@ -80,21 +92,20 @@ public Multi chat(ChatBotRequest request) { validateRequest(request); StreamingChatLanguageModel llm = modelTemplateFactory.getModel(request.getModelRequest().getModelType()) - .getChatModel(request.getModelRequest()); + .getChatModel(request.getModelRequest()); - // TODO: Make this configurable - Class aiServiceClass = aiServicesFactory.getAiService(AIServicesFactory.MISTRAL7B_AI_SERVICE); + // TODO: Make this configurable + Class aiServiceClass = aiServicesFactory + .getAiService(AiServicesFactory.MISTRAL7B_AI_SERVICE); - AiServices builder = AiServices.builder(aiServiceClass) + AiServices builder = AiServices.builder(aiServiceClass) .streamingChatLanguageModel(llm); - if(request.getRetrieverRequest() != null) { - builder.contentRetriever(ragService.getContentRetriever(request.getRetrieverRequest())); + if (request.getRetrieverRequest() != null) { + builder.contentRetriever(ragService.getContentRetriever(request.getRetrieverRequest())); } - BaseAIService aiService = builder.build(); - - + BaseAiService aiService = builder.build(); try { Multi multi = Multi.createFrom().emitter(em -> { @@ -111,20 +122,21 @@ public Multi chat(ChatBotRequest request) { }) .onError(em::fail) .onComplete(response -> { - em.complete();}) - .start(); - }); + em.complete(); + }) + .start(); + }); return multi; } catch (Exception e) { - log.error("Error in ChatBotService.chat", e); - return Multi.createFrom().failure(e); - } + log.error("Error in ChatBotService.chat", e); + return Multi.createFrom().failure(e); + } } // TODO: Support non-streaming chat? private void validateRequest(ChatBotRequest request) { - if(request.getMessage() == null) { + if (request.getMessage() == null) { throw new RuntimeException("Request Message Required"); } } diff --git a/src/main/java/com/redhat/composer/services/EmbeddingService.java b/src/main/java/com/redhat/composer/services/EmbeddingService.java index c9de112..b81fd68 100644 --- a/src/main/java/com/redhat/composer/services/EmbeddingService.java +++ b/src/main/java/com/redhat/composer/services/EmbeddingService.java @@ -2,7 +2,7 @@ import org.jboss.logging.Logger; -import com.redhat.composer.config.retriever.embeddingModel.EmbeddingModelFactory; +import com.redhat.composer.config.retriever.embeddingmodel.EmbeddingModelFactory; import dev.langchain4j.data.embedding.Embedding; import dev.langchain4j.model.embedding.EmbeddingModel; @@ -16,15 +16,19 @@ @ApplicationScoped public class EmbeddingService { - private static final Logger logger = Logger.getLogger(EmbeddingService.class); - @Inject EmbeddingModelFactory embeddingTemplateFactory; + /** + * Embeds the given text using the specified embedding model. + * @param text the text to embed + * @param embeddingType the type of embedding model to use + * @return the embedded text + */ public Embedding embedding(String text, String embeddingType) { EmbeddingModel embedding = embeddingTemplateFactory.getEmbeddingModel(embeddingType); Response response = embedding.embed(text); return response.content(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/redhat/composer/services/RetrieveService.java b/src/main/java/com/redhat/composer/services/RetrieveService.java index e263645..5a1482a 100644 --- a/src/main/java/com/redhat/composer/services/RetrieveService.java +++ b/src/main/java/com/redhat/composer/services/RetrieveService.java @@ -2,8 +2,8 @@ import java.util.List; -import com.redhat.composer.config.retriever.contentRetriever.BaseContentRetrieverClient; -import com.redhat.composer.config.retriever.contentRetriever.ContentRetrieverClientFactory; +import com.redhat.composer.config.retriever.contentretriever.BaseContentRetrieverClient; +import com.redhat.composer.config.retriever.contentretriever.ContentRetrieverClientFactory; import com.redhat.composer.model.enums.ContentRetrieverType; import com.redhat.composer.model.request.RetrieverRequest; @@ -13,19 +13,35 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +/** + * Service for retrieving content. + */ @ApplicationScoped public class RetrieveService { @Inject ContentRetrieverClientFactory contentRetrieverClientFactory; + /** + * Retrieves content from a given message. + * @param request the request to retrieve content + * @return the retrieved content + */ public ContentRetriever getContentRetriever(RetrieverRequest request) { - ContentRetrieverType contentRetrieverType = ContentRetrieverType.fromString(request.getBaseRetrieverRequest().getContentRetrieverType()); - BaseContentRetrieverClient client = contentRetrieverClientFactory.getContentRetrieverClient(contentRetrieverType); //TODO: Fix this + ContentRetrieverType contentRetrieverType = ContentRetrieverType.fromString( + request.getBaseRetrieverRequest().getContentRetrieverType()); + BaseContentRetrieverClient client = contentRetrieverClientFactory + .getContentRetrieverClient(contentRetrieverType); return client.getContentRetriever(request); } + /** + * Retrieves content from a given message. + * @param request the request to retrieve content + * @param message the message to retrieve content from + * @return the retrieved content + */ public List retrieveContent(RetrieverRequest request, String message) { ContentRetriever contentRetriever = getContentRetriever(request); Query query = Query.from(message); diff --git a/src/main/java/com/redhat/composer/util/DisabledAuthController.java b/src/main/java/com/redhat/composer/util/DisabledAuthController.java index d52f857..f263b63 100644 --- a/src/main/java/com/redhat/composer/util/DisabledAuthController.java +++ b/src/main/java/com/redhat/composer/util/DisabledAuthController.java @@ -1,7 +1,5 @@ package com.redhat.composer.util; - - import org.eclipse.microprofile.config.inject.ConfigProperty; import io.quarkus.security.spi.runtime.AuthorizationController; @@ -11,16 +9,19 @@ import jakarta.interceptor.Interceptor; -// TODO: Remove this class once we have the frontend setup +/** + * Disabled Authorization Controller. + */ @Alternative @Priority(Interceptor.Priority.LIBRARY_AFTER) @ApplicationScoped public class DisabledAuthController extends AuthorizationController { - @ConfigProperty(name = "disable.authorization", defaultValue = "false") - boolean disableAuthorization; - @Override - public boolean isAuthorizationEnabled() { - return !disableAuthorization; - } + @ConfigProperty(name = "disable.authorization", defaultValue = "false") + boolean disableAuthorization; + + @Override + public boolean isAuthorizationEnabled() { + return !disableAuthorization; + } } \ No newline at end of file diff --git a/src/main/java/com/redhat/composer/util/mappers/MapperUtil.java b/src/main/java/com/redhat/composer/util/mappers/MapperUtil.java index ead1774..85c08cf 100644 --- a/src/main/java/com/redhat/composer/util/mappers/MapperUtil.java +++ b/src/main/java/com/redhat/composer/util/mappers/MapperUtil.java @@ -2,14 +2,15 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import com.redhat.composer.model.enums.ContentRetrieverType; -import com.redhat.composer.model.mongo.LLMConnectionEntity; +import com.redhat.composer.model.mongo.LlmConnectionEntity; import com.redhat.composer.model.mongo.RetrieverConnectionEntity; -import com.redhat.composer.model.mongo.contentRetrieverEntites.BaseRetrieverConnectionEntity; -import com.redhat.composer.model.mongo.contentRetrieverEntites.Neo4JEntity; -import com.redhat.composer.model.mongo.contentRetrieverEntites.WeaviateConnectionEntity; +import com.redhat.composer.model.mongo.contentretrieverentites.BaseRetrieverConnectionEntity; +import com.redhat.composer.model.mongo.contentretrieverentites.Neo4jEntity; +import com.redhat.composer.model.mongo.contentretrieverentites.WeaviateConnectionEntity; import com.redhat.composer.model.request.LLMRequest; import com.redhat.composer.model.request.RetrieverRequest; import com.redhat.composer.model.request.retriever.BaseRetrieverRequest; @@ -18,26 +19,59 @@ import jakarta.enterprise.inject.Default; +/** + * MapperUtil interface. + */ @Default @Mapper(config = QuarkusMapperConfig.class) public interface MapperUtil { RetrieverConnectionMapper retrieverConnectionMapper = Mappers.getMapper(RetrieverConnectionMapper.class); - @Mapping(target = "connectionEntity", source = "baseRetrieverRequest") + /** + * Maps a RetrieverRequest to a RetrieverConnectionEntity. + */ + @Mappings({ + @Mapping(target = "connectionEntity", source = "baseRetrieverRequest"), + @Mapping(target = "id", ignore = true) + }) RetrieverConnectionEntity toEntity(RetrieverRequest request); - @Mapping(source = "connectionEntity", target = "baseRetrieverRequest") - RetrieverRequest toRequest(RetrieverConnectionEntity entity); + /** + * Maps a LLMRequest to a LLMConnectionEntity. + * @param request the LLMRequest to map + * @return the LLMConnectionEntity + */ + @Mapping(target = "id", ignore = true) + LlmConnectionEntity toEntity(LLMRequest request); - LLMConnectionEntity toEntity(LLMRequest request); - LLMRequest toRequest(LLMConnectionEntity entity); + /** + * Maps a RetrieverConnectionEntity to a RetrieverRequest. + * @param entity the RetrieverConnectionEntity to map + * @return the RetrieverRequest + */ + @Mapping(source = "connectionEntity", target = "baseRetrieverRequest") + RetrieverRequest toRequest(RetrieverConnectionEntity entity); + + /** + * Maps a LLMConnectionEntity to a LLMRequest. + * @param entity the LLMConnectionEntity to map + * @return the LLMRequest + */ + LLMRequest toRequest(LlmConnectionEntity entity); + /** + * Maps a BaseRetrieverRequest to a BaseRetrieverConnectionEntity. + * @param request the BaseRetrieverRequest to map + * @return the BaseRetrieverConnectionEntity + */ default BaseRetrieverConnectionEntity mapToBaseEntity(BaseRetrieverRequest request) { - if(request == null) { + + if (request == null) { return null; } + switch (ContentRetrieverType.fromString(request.getContentRetrieverType())) { case ContentRetrieverType.WEAVIATE: return retrieverConnectionMapper.toEntity((WeaviateRequest) request); @@ -48,19 +82,27 @@ default BaseRetrieverConnectionEntity mapToBaseEntity(BaseRetrieverRequest reque } } - default BaseRetrieverRequest mapToBaseRequest(BaseRetrieverConnectionEntity entity){ - if(entity == null || entity.getContentRetrieverType() == null) { + /** + * Maps a BaseRetrieverConnectionEntity to a BaseRetrieverRequest. + + * @param entity the BaseRetrieverConnectionEntity to map + * @return the BaseRetrieverRequest + */ + default BaseRetrieverRequest mapToBaseRequest(BaseRetrieverConnectionEntity entity) { + + if (entity == null || entity.getContentRetrieverType() == null) { return null; } + switch (entity.getContentRetrieverType()) { case ContentRetrieverType.WEAVIATE: return retrieverConnectionMapper.toRequest((WeaviateConnectionEntity) entity); case ContentRetrieverType.NEO4J: - return retrieverConnectionMapper.toRequest((Neo4JEntity) entity); + return retrieverConnectionMapper.toRequest((Neo4jEntity) entity); default: return null; } } - + } diff --git a/src/main/java/com/redhat/composer/util/mappers/QuarkusMapperConfig.java b/src/main/java/com/redhat/composer/util/mappers/QuarkusMapperConfig.java index 0a0d054..91a110e 100644 --- a/src/main/java/com/redhat/composer/util/mappers/QuarkusMapperConfig.java +++ b/src/main/java/com/redhat/composer/util/mappers/QuarkusMapperConfig.java @@ -2,8 +2,9 @@ import org.mapstruct.MapperConfig; +/** + * Quarkus Mapper Config. + */ @MapperConfig(componentModel = "cdi") public interface QuarkusMapperConfig { - - -} +} diff --git a/src/main/java/com/redhat/composer/util/mappers/RetrieverConnectionMapper.java b/src/main/java/com/redhat/composer/util/mappers/RetrieverConnectionMapper.java index 680ccfc..66ec816 100644 --- a/src/main/java/com/redhat/composer/util/mappers/RetrieverConnectionMapper.java +++ b/src/main/java/com/redhat/composer/util/mappers/RetrieverConnectionMapper.java @@ -3,26 +3,64 @@ import org.mapstruct.Mapper; import com.redhat.composer.model.enums.ContentRetrieverType; -import com.redhat.composer.model.mongo.contentRetrieverEntites.Neo4JEntity; -import com.redhat.composer.model.mongo.contentRetrieverEntites.WeaviateConnectionEntity; +import com.redhat.composer.model.mongo.contentretrieverentites.Neo4jEntity; +import com.redhat.composer.model.mongo.contentretrieverentites.WeaviateConnectionEntity; import com.redhat.composer.model.request.retriever.Neo4JRequest; import com.redhat.composer.model.request.retriever.WeaviateRequest; +/** + * RetrieverConnectionMapper interface. + */ @Mapper(config = QuarkusMapperConfig.class) public interface RetrieverConnectionMapper { + /** + * Maps a WeaviateConnectionEntity to a WeaviateRequest. + + * @param request the WeaviateConnectionEntity to map + * @return the WeaviateRequest + */ WeaviateConnectionEntity toEntity(WeaviateRequest request); - Neo4JEntity toEntity(Neo4JRequest request); + /** + * Maps a Neo4JEntity to a Neo4JRequest. + + * @param request the Neo4JEntity to map + * @return the Neo4JRequest + */ + Neo4jEntity toEntity(Neo4JRequest request); + + /** + * Maps a WeaviateConnectionEntity to a WeaviateRequest. + * @param entity the WeaviateConnectionEntity to map + * @return the WeaviateRequest + */ WeaviateRequest toRequest(WeaviateConnectionEntity entity); - Neo4JRequest toRequest(Neo4JEntity entity); + /** + * Maps a Neo4JEntity to a Neo4JRequest. + + * @param entity the Neo4JEntity to map + * @return the Neo4JRequest + */ + Neo4JRequest toRequest(Neo4jEntity entity); + + /** + * Maps a ContentRetrieverType to a String. + * @param contentRetrieverType the ContentRetrieverType to map + * @return type value + */ default String toString(ContentRetrieverType contentRetrieverType) { return contentRetrieverType.getType(); } + /** + * Maps a String to a ContentRetrieverType. + * @param value the String to map + * @return the ContentRetrieverType + */ default ContentRetrieverType toContentRetrieverType(String value) { return ContentRetrieverType.fromString(value); } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 1aa4043..a500025 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -13,4 +13,4 @@ quarkus.http.cors=true quarkus.http.cors.origins=* # Set logging to debug -logging.level.root=DEBUG \ No newline at end of file +logging.level.root=DEBUG diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 11159bf..06f1aee 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -30,7 +30,7 @@ mistral.default.temp=0.8 ############################################################ # Default OpenAI Model ############################################################ -openai.default.url= https://vllm-predictor-composer-ai-app.apps.cluster-c4gwj.c4gwj.sandbox1157.opentlc.com/v1 +openai.default.url=https://vllm-predictor-composer-ai-app.apps.cluster-c4gwj.c4gwj.sandbox1157.opentlc.com/v1 openai.default.apiKey=abc123 # openai.default.url=https://mistral-7b-instruct-v0-3-maas-apicast-production.apps.prod.rhoai.rh-aiservices-bu.com:443/v1 # openai.default.apiKey=