Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI for ASW2425
name: CI for wichat_0

on:
release:
Expand Down Expand Up @@ -54,14 +54,13 @@ jobs:
uses: elgohr/Publish-Docker-Github-Action@v5
env:
API_URI: http://${{ secrets.DEPLOY_HOST }}:8000
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
with:
name: pglez82/asw2425_0/webapp
name: arquisoft/wichat_0/webapp
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: webapp
buildargs: API_URI,LLM_API_KEY
buildargs: API_URI
docker-push-authservice:
name: Push auth service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -76,7 +75,7 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: pglez82/asw2425_0/authservice
name: arquisoft/wichat_0/authservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -95,7 +94,7 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: pglez82/asw2425_0/userservice
name: arquisoft/wichat_0/userservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -113,7 +112,7 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: pglez82/asw2425_0/llmservice
name: arquisoft/wichat_0/llmservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -135,7 +134,7 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: pglez82/asw2425_0/gatewayservice
name: arquisoft/wichat_0/gatewayservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
Expand All @@ -152,6 +151,6 @@ jobs:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/pglez82/asw2425_0/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wichat_0/master/docker-compose.yml -O docker-compose.yml
docker compose --profile prod down
docker compose --profile prod up -d --pull always
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"postman.settings.dotenv-detection-notification-visibility": false
}
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# asw2425_0
# wichat_0

[![Actions Status](https://github.com/pglez82/asw2425_0/workflows/CI%20for%20ASW2425/badge.svg)](https://github.com/pglez82/asw2425_0/actions)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pglez82_asw2425_0&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=pglez82_asw2425_0)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=pglez82_asw2425_0&metric=coverage)](https://sonarcloud.io/summary/new_code?id=pglez82_asw2425_0)
[![Actions Status](https://github.com/arquisoft/wichat_0/workflows/CI%20for%20wichat_0/badge.svg)](https://github.com/arquisoft/wichat_0/actions)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wichat_0&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wichat_0)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wichat_0&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wichat_0)

<p float="left">
<img src="https://blog.wildix.com/wp-content/uploads/2020/06/react-logo.jpg" height="100">
Expand All @@ -23,16 +23,16 @@ Both the user and auth service share a Mongo database that is accessed with mong

First, clone the project:

```git clone [email protected]:pglez82/asw2425_0.git```
```git clone [email protected]:arquisoft/wichat_0.git```

### LLM API key configuration

In order to communicate with the LLM integrated in this project, we need to setup an API key. Two integrations are available in this propotipe: gemini and empaphy. The API key provided must match the LLM provider used.

We need to create two .env files.
- The first one in the webapp directory (for executing the webapp using ```npm start```). The content of this .env file should be as follows:
- The first one in the llmservice directory (for executing the llmservice using ```npm start```). The content of this .env file should be as follows:
```
REACT_APP_LLM_API_KEY="YOUR-API-KEY"
LLM_API_KEY="YOUR-API-KEY"
```
- The second one located in the root of the project (along the docker-compose.yml). This .env file is used for the docker-compose when launching the app with docker. The content of this .env file should be as follows:
```
Expand All @@ -41,8 +41,7 @@ LLM_API_KEY="YOUR-API-KEY"

Note that these files must NOT be uploaded to the github repository (they are excluded in the .gitignore).

An extra configuration for the LLM to work in the deployed version of the app is to include it as a repository secret (LLM_API_KEY). This secret will be used by GitHub Action when building and deploying the application.

An extra configuration for the LLM to work in the deployed version of the app is to create the same .env file (with the LLM_API_KEY variable) in the virtual machine (in the home of the azureuser directory).

### Launching Using docker
For launching the propotipe using docker compose, just type:
Expand Down Expand Up @@ -106,7 +105,7 @@ deploy:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/pglez82/asw2425_0/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wichat_0/master/docker-compose.yml -O docker-compose.yml
docker compose --profile prod down
docker compose --profile prod up -d --pull always
```
Expand Down
36 changes: 18 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
mongodb:
container_name: mongodb-asw2425_0
container_name: mongodb-wichat_0
image: mongo
profiles: ["dev", "prod"]
volumes:
Expand All @@ -11,8 +11,8 @@ services:
- mynetwork

authservice:
container_name: authservice-asw2425_0
image: ghcr.io/pglez82/asw2425_0/authservice:latest
container_name: authservice-wichat_0
image: ghcr.io/arquisoft/wichat_0/authservice:latest
profiles: ["dev", "prod"]
build: ./users/authservice
depends_on:
Expand All @@ -25,8 +25,8 @@ services:
MONGODB_URI: mongodb://mongodb:27017/userdb

userservice:
container_name: userservice-asw2425_0
image: ghcr.io/pglez82/asw2425_0/userservice:latest
container_name: userservice-wichat_0
image: ghcr.io/arquisoft/wichat_0/userservice:latest
profiles: ["dev", "prod"]
build: ./users/userservice
depends_on:
Expand All @@ -39,18 +39,21 @@ services:
MONGODB_URI: mongodb://mongodb:27017/userdb

llmservice:
container_name: llmservice-asw2425_0
image: ghcr.io/pglez82/asw2425_0/llmservice:latest
container_name: llmservice-wichat_0
image: ghcr.io/arquisoft/wichat_0/llmservice:latest
profiles: ["dev", "prod"]
build: ./llmservice
env_file:
- .env
build:
context: ./llmservice
ports:
- "8003:8003"
networks:
- mynetwork

gatewayservice:
container_name: gatewayservice-asw2425_0
image: ghcr.io/pglez82/asw2425_0/gatewayservice:latest
container_name: gatewayservice-wichat_0
image: ghcr.io/arquisoft/wichat_0/gatewayservice:latest
profiles: ["dev", "prod"]
build: ./gatewayservice
depends_on:
Expand All @@ -68,21 +71,18 @@ services:
LLM_SERVICE_URL: http://llmservice:8003

webapp:
container_name: webapp-asw2425_0
image: ghcr.io/pglez82/asw2425_0/webapp:latest
container_name: webapp-wichat_0
image: ghcr.io/arquisoft/wichat_0/webapp:latest
profiles: ["dev", "prod"]
build:
context: ./webapp
args:
LLM_API_KEY: ${LLM_API_KEY}
build: ./webapp
depends_on:
- gatewayservice
ports:
- "3000:3000"

prometheus:
image: prom/prometheus
container_name: prometheus-asw2425_0
container_name: prometheus-wichat_0
profiles: ["dev"]
networks:
- mynetwork
Expand All @@ -96,7 +96,7 @@ services:

grafana:
image: grafana/grafana
container_name: grafana-asw2425_0
container_name: grafana-wichat_0
profiles: ["dev"]
networks:
- mynetwork
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## The documentation
In this project, the documentation is compiled locally and deployed to GitHub pages.
The deployment url is: [https://pglez82.github.io/asw2425_0/](https://pglez82.github.io/asw2425_0/).
The deployment url is: [https://arquisoft.github.io/wichat_0/](https://arquisoft.github.io/wichat_0/).

### Documentation build
For the documentation, we are going to use [AsciiDoc](https://asciidoc.org/) and [PlantUML](https://plantuml.com) and follow the [Arc42](https://github.com/arc42/arc42-template) template. If you want to be able to generate the doc locally you need to install Ruby, Java and some dependencies to translate the AsciiDoc code into html. If you are in Linux you can install Ruby and Java simply by executing:
Expand Down Expand Up @@ -30,6 +30,6 @@ npm run build
The documentation will be generated under the `docs/build` directory.

### Documentation deployment
If we want to deploy it to GitHub pages, so it is accessible via [https://pglez82.github.io/asw2425_0/](https://pglez82.github.io/asw2425_0/), we need to execute `npm run deploy`.
If we want to deploy it to GitHub pages, so it is accessible via [https://arquisoft.github.io/wichat_0/](https://arquisoft.github.io/wichat_0/), we need to execute `npm run deploy`.

If you check the `package.json` in this directory you can see how deploying is as easy as executing `gh-pages -d build`, which can be directly executed using `npm run deploy` in the docs directory. The `gh-pages` package is in charge of pushing the documentation generated directory (basically some htmls) to a special github branch called gh-pages. Everything pushed to this branch is accessible on the repository page. Note that we only want to push there the documentation. Also is important that the documentation build is not pushed to the other branches of the project.
2 changes: 1 addition & 1 deletion docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// configure EN settings for asciidoc
include::src/config.adoc[]

= image:arc42-logo.png[arc42] Template
= image:arc42-logo.png[arc42] wichat_0
:revnumber: 8.2 EN
:revdate: January 2023
:revremark: (based upon AsciiDoc version)
Expand Down
6 changes: 3 additions & 3 deletions gatewayservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/pglez82/asw2425_0.git"
"url": "git+https://github.com/arquisoft/wichat_0.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/pglez82/asw2425_0/issues"
"url": "https://github.com/arquisoft/wichat_0/issues"
},
"homepage": "https://github.com/pglez82/asw2425_0#readme",
"homepage": "https://github.com/arquisoft/wichat_0#readme",
"dependencies": {
"axios": "^1.7.9",
"cors": "^2.8.5",
Expand Down
3 changes: 2 additions & 1 deletion llmservice/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
coverage
coverage
.env
15 changes: 11 additions & 4 deletions llmservice/llm-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const port = 8003;

// Middleware to parse JSON in request body
app.use(express.json());
// Load enviornment variables
require('dotenv').config();

// Define configurations for different LLM APIs
const llmConfigs = {
Expand All @@ -17,9 +19,9 @@ const llmConfigs = {
transformResponse: (response) => response.data.candidates[0]?.content?.parts[0]?.text
},
empathy: {
url: () => 'https://empathyai.staging.empathy.co/v1/chat/completions',
url: () => 'https://empathyai.prod.empathy.co/v1/chat/completions',
transformRequest: (question) => ({
model: "qwen/Qwen2.5-Coder-7B-Instruct",
model: "mistralai/Mistral-7B-Instruct-v0.3",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: question }
Expand Down Expand Up @@ -71,9 +73,14 @@ async function sendQuestionToLLM(question, apiKey, model = 'gemini') {
app.post('/ask', async (req, res) => {
try {
// Check if required fields are present in the request body
validateRequiredFields(req, ['question', 'model', 'apiKey']);
validateRequiredFields(req, ['question', 'model']);

const { question, model, apiKey } = req.body;
const { question, model } = req.body;
//load the api key from an environment variable
const apiKey = process.env.LLM_API_KEY;
if (!apiKey) {
return res.status(400).json({ error: 'API key is missing.' });
}
const answer = await sendQuestionToLLM(question, apiKey, model);
res.json({ answer });

Expand Down
21 changes: 15 additions & 6 deletions llmservice/llm-service.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//set a fake api key
process.env.LLM_API_KEY = 'test-api-key';

const request = require('supertest');
const axios = require('axios');
const app = require('./llm-service');
Expand All @@ -13,19 +16,25 @@ describe('LLM Service', () => {
axios.post.mockImplementation((url, data) => {
if (url.startsWith('https://generativelanguage')) {
return Promise.resolve({ data: { candidates: [{ content: { parts: [{ text: 'llmanswer' }] } }] } });
} else if (url.endsWith('https://empathyai')) {
return Promise.resolve({ data: { answer: 'llmanswer' } });
} else if (url.startsWith('https://empathyai')) {
return Promise.resolve({ data: { choices: [ {message: { content: 'llmanswer' } } ] } });
}
});

// Test /ask endpoint
it('the llm should reply', async () => {
const response = await request(app)
const response1 = await request(app)
.post('/ask')
.send({ question: 'a question', model: 'gemini' });

const response2 = await request(app)
.post('/ask')
.send({ question: 'a question', apiKey: 'apiKey', model: 'gemini' });
.send({ question: 'a question', model: 'empathy' });

expect(response.statusCode).toBe(200);
expect(response.body.answer).toBe('llmanswer');
expect(response1.statusCode).toBe(200);
expect(response1.body.answer).toBe('llmanswer');
expect(response2.statusCode).toBe(200);
expect(response2.body.answer).toBe('llmanswer');
});

});
13 changes: 13 additions & 0 deletions llmservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions llmservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
"author": "",
"license": "ISC",
"description": "",
"homepage": "https://github.com/pglez82/asw2425_0#readme",
"dependencies": {
"axios": "^1.7.9",
"express": "^4.21.2"
},
"devDependencies": {
"jest": "^29.7.0",
"supertest": "^7.0.0"
}
"homepage": "https://github.com/arquisoft/wichat_0#readme",
"dependencies": {
"axios": "^1.7.9",
"dotenv": "^16.4.7",
"express": "^4.21.2"
},
"devDependencies": {
"jest": "^29.7.0",
"supertest": "^7.0.0"
}
}
Loading
Loading