Skip to content
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

Revert "keycloak integration, mysql enablement, megaservice refactor and import sample button" #28

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/_e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
fi
sleep 5
sudo apt install ansible -y
ansible-playbook genai-studio.yml -e "container_registry=${OPEA_IMAGE_REPO}opea" -e "container_tag=${{ inputs.tag }}" -e "mysql_host=$(hostname -I | awk '{print $1}')"
ansible-playbook genai-studio.yml -e "container_registry=${OPEA_IMAGE_REPO}opea" -e "container_tag=${{ inputs.tag }}"
sleep 5
kubectl wait --for=condition=ready pod --all --namespace=studio --timeout=300s --field-selector=status.phase!=Succeeded
kubectl wait --for=condition=ready pod --all --namespace=monitoring --timeout=300s --field-selector=status.phase!=Succeeded
Expand All @@ -74,7 +74,7 @@ jobs:
- name: Update Playwright Config
run: |
NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
sed -i "s|baseURL:.*|baseURL: \"https://$NODE_IP:30007\",|" playwright.config.js
sed -i "s|baseURL:.*|baseURL: \"http://$NODE_IP:30007\",|" playwright.config.js
working-directory: ${{ github.workspace }}/tests/playwright

- name: Run Playwright Tests
Expand Down
6 changes: 4 additions & 2 deletions app-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ RUN useradd -m -s /bin/bash user && \
chown -R user /home/user/

WORKDIR /home/user/
RUN git clone --depth 1 https://github.com/opea-project/GenAIComps.git
# temporary pointing to v1.1 GenAIComps for Gateway dependency
RUN git clone https://github.com/opea-project/GenAIComps.git -b v1.1rc

WORKDIR /home/user/GenAIComps
RUN pip install --no-cache-dir --upgrade pip==24.3.1 setuptools==75.3.0 && \
pip install --no-cache-dir -r /home/user/GenAIComps/requirements.txt

COPY ./app_gateway.py /home/user/app_gateway.py
COPY ./templates/microservices/* /home/user/templates/microservices/
COPY ./megaservice.py /home/user/megaservice.py
COPY config/* /home/user/config/
Expand All @@ -30,4 +32,4 @@ WORKDIR /home/user

RUN echo 'ulimit -S -n 999999' >> ~/.bashrc

ENTRYPOINT ["python", "megaservice.py"]
ENTRYPOINT ["python", "megaservice.py"]
89 changes: 89 additions & 0 deletions app-backend/app_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import os
import json
import logging

# library import
from fastapi import Request
from fastapi.responses import StreamingResponse

# comps import
from comps import Gateway, MicroService, ServiceOrchestrator, ServiceType
from comps.cores.proto.api_protocol import (
AudioChatCompletionRequest,
ChatCompletionRequest,
ChatCompletionResponse,
ChatCompletionResponseChoice,
ChatMessage,
EmbeddingRequest,
UsageInfo
)
from comps.cores.proto.docarray import LLMParams, LLMParamsDoc, RerankedDoc, RerankerParms, RetrieverParms, TextDoc

category_params_map = {
'LLM': LLMParams,
'Reranking': RerankerParms,
'Retreiver': RetrieverParms,
}

class AppGateway(Gateway):
def __init__(self, megaservice, host='0.0.0.0', port=8888):
try:
with open('config/project-info.json', 'r') as f:
self.project_info = json.load(f)
except:
logging.error('Failed to load project-info.json')
super().__init__(
megaservice, host, port, '/v1/app-backend', ChatCompletionRequest, ChatCompletionResponse
)

async def handle_request(self, request: Request):
data = await request.json()
print('\n'*5, '====== handle_request ======\n', data)
if 'chat_completion_ids' in self.project_info:
prompt = self._handle_message(data['messages'])
params = {}
llm_parameters = None
for id, node in self.project_info['nodes'].items():
if node['category'] in category_params_map:
param_class = category_params_map[node['category']]()
param_keys = [key for key in dir(param_class) if not key.startswith('__') and not callable(getattr(param_class, key))]
print('param_keys', param_keys)
params_dict = {}
for key in param_keys:
if key in data:
params_dict[key] = data[key]
# hadle special case for stream and streaming
if key in ['stream', 'streaming']:
params_dict[key] = data.get('stream', True) and data.get('streaming', True)
elif key in node['inference_params']:
params_dict[key] = node['inference_params'][key]
params[id] = params_dict
if node['category'] == 'LLM':
params[id]['max_new_tokens'] = params[id]['max_tokens']
llm_parameters = LLMParams(**params[id])
result_dict, runtime_graph = await self.megaservice.schedule(
initial_inputs={'query':prompt, 'text': prompt},
llm_parameters=llm_parameters,
params=params,
)
print('runtime_graph', runtime_graph.graph)
for node, response in result_dict.items():
if isinstance(response, StreamingResponse):
return response
last_node = runtime_graph.all_leaves()[-1]
print('result_dict:', result_dict)
print('last_node:',last_node)
response = result_dict[last_node]['text']
choices = []
usage = UsageInfo()
choices.append(
ChatCompletionResponseChoice(
index=0,
message=ChatMessage(role='assistant', content=response),
finish_reason='stop',
)
)
return ChatCompletionResponse(model='custom_app', choices=choices, usage=usage)
Loading
Loading