Skip to content

Commit

Permalink
Merge branch 'main' into feat/pgvector
Browse files Browse the repository at this point in the history
  • Loading branch information
ganesanintel authored Jun 3, 2024
2 parents 4dcd3f8 + db3b4f1 commit ab7c5cb
Show file tree
Hide file tree
Showing 139 changed files with 1,175 additions and 1,584 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/docker/code-scan.dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

ARG UBUNTU_VER=22.04
FROM ubuntu:${UBUNTU_VER} as devel
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/docker/ut.dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

ARG UBUNTU_VER=22.04
FROM ubuntu:${UBUNTU_VER} as devel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches: [main]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- .github/workflows/mega-test.yml
- .github/workflows/megaservice-test.yml
- comps/cores/**
- requirements.txt
- setup.py
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
# - name: Run Workflow
# env:
# HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
# HF_TOKEN: ${{ secrets.HF_TOKEN }}
# run: |
# xxx

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/microservice-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
run: |
set -xe
changed_files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} \
| grep 'comps/' | grep -vE '*.md|*.txt')
services=$(printf '%s\n' "${changed_files[@]}" | grep '/' | cut -d'/' -f2 | sort -u)
| grep 'comps/' | grep -vE '*.md|*.txt|comps/cores')
services=$(printf '%s\n' "${changed_files[@]}" | cut -d'/' -f2 | grep -vE '*.py' | sort -u)
run_matrix="{\"include\":["
for service in ${services}; do
hardware="gaudi" # default hardware, set based on the changed files
Expand All @@ -62,7 +62,7 @@ jobs:

- name: Run microservice test
env:
HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
service: ${{ matrix.service }}
hardware: ${{ matrix.hardware }}
run: |
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/scripts/codeScan/bandit.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
#!/bin/bash
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

source /GenAIComps/.github/workflows/scripts/change_color
pip install bandit==1.7.8
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/scripts/codeScan/hadolint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
#!/bin/bash
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

source /GenAIComps/.github/workflows/scripts/change_color
log_dir=/GenAIComps/.github/workflows/scripts/codeScan
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/scripts/codeScan/trellix.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
#!/bin/bash
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

source ${workspace}/.github/workflows/scripts/change_color
log_dir=${workspace}/.github/workflows/scripts/codeScan
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/scripts/test_ut.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
#!/bin/bash

# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

test_name=$1

Expand Down
18 changes: 15 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

ci:
autofix_prs: true
autoupdate_schedule: quarterly
Expand All @@ -18,13 +21,22 @@ repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
- id: insert-license
files: (Dockerfile)$
args:
[
--license-filepath=.github/license_template.txt,
--use-current-year,
--detect-license-in-X-top-lines=5,
--skip-license-insertion-comment=Copyright,
]
- id: insert-license
files: (.*\.(py|yaml|yml|sh))$
args:
[
--license-filepath=.github/license_template.txt,
--use-current-year,
--detect-license-in-X-top-lines=40,
--detect-license-in-X-top-lines=5,
--skip-license-insertion-comment=Copyright,
]
- id: insert-license
Expand All @@ -33,7 +45,7 @@ repos:
[
--license-filepath=.github/license_template.txt,
--use-current-year,
--detect-license-in-X-top-lines=40,
--detect-license-in-X-top-lines=5,
--skip-license-insertion-comment=Copyright,
--comment-style=//,
]
Expand All @@ -43,7 +55,7 @@ repos:
[
--license-filepath=.github/license_template.txt,
--use-current-year,
--detect-license-in-X-top-lines=40,
--detect-license-in-X-top-lines=5,
--skip-license-insertion-comment=Copyright,
--comment-style=<!--| |-->,
]
Expand Down
10 changes: 0 additions & 10 deletions LEGAL_INFORMATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

1. [License](#license)
2. [Citation](#citation)
3. [Trademarks](#trademarks)

## License

Expand All @@ -26,12 +25,3 @@ If you use Generative AI Examples in your research, use the following BibTeX ent
year = {2024}
}
```

## Trademarks

Intel, the Intel logo, Intel Atom, Intel Core, Intel Xeon Phi, Pentium,
VTune, and Xeon are trademarks of Intel Corporation or its subsidiaries.

\* Other names and brands may be claimed as the property of others.

Copyright, Intel Corporation
108 changes: 106 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,31 @@ GenAIComps provides a suite of microservices, leveraging a service composer to a

![Architecture](https://i.imgur.com/r5J0i8j.png)

### Installation

- Install from Pypi

```bash
pip install opea-comps
```

- Build from Source

```bash
git clone https://github.com/opea-project/GenAIComps
cd GenAIComps
pip install -e .
```

## MicroService

The initially supported microservices are described in the below table. More microservices are on the way.
`Microservices` are akin to building blocks, offering the fundamental services for constructing `RAG (Retrieval-Augmented Generation)` applications.

Each `Microservice` is designed to perform a specific function or task within the application architecture. By breaking down the system into smaller, self-contained services, `Microservices` promote modularity, flexibility, and scalability.

This modular approach allows developers to independently develop, deploy, and scale individual components of the application, making it easier to maintain and evolve over time. Additionally, `Microservices` facilitate fault isolation, as issues in one service are less likely to impact the entire system.

The initially supported `Microservices` are described in the below table. More `Microservices` are on the way.

<table>
<tbody>
Expand Down Expand Up @@ -89,7 +111,89 @@ The initially supported microservices are described in the below table. More mic
</tbody>
</table>

## MegaService (under construction)
A `Microservices` can be created by using the decorator `register_microservice`. Taking the `embedding microservice` as an example:

```python
from langchain_community.embeddings import HuggingFaceHubEmbeddings
from langsmith import traceable

from comps import register_microservice, EmbedDoc768, ServiceType, TextDoc


@register_microservice(
name="opea_service@embedding_tgi_gaudi",
service_type=ServiceType.EMBEDDING,
endpoint="/v1/embeddings",
host="0.0.0.0",
port=6000,
input_datatype=TextDoc,
output_datatype=EmbedDoc768,
)
@traceable(run_type="embedding")
def embedding(input: TextDoc) -> EmbedDoc768:
embed_vector = embeddings.embed_query(input.text)
embed_vector = embed_vector[:768] # Keep only the first 768 elements
res = EmbedDoc768(text=input.text, embedding=embed_vector)
return res
```

## MegaService

A `Megaservice` is a higher-level architectural construct composed of one or more `Microservices`, providing the capability to assemble end-to-end applications. Unlike individual `Microservices`, which focus on specific tasks or functions, a `Megaservice` orchestrates multiple `Microservices` to deliver a comprehensive solution.

`Megaservices` encapsulate complex business logic and workflow orchestration, coordinating the interactions between various `Microservices` to fulfill specific application requirements. This approach enables the creation of modular yet integrated applications, where each `Microservice` contributes to the overall functionality of the `Megaservice`.

Here is a simple example of building `Megaservice`:

```python
from comps import MicroService, ServiceOrchestrator

EMBEDDING_SERVICE_HOST_IP = os.getenv("EMBEDDING_SERVICE_HOST_IP", "0.0.0.0")
EMBEDDING_SERVICE_PORT = os.getenv("EMBEDDING_SERVICE_PORT", 6000)
LLM_SERVICE_HOST_IP = os.getenv("LLM_SERVICE_HOST_IP", "0.0.0.0")
LLM_SERVICE_PORT = os.getenv("LLM_SERVICE_PORT", 9000)


class ExampleService:
def __init__(self, host="0.0.0.0", port=8000):
self.host = host
self.port = port
self.megaservice = ServiceOrchestrator()

def add_remote_service(self):
embedding = MicroService(
name="embedding",
host=EMBEDDING_SERVICE_HOST_IP,
port=EMBEDDING_SERVICE_PORT,
endpoint="/v1/embeddings",
use_remote_service=True,S
service_type=ServiceType.EMBEDDING,
)
llm = MicroService(
name="llm",
host=LLM_SERVICE_HOST_IP,
port=LLM_SERVICE_PORT,
endpoint="/v1/chat/completions",
use_remote_service=True,
service_type=ServiceType.LLM,
)
self.megaservice.add(embedding).add(llm)
self.megaservice.flow_to(embedding, llm)
```

## Gateway

The `Gateway` serves as the interface for users to access the `Megaservice`, providing customized access based on user requirements. It acts as the entry point for incoming requests, routing them to the appropriate `Microservices` within the `Megaservice` architecture.

`Gateways` support API definition, API versioning, rate limiting, and request transformation, allowing for fine-grained control over how users interact with the underlying `Microservices`. By abstracting the complexity of the underlying infrastructure, `Gateways` provide a seamless and user-friendly experience for interacting with the `Megaservice`.

For example, the `Gateway` for `ChatQnA` can be built like this:

```python
from comps import ChatQnAGateway

self.gateway = ChatQnAGateway(megaservice=self.megaservice, host="0.0.0.0", port=self.port)
```

## Additional Content

Expand Down
6 changes: 1 addition & 5 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Security Policy

Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation.

## Reporting a Vulnerability

Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html).
Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.linuxfoundation.org/security).

## Script Usage Notice

Expand Down
16 changes: 2 additions & 14 deletions comps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# Document
from comps.cores.proto.docarray import (
Expand Down
3 changes: 3 additions & 0 deletions comps/asr/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

FROM python:3.11-slim

ENV LANG C.UTF-8
Expand Down
Loading

0 comments on commit ab7c5cb

Please sign in to comment.