Skip to content

Commit

Permalink
Merge pull request #6 from edeandrea/add-tests
Browse files Browse the repository at this point in the history
Some cleanup and adding some tests
  • Loading branch information
jamesfalkner authored Jun 7, 2024
2 parents 2284b8e + 3b6bdb8 commit 713f4c3
Show file tree
Hide file tree
Showing 14 changed files with 645 additions and 45 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: maven
directory: app
schedule:
interval: daily
target-branch: dev

- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
target-branch: dev
55 changes: 55 additions & 0 deletions .github/workflows/simple-build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Simple build and test

on:
push:
branches:
- dev
paths-ignore:
- '**/*.md'
- '.github/dependabot.yml'
- '.github/workflows/dependabot-automerge.yml'
pull_request:
branches:
- dev
paths-ignore:
- '**/*.md'
- '.github/dependabot.yml'
- '.github/workflows/dependabot-automerge.yml'
workflow_dispatch:

concurrency:
group: "workflow = ${{ github.workflow }}, ref = ${{ github.event.ref }}, pr = ${{ github.event.pull_request.id }}"
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
jvm-build-test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java:
- '17'
- '21'
services:
ollama:
image: ollama/ollama
ports:
- 11434:11434
name: "jvm-build-test-${{ matrix.java }}"
steps:
- uses: actions/checkout@v4

- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
cache: maven

- name: "build-test-jvm-java${{ matrix.java }}"
working-directory: app
run: |
./mvnw -B clean verify \
-Dquarkus.langchain4j.chat-model.provider=ollama \
-Dquarkus.http.host=0.0.0.0 \
-Dmaven.compiler.release=${{ matrix.java }}
44 changes: 43 additions & 1 deletion app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
<artifactId>insurance-app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<assertj.version>3.26.0</assertj.version>
<compiler-plugin.version>3.12.1</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.langchain4j.version>0.15.1</quarkus.langchain4j.version>
<quarkus.playwright.version>1.0.0</quarkus.playwright.version>
<quarkus.quinoa.version>2.3.7</quarkus.quinoa.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.11.0</quarkus.platform.version>
Expand Down Expand Up @@ -67,18 +70,51 @@
<dependency>
<groupId>io.quarkiverse.quinoa</groupId>
<artifactId>quarkus-quinoa</artifactId>
<version>2.3.7</version>
<version>${quarkus.quinoa.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.quinoa</groupId>
<artifactId>quarkus-quinoa-testing</artifactId>
<version>${quarkus.quinoa.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.playwright</groupId>
<artifactId>quarkus-playwright</artifactId>
<version>${quarkus.playwright.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -114,6 +150,9 @@
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
<environmentVariables>
<BACKEND_API_URL>http://localhost:8081/api</BACKEND_API_URL>
</environmentVariables>
</configuration>
</plugin>
<plugin>
Expand All @@ -133,6 +172,9 @@
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
<environmentVariables>
<BACKEND_API_URL>http://localhost:8081/api</BACKEND_API_URL>
</environmentVariables>
</configuration>
</plugin>
</plugins>
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/parasol/ai/ClaimService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.parasol.ai;

import jakarta.enterprise.context.SessionScoped;

import org.parasol.model.ClaimBotQuery;
import org.parasol.model.ClaimBotQueryResponse;

import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import io.quarkiverse.langchain4j.RegisterAiService;
import io.smallrye.mutiny.Multi;
import jakarta.enterprise.context.SessionScoped;

@RegisterAiService
@SessionScoped
Expand All @@ -22,9 +22,9 @@ public interface ClaimService {
)
@UserMessage("""
Claim Summary:
{{claim}}
{{query.claim}}
Question: {{query}}
Question: {{query.query}}
""")
Multi<String> chat(String claim, String query);
Multi<String> chat(ClaimBotQuery query);
}
14 changes: 9 additions & 5 deletions app/src/main/java/org/parasol/model/Claim.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.parasol.model;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;

import io.quarkus.hibernate.orm.panache.PanacheEntity;

import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

@Entity
@JsonNaming(SnakeCaseStrategy.class)
public class Claim extends PanacheEntity {

public String claim_number;
public String claimNumber;
public String category;
public String policy_number;
public String client_name;
public String policyNumber;
public String clientName;
public String subject;
@Column(length = 5000)
public String body;
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/org/parasol/model/ClaimBotQuery.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package org.parasol.model;

import com.fasterxml.jackson.annotation.JsonCreator;

public record ClaimBotQuery(String claim, String query) {

@JsonCreator
public ClaimBotQuery {
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package org.parasol.model;

import com.fasterxml.jackson.annotation.JsonCreator;

public record ClaimBotQueryResponse(String type, String token, String source) {

@JsonCreator
public ClaimBotQueryResponse {
}

}
19 changes: 15 additions & 4 deletions app/src/main/java/org/parasol/resources/ClaimWebsocketChatBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@
import org.parasol.model.ClaimBotQuery;
import org.parasol.model.ClaimBotQueryResponse;

import io.quarkus.logging.Log;
import io.quarkus.websockets.next.OnClose;
import io.quarkus.websockets.next.OnOpen;
import io.quarkus.websockets.next.OnTextMessage;
import io.quarkus.websockets.next.WebSocket;
import io.quarkus.websockets.next.WebSocketConnection;

import io.smallrye.mutiny.Multi;

@WebSocket(path = "/ws/query")
public class ClaimWebsocketChatBot {
private final ClaimService bot;
private final ClaimService bot;

public ClaimWebsocketChatBot(ClaimService bot) {
this.bot = bot;
}

@OnOpen
public void onOpen() {
System.out.println("Websocket opened");
public void onOpen(WebSocketConnection connection) {
Log.infof("Websocket connection %s opened", connection.id());
}

@OnClose
public void onClose(WebSocketConnection connection) {
Log.infof("Websocket connection %s closed", connection.id());
}

@OnTextMessage
public Multi<ClaimBotQueryResponse> onMessage(ClaimBotQuery query) {
return bot.chat(query.claim(), query.query())
return bot.chat(query)
.invoke(response -> Log.debugf("Got chat response: %s", response))
.map(resp -> new ClaimBotQueryResponse("token", resp, ""));
}
}
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/org/parasol/resources/GreetingResource.java

This file was deleted.

9 changes: 7 additions & 2 deletions app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ quarkus.langchain4j.openai.base-url=http://localhost:8000/v1

# Ollama
quarkus.langchain4j.ollama.timeout=600s
# quarkus.langchain4j.ollama.base-url=http://127.0.0.1:11434
quarkus.langchain4j.ollama.model-id=llama3
quarkus.langchain4j.ollama.chat-model.temperature=0.3

quarkus.http.host=0.0.0.0
quarkus.http.port=8005
quarkus.http.cors=true
quarkus.dev-ui.cors.enabled=false
quarkus.http.cors.origins=*
quarkus.dev-ui.cors.enabled=false
#%dev.quarkus.http.cors.origins=/.*/

quarkus.hibernate-orm.physical-naming-strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
quarkus.log.category."org.parasol".level=DEBUG
%dev,test.quarkus.log.console.level=DEBUG

# Quinoa
quarkus.quinoa.package-manager-install=true
quarkus.quinoa.package-manager-install.node-version=22.2.0
quarkus.quinoa.package-manager-install.npm-version=10.8.1
quarkus.quinoa.build-dir=dist
quarkus.quinoa.enable-spa-routing=true
Loading

0 comments on commit 713f4c3

Please sign in to comment.