From 3f781b450d419fc7d71bcf9511f24551a5c9b407 Mon Sep 17 00:00:00 2001 From: Filippo Pedrazzini Date: Thu, 20 Jul 2023 15:41:46 +0200 Subject: [PATCH] Pr/290 (#295) * Add getServiceUrl * fixed proxy url for chat * fixed prettier * removed unused logic --------- Co-authored-by: Janaka-Steph --- caddy/Caddyfile | 6 ++++++ docker-compose.yml | 17 ++++++++++------- src/shared/api/v1.ts | 6 ++---- src/shared/hooks/usePremChatStream.ts | 10 +++++++--- 4 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 caddy/Caddyfile diff --git a/caddy/Caddyfile b/caddy/Caddyfile new file mode 100644 index 00000000..3a80b720 --- /dev/null +++ b/caddy/Caddyfile @@ -0,0 +1,6 @@ +:8000 { + handle_path /api/* { + reverse_proxy premd:8000 + } + reverse_proxy prem_app:1420 +} diff --git a/docker-compose.yml b/docker-compose.yml index d1c85d90..2253af92 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,22 +4,25 @@ services: prem_app: container_name: prem_app build: . - ports: - - 1420:1420 environment: - VITE_DESTINATION=browser - VITE_IS_PACKAGED=true - - VITE_BACKEND_URL=http://localhost:8000 premd: container_name: premd - image: ghcr.io/premai-io/premd:latest - ports: - - 8000:8000 + image: ghcr.io/premai-io/premd:v0.0.20 restart: on-failure volumes: - /var/run/docker.sock:/var/run/docker.sock environment: - PREM_REGISTRY_URL=https://raw.githubusercontent.com/premAI-io/prem-registry/main/manifests.json - SENTRY_DSN=https://75592545ad6b472e9ad7c8ff51740b73@o1068608.ingest.sentry.io/4505244431941632 - \ No newline at end of file + + caddy: + container_name: caddy + image: caddy:2.6.4-alpine + restart: on-failure + ports: + - 8000:8000 + volumes: + - ./caddy/Caddyfile:/etc/caddy/Caddyfile \ No newline at end of file diff --git a/src/shared/api/v1.ts b/src/shared/api/v1.ts index d9bc82ef..53c7acc0 100644 --- a/src/shared/api/v1.ts +++ b/src/shared/api/v1.ts @@ -1,15 +1,13 @@ import axios from "axios"; -import { getBackendUrlFromStore } from "shared/store/setting"; +import { getBackendUrlFromStore } from "../store/setting"; const api = () => { - const client = axios.create({ + return axios.create({ baseURL: getBackendUrlFromStore(), headers: { "Content-Type": "application/json", }, }); - - return client; }; export default api; diff --git a/src/shared/hooks/usePremChatStream.ts b/src/shared/hooks/usePremChatStream.ts index d3503ce0..512f03c8 100644 --- a/src/shared/hooks/usePremChatStream.ts +++ b/src/shared/hooks/usePremChatStream.ts @@ -7,6 +7,7 @@ import { PremChatResponse } from "modules/prem-chat/types"; import usePremChatStore from "../store/prem-chat"; import useService from "./useService"; import { toast } from "react-toastify"; +import { generateUrl } from "shared/helpers/utils"; import { getBackendUrlFromStore } from "shared/store/setting"; import { AxiosError } from "axios"; @@ -78,11 +79,14 @@ const usePremChatStream = (serviceId: string, chatId: string | null): PremChatRe setLoading(true); abortController.current = new AbortController(); - const backendUrl = new URL(getBackendUrlFromStore()); - backendUrl.port = `${service?.runningPort!}`; + const backendUrl = generateUrl( + getBackendUrlFromStore(), + service?.runningPort!, + "v1/chat/completions" + ); try { - fetchEventSource(`${backendUrl}v1/chat/completions`, { + fetchEventSource(backendUrl, { method: "POST", openWhenHidden: true, headers: {