diff --git a/.github/workflows/changelog_report.py b/.github/workflows/changelog_report.py new file mode 100644 index 00000000..56e29b1f --- /dev/null +++ b/.github/workflows/changelog_report.py @@ -0,0 +1,36 @@ +if __name__ == "__main__": + with open("../../CHANGELOG.md") as f: + temp = f.readlines() + + # divide the file into four categories + commit, name, date, msg = [], [], [], [] + + # regex is \t\t\t + for line in temp: + line = line.split('\t') + commit.append(line[0]) + name.append(line[1]) + date.append(line[2]) + msg.append(line[3]) + + # first detect the number of unique year-month combo + date_year_month = [x[:7] for x in date] + unique = sorted(list(set(date_year_month)), reverse=True) + + # based on this write from the reverse order + final_lines = [] + + for year_month in unique: + # first write the header + final_lines.append(f"# {year_month}\n\n") + + # loop through and stop when the year_month is lesser + for idx in range(len(date)): + if date[idx][:7] == year_month: + l = f"- {commit[idx]} {name[idx]} {date[idx]} {msg[idx]}" + final_lines.append(l) + final_lines.append("\n") + + with open('../../CHANGELOG.md', 'w') as f: + for l in final_lines: + f.write(l) diff --git a/.github/workflows/ci-changelog.yaml b/.github/workflows/ci-changelog.yaml new file mode 100644 index 00000000..3d072c5c --- /dev/null +++ b/.github/workflows/ci-changelog.yaml @@ -0,0 +1,41 @@ +name: Update Changelog + +on: + workflow_dispatch: + +jobs: + updateChangeLog: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Create Changelog file + run: | + make changelog + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GH_PAT }} + commit-message: Update report + committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> + author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> + signoff: true + base: master + branch: update-chglog + delete-branch: true + title: Changelog Update + body: | + - Auto-generated by [create-pull-request][1] + [1]: https://github.com/peter-evans/create-pull-request + labels: | + docs + assignees: luarss + reviewers: luarss diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d6cf4205..8afa3fc5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,7 +34,7 @@ jobs: cp ${{ secrets.PATH_TO_GOOGLE_APPLICATION_CREDENTIALS }} evaluation/auto_evaluation/src - name: Build Docker image run: | - make docker + make docker-up sleep 900 # TODO: Remove this after docker-compose healthcheck timeout restored fixed. - name: Run LLM CI working-directory: evaluation @@ -48,4 +48,4 @@ jobs: - name: Teardown if: always() run: | - docker compose down --remove-orphans + make docker-down diff --git a/Makefile b/Makefile index 1c6a81fa..6015671f 100644 --- a/Makefile +++ b/Makefile @@ -16,5 +16,12 @@ check: @. ./backend/.venv/bin/activate && \ pre-commit run --all-files -docker: +docker-up: @docker compose up --build --wait + +docker-down: + @docker compose down --remove-orphans + +changelog: + @git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --date=short --since="2024-06-01" > CHANGELOG.md + @cd .github/workflows && python changelog_report.py diff --git a/docker-compose.yml b/docker-compose.yml index fe9923d9..fd14b656 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,15 @@ services: # timeout: 10s # retries: 5 # start_period: 30 s # todo: make sure that this healthcheck starts after the API in the backend is ready. + + frontend: + build: + context: ./frontend + container_name: "orassistant-frontend" + ports: + - "8501:8501" + networks: + - orassistant-network # health-checker: # build: ./common diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 00000000..f77fad15 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.12.3-slim + +WORKDIR /ORAssistant-frontend + +COPY ./requirements.txt /ORAssistant-frontend/requirements.txt +COPY ./requirements-test.txt /ORAssistant-frontend/requirements-test.txt +COPY ./pyproject.toml /ORAssistant-frontend/pyproject.toml + +RUN pip install --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt && \ + pip install --no-cache-dir -r requirements-test.txt && \ + pip install --no-cache-dir -e . + +COPY streamlit_app.py . +COPY ./utils ./utils +COPY ./assets ./assets + +CMD ["streamlit", "run", "streamlit_app.py"] diff --git a/frontend/README.md b/frontend/README.md index bbb8e9b8..2652bedd 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,6 +1,6 @@ -# FrontEnd For Streamlit +# Frontend For Streamlit -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. +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. ## Preparing the Environment Variables @@ -39,6 +39,7 @@ To collect feedback, you need to set up a Google Sheet and configure the necessa ``` 4. **Set the Current Version for Feedback Evaluation:** - Add the current version of the feedback evaluation to the environment variables. + - If unset, this defaults to the commit hash of `master`. ```plaintext RAG_VERSION= @@ -73,4 +74,4 @@ This will start a mock API server that simulates responses for testing purposes. ## License -This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the [LICENSE](../../LICENSE) file for details. \ No newline at end of file +This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the [LICENSE](../LICENSE) file for details. \ No newline at end of file diff --git a/frontend/streamlit_app.py b/frontend/streamlit_app.py index 94c9125e..df9911a8 100644 --- a/frontend/streamlit_app.py +++ b/frontend/streamlit_app.py @@ -92,7 +92,7 @@ def main() -> None: base_url, endpoints = fetch_endpoints() selected_endpoint = st.selectbox( - "Select preferred architecture", + "Select preferred endpoint", options=endpoints, index=0, format_func=lambda x: x.split("/")[-1].capitalize(), diff --git a/frontend/utils/feedback.py b/frontend/utils/feedback.py index 292ff59c..56e786e6 100644 --- a/frontend/utils/feedback.py +++ b/frontend/utils/feedback.py @@ -89,9 +89,6 @@ def submit_feedback_to_google_sheet( "The FEEDBACK_SHEET_ID environment variable is not set or is empty." ) - if not os.getenv("RAG_VERSION"): - raise ValueError("The RAG_VERSION environment variable is not set or is empty.") - service_account_file = os.getenv("GOOGLE_CREDENTIALS_JSON") scope = [ "https://spreadsheets.google.com/feeds", @@ -186,10 +183,31 @@ def show_feedback_form( sources=sources, context=context, issue=feedback, - version=os.getenv("RAG_VERSION", "N/A"), + version=os.getenv("RAG_VERSION", get_git_commit_hash()), ) st.session_state.submitted = True if st.session_state.submitted: st.sidebar.success("Thank you for your feedback!") + + +def get_git_commit_hash() -> str: + """ + Get the latest commit hash from the Git repository. + + Returns: + - str: The latest commit hash. + """ + import subprocess + + try: + commit_hash = ( + subprocess.check_output(["git", "rev-parse", "HEAD"]) + .strip() + .decode("utf-8") + ) + except subprocess.CalledProcessError: + commit_hash = "N/A" + + return commit_hash