Skip to content

Commit ee2aad2

Browse files
lkk12014402chyundunovDatamonsters
authored andcommitted
compatible open-webui for opea agent. (opea-project#1765)
Signed-off-by: Chingis Yundunov <c.yundunov@datamonsters.com>
1 parent ce00546 commit ee2aad2

File tree

100 files changed

+780
-3830
lines changed

Some content is hidden

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

100 files changed

+780
-3830
lines changed

AgentQnA/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,16 @@ bash run_ingest_data.sh
208208
209209
## Launch the UI
210210

211-
Open a web browser to http://localhost:5173 to access the UI. Ensure the environment variable `AGENT_URL` is set to http://$ip_address:9090/v1/chat/completions in [ui/svelte/.env](./ui/svelte/.env) or else the UI may not work properly.
211+
Open a web browser to http://localhost:5173 to access the UI.
212212

213-
The AgentQnA UI can be deployed locally or using Docker. To customize deployment, refer to the [AgentQnA UI Guide](./ui/svelte/README.md).
213+
1. `create Admin Account` with a random value
214+
2. add opea agent endpoint `http://$ip_address:9090/v1` which is a openai compatible api
215+
216+
![opea-agent-setting](assets/img/opea-agent-setting.png)
217+
218+
3. test opea agent with ui
219+
220+
![opea-agent-test](assets/img/opea-agent-test.png)
214221

215222
## [Optional] Deploy using Helm Charts
216223

71 KB
Loading
99.4 KB
Loading

AgentQnA/docker_compose/intel/cpu/xeon/compose_openai.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ services:
103103
agent-ui:
104104
image: opea/agent-ui
105105
container_name: agent-ui
106-
volumes:
107-
- ${WORKDIR}/GenAIExamples/AgentQnA/ui/svelte/.env:/home/user/svelte/.env # test db
108106
ports:
109-
- "5173:5173"
107+
- "5173:8080"
110108
ipc: host
111109

112110
networks:

AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,10 @@ services:
106106
agent-ui:
107107
image: opea/agent-ui
108108
container_name: agent-ui
109-
volumes:
110-
- ${WORKDIR}/GenAIExamples/AgentQnA/ui/svelte/.env:/home/user/svelte/.env
111109
environment:
112110
host_ip: ${host_ip}
113111
ports:
114-
- "5173:5173"
112+
- "5173:8080"
115113
ipc: host
116114
vllm-service:
117115
image: ${REGISTRY:-opea}/vllm-gaudi:${TAG:-latest}

AgentQnA/docker_compose/intel/hpu/gaudi/set_env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if [ ! -f $WORKDIR/GenAIExamples/AgentQnA/tests/Chinook_Sqlite.sqlite ]; then
4242
fi
4343

4444
# configure agent ui
45-
echo "AGENT_URL = 'http://$ip_address:9090/v1/chat/completions'" | tee ${WORKDIR}/GenAIExamples/AgentQnA/ui/svelte/.env
45+
# echo "AGENT_URL = 'http://$ip_address:9090/v1/chat/completions'" | tee ${WORKDIR}/GenAIExamples/AgentQnA/ui/svelte/.env
4646

4747
# retriever
4848
export host_ip=$(hostname -I | awk '{print $1}')

AgentQnA/ui/docker/Dockerfile

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,49 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
# Use node 20.11.1 as the base image
5-
FROM node:20.11.1
4+
#FROM python:3.11-slim
5+
FROM node:22.9.0
66

7-
# Update package manager and install Git
8-
RUN apt-get update -y && apt-get install -y git
7+
ENV LANG=C.UTF-8
8+
ARG ARCH=cpu
99

10-
# Copy the front-end code repository
11-
COPY svelte /home/user/svelte
10+
RUN apt-get update -y && apt-get install -y --no-install-recommends --fix-missing \
11+
build-essential \
12+
libgl1-mesa-glx \
13+
libjemalloc-dev \
14+
git \
15+
python3-venv
1216

13-
# Set the working directory
14-
WORKDIR /home/user/svelte
1517

16-
# Install front-end dependencies
17-
RUN npm install
18+
WORKDIR /root/
1819

19-
# Build the front-end application
20-
RUN npm run build
20+
ENV HOME=/root
21+
ENV VIRTUAL_ENV=$HOME/.env/open-webui
22+
23+
COPY open_webui_patches /root/patches
24+
25+
RUN git clone https://github.com/open-webui/open-webui.git && \
26+
git config --global user.name "opea" && git config --global user.email "" && \
27+
mkdir -p $HOME/.env && python3 -m venv $VIRTUAL_ENV && \
28+
$VIRTUAL_ENV/bin/python -m pip install --no-cache-dir --upgrade pip && \
29+
$VIRTUAL_ENV/bin/python -m pip install --no-cache-dir build
30+
31+
WORKDIR /root/open-webui
32+
33+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
34+
35+
RUN git checkout v0.5.20 && \
36+
git am ../patches/*.patch && \
37+
python -m build && \
38+
pip install --no-cache-dir dist/open_webui-0.5.20-py3-none-any.whl
39+
40+
ENV LANG=en_US.UTF-8
41+
42+
WORKDIR /root/
43+
44+
RUN rm -fr /root/open-webui && rm -fr /root/patches
45+
46+
# CMD ["/bin/bash"]
47+
ENTRYPOINT ["open-webui", "serve"]
2148

22-
# Expose the port of the front-end application
23-
EXPOSE 5173
2449

25-
# Run the front-end application in preview mode
26-
CMD ["npm", "run", "preview", "--", "--port", "5173", "--host", "0.0.0.0"]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
From d90ba418f866bc11848d7d6507aabc6b5e8cc3e2 Mon Sep 17 00:00:00 2001
2+
From: lkk12014402 <kaokao.lv@intel.com>
3+
Date: Mon, 7 Apr 2025 07:22:53 +0000
4+
Subject: [PATCH] compatible opea agent tool content
5+
6+
---
7+
backend/open_webui/utils/middleware.py | 56 ++++++++++++++++++++++++++
8+
1 file changed, 56 insertions(+)
9+
10+
diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py
11+
index 289d887df..fddbe8ee1 100644
12+
--- a/backend/open_webui/utils/middleware.py
13+
+++ b/backend/open_webui/utils/middleware.py
14+
@@ -1465,6 +1465,8 @@ async def process_chat_response(
15+
async def stream_body_handler(response):
16+
nonlocal content
17+
nonlocal content_blocks
18+
+ nonlocal events
19+
+ sources = []
20+
21+
response_tool_calls = []
22+
23+
@@ -1486,6 +1488,60 @@ async def process_chat_response(
24+
try:
25+
data = json.loads(data)
26+
27+
+ tool_content_block = []
28+
+ if data.get("tool_name"):
29+
+ sources.append(
30+
+ {
31+
+ "source": {
32+
+ "name": f"TOOL:{data.get('tool_name')}"},
33+
+ "document": [data.get("tool_content")],
34+
+ "metadata": [{
35+
+ "source": f"TOOL:{data.get('tool_name')}"}],
36+
+ }
37+
+ )
38+
+ events.append({"sources": sources})
39+
+
40+
+ await event_emitter(
41+
+ {
42+
+ "type": "chat:completion",
43+
+ "data": {"sources": sources},
44+
+ }
45+
+ )
46+
+ tool_content_block = [
47+
+ {
48+
+ "type": "tool_calls",
49+
+ "content": [
50+
+ {"id": data.get('tool_name'), "function": {"name": data.get('tool_name')}}
51+
+ ]
52+
+ }
53+
+ ]
54+
+
55+
+ await event_emitter(
56+
+ {
57+
+ "type": "chat:completion",
58+
+ "data": {
59+
+ "content": serialize_content_blocks(tool_content_block),
60+
+ },
61+
+ }
62+
+ )
63+
+
64+
+ tool_content_block = [
65+
+ {
66+
+ "type": "tool_calls",
67+
+ "content": [
68+
+ {"id": data.get('tool_name'), "function": {"name": data.get('tool_name')}}
69+
+ ],
70+
+ "results": [
71+
+ {"tool_call_id": data.get('tool_name'), "content": data.get("tool_content")}
72+
+ ]
73+
+ },
74+
+ {
75+
+ "type": "text",
76+
+ "content": "",
77+
+ }
78+
+ ]
79+
+ content_blocks.extend(tool_content_block)
80+
+
81+
data, _ = await process_filter_functions(
82+
request=request,
83+
filter_functions=filter_functions,
84+
--
85+
2.34.1
86+

0 commit comments

Comments
 (0)