Skip to content

Commit 7090704

Browse files
authored
Frontend updates (#92)
* add frontend into docker-compose * RAG_VERSION now defaults to git commit hash * add CHANGELOG ci * add more spaces to avoid merge conflict * make changelog manual_dispatch, fix docker CI --------- Signed-off-by: Jack Luar <[email protected]>
1 parent 260bba5 commit 7090704

File tree

9 files changed

+141
-11
lines changed

9 files changed

+141
-11
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
if __name__ == "__main__":
2+
with open("../../CHANGELOG.md") as f:
3+
temp = f.readlines()
4+
5+
# divide the file into four categories
6+
commit, name, date, msg = [], [], [], []
7+
8+
# regex is <commit>\t<name>\t<date>\t<msg>
9+
for line in temp:
10+
line = line.split('\t')
11+
commit.append(line[0])
12+
name.append(line[1])
13+
date.append(line[2])
14+
msg.append(line[3])
15+
16+
# first detect the number of unique year-month combo
17+
date_year_month = [x[:7] for x in date]
18+
unique = sorted(list(set(date_year_month)), reverse=True)
19+
20+
# based on this write from the reverse order
21+
final_lines = []
22+
23+
for year_month in unique:
24+
# first write the header
25+
final_lines.append(f"# {year_month}\n\n")
26+
27+
# loop through and stop when the year_month is lesser
28+
for idx in range(len(date)):
29+
if date[idx][:7] == year_month:
30+
l = f"- {commit[idx]} {name[idx]} {date[idx]} {msg[idx]}"
31+
final_lines.append(l)
32+
final_lines.append("\n")
33+
34+
with open('../../CHANGELOG.md', 'w') as f:
35+
for l in final_lines:
36+
f.write(l)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Update Changelog
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
updateChangeLog:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out repository code
11+
uses: actions/checkout@v4
12+
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.12'
17+
18+
- name: Create Changelog file
19+
run: |
20+
make changelog
21+
22+
- name: Create Pull Request
23+
id: cpr
24+
uses: peter-evans/create-pull-request@v6
25+
with:
26+
token: ${{ secrets.GH_PAT }}
27+
commit-message: Update report
28+
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
29+
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
30+
signoff: true
31+
base: master
32+
branch: update-chglog
33+
delete-branch: true
34+
title: Changelog Update
35+
body: |
36+
- Auto-generated by [create-pull-request][1]
37+
[1]: https://github.com/peter-evans/create-pull-request
38+
labels: |
39+
docs
40+
assignees: luarss
41+
reviewers: luarss

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
cp ${{ secrets.PATH_TO_GOOGLE_APPLICATION_CREDENTIALS }} evaluation/auto_evaluation/src
3535
- name: Build Docker image
3636
run: |
37-
make docker
37+
make docker-up
3838
sleep 900 # TODO: Remove this after docker-compose healthcheck timeout restored fixed.
3939
- name: Run LLM CI
4040
working-directory: evaluation
@@ -48,4 +48,4 @@ jobs:
4848
- name: Teardown
4949
if: always()
5050
run: |
51-
docker compose down --remove-orphans
51+
make docker-down

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,12 @@ check:
1616
@. ./backend/.venv/bin/activate && \
1717
pre-commit run --all-files
1818

19-
docker:
19+
docker-up:
2020
@docker compose up --build --wait
21+
22+
docker-down:
23+
@docker compose down --remove-orphans
24+
25+
changelog:
26+
@git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --date=short --since="2024-06-01" > CHANGELOG.md
27+
@cd .github/workflows && python changelog_report.py

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ services:
1313
# timeout: 10s
1414
# retries: 5
1515
# start_period: 30 s # todo: make sure that this healthcheck starts after the API in the backend is ready.
16+
17+
frontend:
18+
build:
19+
context: ./frontend
20+
container_name: "orassistant-frontend"
21+
ports:
22+
- "8501:8501"
23+
networks:
24+
- orassistant-network
1625

1726
# health-checker:
1827
# build: ./common

frontend/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.12.3-slim
2+
3+
WORKDIR /ORAssistant-frontend
4+
5+
COPY ./requirements.txt /ORAssistant-frontend/requirements.txt
6+
COPY ./requirements-test.txt /ORAssistant-frontend/requirements-test.txt
7+
COPY ./pyproject.toml /ORAssistant-frontend/pyproject.toml
8+
9+
RUN pip install --upgrade pip && \
10+
pip install --no-cache-dir -r requirements.txt && \
11+
pip install --no-cache-dir -r requirements-test.txt && \
12+
pip install --no-cache-dir -e .
13+
14+
COPY streamlit_app.py .
15+
COPY ./utils ./utils
16+
COPY ./assets ./assets
17+
18+
CMD ["streamlit", "run", "streamlit_app.py"]

frontend/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# FrontEnd For Streamlit
1+
# Frontend For Streamlit
22

3-
This Folder contains the frontend code for the OR Assistant using Streamlit. Follow the instructions below to set up the environment, run the application, and perform testing using a mock API.
3+
This folder contains the frontend code for the OR Assistant using Streamlit. Follow the instructions below to set up the environment, run the application, and perform testing using a mock API.
44

55
## Preparing the Environment Variables
66

@@ -39,6 +39,7 @@ To collect feedback, you need to set up a Google Sheet and configure the necessa
3939
```
4040
4. **Set the Current Version for Feedback Evaluation:**
4141
- Add the current version of the feedback evaluation to the environment variables.
42+
- If unset, this defaults to the commit hash of `master`.
4243
4344
```plaintext
4445
RAG_VERSION=<current-version>
@@ -73,4 +74,4 @@ This will start a mock API server that simulates responses for testing purposes.
7374

7475
## License
7576

76-
This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the [LICENSE](../../LICENSE) file for details.
77+
This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the [LICENSE](../LICENSE) file for details.

frontend/streamlit_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def main() -> None:
9292
base_url, endpoints = fetch_endpoints()
9393

9494
selected_endpoint = st.selectbox(
95-
"Select preferred architecture",
95+
"Select preferred endpoint",
9696
options=endpoints,
9797
index=0,
9898
format_func=lambda x: x.split("/")[-1].capitalize(),

frontend/utils/feedback.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ def submit_feedback_to_google_sheet(
8989
"The FEEDBACK_SHEET_ID environment variable is not set or is empty."
9090
)
9191

92-
if not os.getenv("RAG_VERSION"):
93-
raise ValueError("The RAG_VERSION environment variable is not set or is empty.")
94-
9592
service_account_file = os.getenv("GOOGLE_CREDENTIALS_JSON")
9693
scope = [
9794
"https://spreadsheets.google.com/feeds",
@@ -186,10 +183,31 @@ def show_feedback_form(
186183
sources=sources,
187184
context=context,
188185
issue=feedback,
189-
version=os.getenv("RAG_VERSION", "N/A"),
186+
version=os.getenv("RAG_VERSION", get_git_commit_hash()),
190187
)
191188

192189
st.session_state.submitted = True
193190

194191
if st.session_state.submitted:
195192
st.sidebar.success("Thank you for your feedback!")
193+
194+
195+
def get_git_commit_hash() -> str:
196+
"""
197+
Get the latest commit hash from the Git repository.
198+
199+
Returns:
200+
- str: The latest commit hash.
201+
"""
202+
import subprocess
203+
204+
try:
205+
commit_hash = (
206+
subprocess.check_output(["git", "rev-parse", "HEAD"])
207+
.strip()
208+
.decode("utf-8")
209+
)
210+
except subprocess.CalledProcessError:
211+
commit_hash = "N/A"
212+
213+
return commit_hash

0 commit comments

Comments
 (0)