Skip to content

Commit ef7215d

Browse files
squash: enable docsum and codegen in new app fe ui (#61)
Signed-off-by: wwanarif <[email protected]> Co-authored-by: wwanarif <[email protected]>
1 parent 5d6fa69 commit ef7215d

File tree

177 files changed

+9362
-2012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+9362
-2012
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
test-results/
22
**.log
33
**/report.html
4-
docker-compose
4+
docker-compose
5+
**/node_modules/

app-backend/megaservice.py

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import re
88

99
# library import
10-
from fastapi import Request
10+
from typing import List
11+
from fastapi import Request, UploadFile, File
1112
from fastapi.responses import StreamingResponse
1213
from dotenv import load_dotenv
1314

@@ -65,6 +66,7 @@ def __init__(self, host="0.0.0.0", port=8000):
6566
self.host = host
6667
self.port = port
6768
self.endpoint = "/v1/app-backend"
69+
self.is_docsum = False
6870
with open('config/workflow-info.json', 'r') as f:
6971
self.workflow_info = json.load(f)
7072

@@ -117,6 +119,8 @@ def add_remote_service(self):
117119
if node['inMegaservice']:
118120
print('adding Node', node_id)
119121
microservice_name = node['name'].split('@')[1]
122+
if "docsum" in microservice_name:
123+
self.is_docsum = True
120124
service_node_ip = node_id.split('@')[1].replace('_','-') if USE_NODE_ID_AS_IP else HOST_IP
121125
microservice = templates[microservice_name].get_service(host_ip=service_node_ip, node_id_as_ip=USE_NODE_ID_AS_IP, port=os.getenv(f"{node_id.split('@')[1]}_port", None))
122126
microservice.name = node_id
@@ -356,7 +360,7 @@ async def handle_request(self, request: Request, megaservice):
356360
for node, response in result_dict.items():
357361
if isinstance(response, StreamingResponse):
358362
return response
359-
last_node = runtime_graph.all_leaves()[-1]
363+
last_node = runtime_graph.all_leaves()[-1] # YX to fix it to the source node of chat completion
360364
print('result_dict:', result_dict)
361365
print('last_node:',last_node)
362366
last_node_info = self.workflow_info['nodes'][last_node]
@@ -377,9 +381,77 @@ async def handle_request(self, request: Request, megaservice):
377381
# handle the non-llm response
378382
return result_dict[last_node]
379383

384+
async def handle_request_docsum(self, request: Request, files: List[UploadFile] = File(default=None)):
385+
"""Accept pure text, or files .txt/.pdf.docx, audio/video base64 string."""
386+
if "application/json" in request.headers.get("content-type"):
387+
data = await request.json()
388+
stream_opt = data.get("stream", True)
389+
summary_type = data.get("summary_type", "auto")
390+
chunk_size = data.get("chunk_size", -1)
391+
chunk_overlap = data.get("chunk_overlap", -1)
392+
chat_request = ChatCompletionRequest.model_validate(data)
393+
prompt = handle_message(chat_request.messages)
394+
395+
initial_inputs_data = {data["type"]: prompt}
396+
397+
elif "multipart/form-data" in request.headers.get("content-type"):
398+
data = await request.form()
399+
stream_opt = data.get("stream", True)
400+
summary_type = data.get("summary_type", "auto")
401+
chunk_size = data.get("chunk_size", -1)
402+
chunk_overlap = data.get("chunk_overlap", -1)
403+
chat_request = ChatCompletionRequest.model_validate(data)
404+
405+
data_type = data.get("type")
406+
407+
file_summaries = []
408+
if files:
409+
for file in files:
410+
# Fix concurrency issue with the same file name
411+
# https://github.com/opea-project/GenAIExamples/issues/1279
412+
uid = str(uuid.uuid4())
413+
file_path = f"/tmp/{uid}"
414+
415+
import aiofiles
416+
417+
async with aiofiles.open(file_path, "wb") as f:
418+
await f.write(await file.read())
419+
420+
if data_type == "text":
421+
docs = read_text_from_file(file, file_path)
422+
elif data_type in ["audio", "video"]:
423+
docs = encode_file_to_base64(file_path)
424+
else:
425+
raise ValueError(f"Data type not recognized: {data_type}")
426+
427+
os.remove(file_path)
428+
429+
if isinstance(docs, list):
430+
file_summaries.extend(docs)
431+
else:
432+
file_summaries.append(docs)
433+
434+
if file_summaries:
435+
prompt = handle_message(chat_request.messages) + "\n".join(file_summaries)
436+
else:
437+
prompt = handle_message(chat_request.messages)
438+
439+
data_type = data.get("type")
440+
if data_type is not None:
441+
initial_inputs_data = {}
442+
initial_inputs_data[data_type] = prompt
443+
else:
444+
initial_inputs_data = {"messages": prompt}
445+
446+
else:
447+
raise ValueError(f"Unknown request type: {request.headers.get('content-type')}")
448+
380449
def create_handle_request(self, megaservice):
381450
async def handle_request_wrapper(request: Request):
382-
return await self.handle_request(request, megaservice)
451+
if self.is_docsum:
452+
return await self.handle_request_docsum(request)
453+
else:
454+
return await self.handle_request(request, megaservice)
383455
return handle_request_wrapper
384456

385457
def start(self):

app-frontend/Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Use node 20.11.1 as the base image
5-
FROM node:latest AS vite-app
6-
7-
COPY react /usr/app/react
5+
FROM node:20.11.1 as vite-app
6+
7+
COPY ./react /usr/app/react
88
WORKDIR /usr/app/react
99

10-
RUN npm install --legacy-peer-deps && npm run build
1110

12-
FROM nginx:1.27.4-alpine-slim
11+
RUN ["npm", "install"]
12+
RUN ["npm", "run", "build"]
13+
1314

14-
# Install uuidgen in the nginx:alpine image
15-
RUN apk add --no-cache util-linux \
16-
&& apk upgrade --no-cache
15+
FROM nginx:alpine
1716

1817
COPY --from=vite-app /usr/app/react/dist /usr/share/nginx/html
1918
COPY ./react/env.sh /docker-entrypoint.d/env.sh
2019

2120
COPY ./react/nginx.conf /etc/nginx/conf.d/default.conf
22-
RUN chmod +x /docker-entrypoint.d/env.sh
21+
RUN chmod +x /docker-entrypoint.d/env.sh

app-frontend/compose.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
services:
5+
app-frontend:
6+
image: app-frontend:ch
7+
container_name: app-frontend
8+
depends_on:
9+
- chathistory-mongo
10+
ports:
11+
- 5175:80
12+
environment:
13+
- no_proxy=${no_proxy}
14+
- https_proxy=${https_proxy}
15+
- http_proxy=${http_proxy}
16+
- APP_BACKEND_SERVICE_URL=http://localhost:8888/v1/app-backend
17+
- APP_DATAPREP_SERVICE_URL=http://localhost:6007/v1/dataprep
18+
- APP_CHAT_HISTORY_SERVICE_URL=http://localhost:6012/v1/chathistory
19+
- APP_UI_SELECTION=chat,summary,code
20+
ipc: host
21+
restart: always
22+
23+
mongo:
24+
image: mongo:7.0.11
25+
container_name: mongodb
26+
ports:
27+
- 27017:27017
28+
environment:
29+
http_proxy: ${http_proxy}
30+
https_proxy: ${https_proxy}
31+
no_proxy: ${no_proxy}
32+
command: mongod --quiet --logpath /dev/null
33+
34+
chathistory-mongo:
35+
image: ${REGISTRY:-opea}/chathistory-mongo:${TAG:-latest}
36+
container_name: chathistory-mongo-server
37+
ports:
38+
- "6012:6012"
39+
ipc: host
40+
environment:
41+
http_proxy: ${http_proxy}
42+
no_proxy: ${no_proxy}
43+
https_proxy: ${https_proxy}
44+
MONGO_HOST: ${MONGO_HOST:-mongo}
45+
MONGO_PORT: ${MONGO_PORT:-27017}
46+
COLLECTION_NAME: ${COLLECTION_NAME:-Conversations}
47+
LOGFLAG: ${LOGFLAG}
48+
restart: unless-stopped
49+
50+
networks:
51+
default:
52+
driver: bridge

app-frontend/react/.env

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
VITE_CHAT_SERVICE_URL=http://backend_address:8899/v1/chatqna
2-
VITE_DATA_PREP_SERVICE_URL=http://backend_address:6007/v1/dataprep
1+
VITE_BACKEND_SERVICE_URL=
2+
VITE_DATAPREP_SERVICE_URL=
3+
VITE_CHAT_HISTORY_SERVICE_URL=
4+
VITE_UI_SELECTION=
5+
6+
VITE_PROMPT_SERVICE_GET_ENDPOINT=
7+
VITE_PROMPT_SERVICE_CREATE_ENDPOINT=
8+
VITE_PROMPT_SERVICE_DELETE_ENDPOINT=

app-frontend/react/.env.production

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
VITE_APP_UUID=APP_UUID
1+
VITE_BACKEND_SERVICE_URL=APP_BACKEND_SERVICE_URL
2+
VITE_DATAPREP_SERVICE_URL=APP_DATAPREP_SERVICE_URL
3+
VITE_CHAT_HISTORY_SERVICE_URL=APP_CHAT_HISTORY_SERVICE_URL
4+
VITE_UI_SELECTION=APP_UI_SELECTION
5+
6+
VITE_PROMPT_SERVICE_GET_ENDPOINT=APP_PROMPT_SERVICE_GET_ENDPOINT
7+
VITE_PROMPT_SERVICE_CREATE_ENDPOINT=APP_PROMPT_SERVICE_CREATE_ENDPOINT
8+
VITE_PROMPT_SERVICE_DELETE_ENDPOINT=APP_PROMPT_SERVICE_DELETE_ENDPOINT

app-frontend/react/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ yarn-error.log*
77
pnpm-debug.log*
88
lerna-debug.log*
99

10-
# dependencies
11-
package-lock.json
1210
node_modules
1311
dist
1412
dist-ssr

app-frontend/react/env.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
# Copyright (C) 2024 Intel Corporation
33
# SPDX-License-Identifier: Apache-2.0
44

5-
# Generate a random UUID for the application
6-
export APP_UUID=$(uuidgen)
7-
8-
# Print the generated UUID for verification
9-
echo "Generated UUID: $APP_UUID"
10-
115
for i in $(env | grep APP_) #// Make sure to use the prefix MY_APP_ if you have any other prefix in env.production file variable name replace it with MY_APP_
126
do
137
key=$(echo $i | cut -d '=' -f 1)
@@ -16,6 +10,6 @@ do
1610
# sed All files
1711
# find /usr/share/nginx/html -type f -exec sed -i "s|${key}|${value}|g" '{}' +
1812

19-
# sed JS, CSS, and HTML files
20-
find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' -o -name '*.html' \) -exec sed -i "s|${key}|${value}|g" '{}' +
13+
# sed JS and CSS only
14+
find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|${key}|${value}|g" '{}' +
2115
done

app-frontend/react/index.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
<!--
2-
Copyright (C) 2024 Intel Corporation
2+
Copyright (C) 2025 Intel Corporation
33
SPDX-License-Identifier: Apache-2.0
44
-->
55

66
<!doctype html>
77
<html lang="en">
88
<head>
9-
<meta charset="UTF-8" />
10-
<link rel="icon" type="image/svg+xml" href="/src/assets/opea-icon-color.svg" />
11-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
12-
<title>Conversations UI</title>
9+
<meta charset="utf-8" />
10+
<link rel="shortcut icon" href="/favicon.ico" />
11+
<link rel="preconnect" href="https://fonts.googleapis.com" />
12+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
13+
<link
14+
href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
15+
rel="stylesheet"
16+
/>
17+
<meta name="viewport" content="width=device-width, initial-scale=1" />
18+
<meta name="theme-color" content="#000000" />
19+
<meta name="description" content="RAG ui for demonstrating LLM functionality" />
20+
<link rel="apple-touch-icon" href="logo192.png" />
21+
<link rel="manifest" href="/manifest.json" />
22+
<title>OPEA Studio APP</title>
1323
</head>
1424
<body>
25+
<noscript>You need to enable JavaScript to run this app.</noscript>
1526
<div id="root"></div>
16-
<script type="module" src="/src/main.tsx?v=APP_UUID"></script>
27+
<script type="module" src="/src/index.tsx"></script>
1728
</body>
1829
</html>

app-frontend/react/nginx.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ server {
1212
root /usr/share/nginx/html;
1313
index index.html index.htm;
1414
try_files $uri $uri/ /index.html =404;
15-
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
1615

1716
location ~* \.(gif|jpe?g|png|webp|ico|svg|css|js|mp4|woff2)$ {
1817
expires 1d;
1918
}
2019
}
21-
}
20+
}

0 commit comments

Comments
 (0)