From be3ab88c88b120bdf144b7ab56c95799ad4e6867 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 12 Mar 2024 00:26:14 -0700 Subject: [PATCH 01/10] fix: error handling --- backend/apps/ollama/main.py | 17 +++++++++++++---- backend/constants.py | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 5ecbaa29..039c570b 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -123,6 +123,7 @@ async def get_all_models(): map(lambda response: response["models"], responses) ) } + app.state.MODELS = {model["model"]: model for model in models["models"]} return models @@ -181,11 +182,19 @@ async def get_ollama_versions(url_idx: Optional[int] = None): responses = await asyncio.gather(*tasks) responses = list(filter(lambda x: x is not None, responses)) - lowest_version = min( - responses, key=lambda x: tuple(map(int, x["version"].split("."))) - ) + print(responses) - return {"version": lowest_version["version"]} + if len(responses) > 0: + lowest_version = min( + responses, key=lambda x: tuple(map(int, x["version"].split("."))) + ) + + return {"version": lowest_version["version"]} + else: + raise HTTPException( + status_code=500, + detail=ERROR_MESSAGES.OLLAMA_NOT_FOUND, + ) else: url = app.state.OLLAMA_BASE_URLS[url_idx] try: diff --git a/backend/constants.py b/backend/constants.py index eacf8a20..05bdebc5 100644 --- a/backend/constants.py +++ b/backend/constants.py @@ -52,3 +52,4 @@ class ERROR_MESSAGES(str, Enum): MODEL_NOT_FOUND = lambda name="": f"Model '{name}' was not found" OPENAI_NOT_FOUND = lambda name="": f"OpenAI API was not found" + OLLAMA_NOT_FOUND = "WebUI could not connect to Ollama" From 26a187f5ac2ebc28849f90127d2b96b6935ae56f Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 12 Mar 2024 00:26:53 -0700 Subject: [PATCH 02/10] refac: print removed --- backend/apps/ollama/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/apps/ollama/main.py b/backend/apps/ollama/main.py index 039c570b..2e236f34 100644 --- a/backend/apps/ollama/main.py +++ b/backend/apps/ollama/main.py @@ -182,8 +182,6 @@ async def get_ollama_versions(url_idx: Optional[int] = None): responses = await asyncio.gather(*tasks) responses = list(filter(lambda x: x is not None, responses)) - print(responses) - if len(responses) > 0: lowest_version = min( responses, key=lambda x: tuple(map(int, x["version"].split("."))) From 97842d037ee537478a345ee53e7c97cc16c83fb3 Mon Sep 17 00:00:00 2001 From: Silentoplayz <50341825+Silentoplayz@users.noreply.github.com> Date: Tue, 12 Mar 2024 05:34:00 -0400 Subject: [PATCH 03/10] Update tailwind.css - Combined font-family declaration: Instead of repeating the font-family declaration for both `html` and `pre`, it's combined into one declaration to save space and avoid repetition. - Removed unnecessary `pre` styling: The `pre` styling for `font-family` is removed as the font-family is already defined in the `html` rule. The code is more concise and easier to read. --- src/tailwind.css | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/tailwind.css b/src/tailwind.css index 60b6b04c..6c69643d 100644 --- a/src/tailwind.css +++ b/src/tailwind.css @@ -3,16 +3,13 @@ @tailwind utilities; @layer base { - html { - font-family: -apple-system, 'Arimo', ui-sans-serif, system-ui, 'Segoe UI', Roboto, Ubuntu, - Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', - 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; - } + html, pre { + font-family: -apple-system, 'Arimo', ui-sans-serif, system-ui, 'Segoe UI', Roboto, Ubuntu, + Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', + 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; + } - pre { - font-family: -apple-system, 'Arimo', ui-sans-serif, system-ui, 'Segoe UI', Roboto, Ubuntu, - Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', - 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; - white-space: pre-wrap; - } + pre { + white-space: pre-wrap; + } } From cc4b82a3f3df323d3103341c1533a24661b841b0 Mon Sep 17 00:00:00 2001 From: Silentoplayz <50341825+Silentoplayz@users.noreply.github.com> Date: Tue, 12 Mar 2024 06:08:03 -0400 Subject: [PATCH 04/10] Update tailwind.css Fix spacing --- src/tailwind.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tailwind.css b/src/tailwind.css index 6c69643d..10aca348 100644 --- a/src/tailwind.css +++ b/src/tailwind.css @@ -3,11 +3,11 @@ @tailwind utilities; @layer base { - html, pre { - font-family: -apple-system, 'Arimo', ui-sans-serif, system-ui, 'Segoe UI', Roboto, Ubuntu, - Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', - 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; - } + html, pre { + font-family: -apple-system, 'Arimo', ui-sans-serif, system-ui, 'Segoe UI', Roboto, Ubuntu, + Cantarell, 'Noto Sans', sans-serif, 'Helvetica Neue', Arial, 'Apple Color Emoji', + 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; + } pre { white-space: pre-wrap; From 7f78e584883994c7b8bb12d0d8ec88289074def7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 12 Mar 2024 13:35:30 -0700 Subject: [PATCH 05/10] refac: image generation error handling --- backend/apps/images/main.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/apps/images/main.py b/backend/apps/images/main.py index 31bfc0f5..e14b0f6a 100644 --- a/backend/apps/images/main.py +++ b/backend/apps/images/main.py @@ -293,6 +293,7 @@ def generate_image( "size": form_data.size if form_data.size else app.state.IMAGE_SIZE, "response_format": "b64_json", } + r = requests.post( url=f"https://api.openai.com/v1/images/generations", json=data, @@ -300,7 +301,6 @@ def generate_image( ) r.raise_for_status() - res = r.json() images = [] @@ -356,7 +356,10 @@ def generate_image( return images except Exception as e: - print(e) - if r: - print(r.json()) - raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(e)) + error = e + + if r != None: + data = r.json() + if "error" in data: + error = data["error"]["message"] + raise HTTPException(status_code=400, detail=ERROR_MESSAGES.DEFAULT(error)) From 5a567ce4d0cd2fe65316000f935764d4e63a4c4b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 12 Mar 2024 13:43:49 -0700 Subject: [PATCH 06/10] fix: message after image generation --- src/routes/(app)/+page.svelte | 5 +++-- src/routes/(app)/c/[id]/+page.svelte | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index 07fcc176..924d0c5b 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -308,7 +308,7 @@ .map((file) => file.url.slice(file.url.indexOf(',') + 1)); // Add images array only if it contains elements - if (imageUrls && imageUrls.length > 0) { + if (imageUrls && imageUrls.length > 0 && message.role === 'user') { baseMessage.images = imageUrls; } @@ -532,7 +532,8 @@ .filter((message) => message) .map((message, idx, arr) => ({ role: message.role, - ...(message.files?.filter((file) => file.type === 'image').length > 0 ?? false + ...((message.files?.filter((file) => file.type === 'image').length > 0 ?? false) && + message.role === 'user' ? { content: [ { diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index 4bc6acfa..56bd2f89 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -321,7 +321,7 @@ .map((file) => file.url.slice(file.url.indexOf(',') + 1)); // Add images array only if it contains elements - if (imageUrls && imageUrls.length > 0) { + if (imageUrls && imageUrls.length > 0 && message.role === 'user') { baseMessage.images = imageUrls; } @@ -545,7 +545,8 @@ .filter((message) => message) .map((message, idx, arr) => ({ role: message.role, - ...(message.files?.filter((file) => file.type === 'image').length > 0 ?? false + ...((message.files?.filter((file) => file.type === 'image').length > 0 ?? false) && + message.role === 'user' ? { content: [ { @@ -688,7 +689,12 @@ if (messages.length == 2) { window.history.replaceState(history.state, '', `/c/${_chatId}`); - await setChatTitle(_chatId, userPrompt); + + if ($settings?.titleAutoGenerateModel) { + await generateChatTitle(_chatId, userPrompt); + } else { + await setChatTitle(_chatId, userPrompt); + } } }; From 3790790a18f565f64df090ba911e3f04781fa332 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 12 Mar 2024 13:47:49 -0700 Subject: [PATCH 07/10] fix: possible fix for #1139 --- src/routes/(app)/+page.svelte | 4 +++- src/routes/(app)/c/[id]/+page.svelte | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index 924d0c5b..926681b1 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -140,7 +140,9 @@ }; const scrollToBottom = () => { - messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight; + if (messagesContainerElement) { + messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight; + } }; ////////////////////////// diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index 56bd2f89..081dac76 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -160,7 +160,9 @@ }; const scrollToBottom = () => { - messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight; + if (messagesContainerElement) { + messagesContainerElement.scrollTop = messagesContainerElement.scrollHeight; + } }; ////////////////////////// From c7c81f538dc247351bb028c9d19861ce0791e992 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Mon, 18 Mar 2024 21:06:01 +0100 Subject: [PATCH 08/10] ci: Change image --- .github/workflows/docker-build.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index bb71de8b..52fb65c1 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -12,13 +12,16 @@ on: # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. env: - REGISTRY: ghcr.io + REGISTRY: git.depeuter.dev IMAGE_NAME: ${{ github.repository }} + RUNNER_TOOL_CACHE: /toolcache # There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. jobs: build-and-push-image: runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. permissions: contents: read From 336868c48724fa6ccb90559d9668bbea3a557afc Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Tue, 19 Mar 2024 09:09:04 +0100 Subject: [PATCH 09/10] ci: Change login token --- .github/workflows/docker-build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index 52fb65c1..52fd305c 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -42,7 +42,7 @@ jobs: with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + password: ${{ secrets.CI_TOKEN }} - name: Extract metadata for Docker images id: meta From 7144e0712267ce192f7edfc2ad93bb88d1e2649a Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Tue, 19 Mar 2024 12:11:52 +0100 Subject: [PATCH 10/10] ci: Tweak python --- .github/workflows/format-backend.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/format-backend.yaml b/.github/workflows/format-backend.yaml index 9d767fa5..ab36bd90 100644 --- a/.github/workflows/format-backend.yaml +++ b/.github/workflows/format-backend.yaml @@ -8,15 +8,19 @@ jobs: name: 'Format Backend' env: PUBLIC_API_BASE_URL: '' + RUNNER_TOOL_CACHE: /toolcache runs-on: ubuntu-latest strategy: matrix: node-version: - latest + python-version: [ '3.12.2' ] steps: - uses: actions/checkout@v4 - name: Use Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} - name: Use Bun uses: oven-sh/setup-bun@v1 - name: Install dependencies