Skip to content

compatible open-webui for opea agent. #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions AgentQnA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,16 @@ bash run_ingest_data.sh

## Launch the UI

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.
Open a web browser to http://localhost:5173 to access the UI.

The AgentQnA UI can be deployed locally or using Docker. To customize deployment, refer to the [AgentQnA UI Guide](./ui/svelte/README.md).
1. `create Admin Account` with a random value
2. add opea agent endpoint `http://$ip_address:9090/v1` which is a openai compatible api

![opea-agent-setting](assets/img/opea-agent-setting.png)

3. test opea agent with ui

![opea-agent-test](assets/img/opea-agent-test.png)

## [Optional] Deploy using Helm Charts

Expand Down
Binary file added AgentQnA/assets/img/opea-agent-setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AgentQnA/assets/img/opea-agent-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ services:
agent-ui:
image: opea/agent-ui
container_name: agent-ui
volumes:
- ${WORKDIR}/GenAIExamples/AgentQnA/ui/svelte/.env:/home/user/svelte/.env # test db
ports:
- "5173:5173"
- "5173:8080"
ipc: host

networks:
Expand Down
4 changes: 1 addition & 3 deletions AgentQnA/docker_compose/intel/hpu/gaudi/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ services:
agent-ui:
image: opea/agent-ui
container_name: agent-ui
volumes:
- ${WORKDIR}/GenAIExamples/AgentQnA/ui/svelte/.env:/home/user/svelte/.env
environment:
host_ip: ${host_ip}
ports:
- "5173:5173"
- "5173:8080"
ipc: host
vllm-service:
image: ${REGISTRY:-opea}/vllm-gaudi:${TAG:-latest}
Expand Down
2 changes: 1 addition & 1 deletion AgentQnA/docker_compose/intel/hpu/gaudi/set_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if [ ! -f $WORKDIR/GenAIExamples/AgentQnA/tests/Chinook_Sqlite.sqlite ]; then
fi

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

# retriever
export host_ip=$(hostname -I | awk '{print $1}')
Expand Down
55 changes: 39 additions & 16 deletions AgentQnA/ui/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# Use node 20.11.1 as the base image
FROM node:20.11.1
#FROM python:3.11-slim
FROM node:22.9.0

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

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

# Set the working directory
WORKDIR /home/user/svelte

# Install front-end dependencies
RUN npm install
WORKDIR /root/

# Build the front-end application
RUN npm run build
ENV HOME=/root
ENV VIRTUAL_ENV=$HOME/.env/open-webui

COPY open_webui_patches /root/patches

RUN git clone https://github.com/open-webui/open-webui.git && \
git config --global user.name "opea" && git config --global user.email "" && \
mkdir -p $HOME/.env && python3 -m venv $VIRTUAL_ENV && \
$VIRTUAL_ENV/bin/python -m pip install --no-cache-dir --upgrade pip && \
$VIRTUAL_ENV/bin/python -m pip install --no-cache-dir build

WORKDIR /root/open-webui

ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN git checkout v0.5.20 && \
git am ../patches/*.patch && \
python -m build && \
pip install --no-cache-dir dist/open_webui-0.5.20-py3-none-any.whl

ENV LANG=en_US.UTF-8

WORKDIR /root/

RUN rm -fr /root/open-webui && rm -fr /root/patches

# CMD ["/bin/bash"]
ENTRYPOINT ["open-webui", "serve"]

# Expose the port of the front-end application
EXPOSE 5173

# Run the front-end application in preview mode
CMD ["npm", "run", "preview", "--", "--port", "5173", "--host", "0.0.0.0"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
From d90ba418f866bc11848d7d6507aabc6b5e8cc3e2 Mon Sep 17 00:00:00 2001
From: lkk12014402 <kaokao.lv@intel.com>
Date: Mon, 7 Apr 2025 07:22:53 +0000
Subject: [PATCH] compatible opea agent tool content

---
backend/open_webui/utils/middleware.py | 56 ++++++++++++++++++++++++++
1 file changed, 56 insertions(+)

diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py
index 289d887df..fddbe8ee1 100644
--- a/backend/open_webui/utils/middleware.py
+++ b/backend/open_webui/utils/middleware.py
@@ -1465,6 +1465,8 @@ async def process_chat_response(
async def stream_body_handler(response):
nonlocal content
nonlocal content_blocks
+ nonlocal events
+ sources = []

response_tool_calls = []

@@ -1486,6 +1488,60 @@ async def process_chat_response(
try:
data = json.loads(data)

+ tool_content_block = []
+ if data.get("tool_name"):
+ sources.append(
+ {
+ "source": {
+ "name": f"TOOL:{data.get('tool_name')}"},
+ "document": [data.get("tool_content")],
+ "metadata": [{
+ "source": f"TOOL:{data.get('tool_name')}"}],
+ }
+ )
+ events.append({"sources": sources})
+
+ await event_emitter(
+ {
+ "type": "chat:completion",
+ "data": {"sources": sources},
+ }
+ )
+ tool_content_block = [
+ {
+ "type": "tool_calls",
+ "content": [
+ {"id": data.get('tool_name'), "function": {"name": data.get('tool_name')}}
+ ]
+ }
+ ]
+
+ await event_emitter(
+ {
+ "type": "chat:completion",
+ "data": {
+ "content": serialize_content_blocks(tool_content_block),
+ },
+ }
+ )
+
+ tool_content_block = [
+ {
+ "type": "tool_calls",
+ "content": [
+ {"id": data.get('tool_name'), "function": {"name": data.get('tool_name')}}
+ ],
+ "results": [
+ {"tool_call_id": data.get('tool_name'), "content": data.get("tool_content")}
+ ]
+ },
+ {
+ "type": "text",
+ "content": "",
+ }
+ ]
+ content_blocks.extend(tool_content_block)
+
data, _ = await process_filter_functions(
request=request,
filter_functions=filter_functions,
--
2.34.1

Loading
Loading