-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Guardrails and Embedding microservices (#15)
* Add Guardrails and Embedding microservices Signed-off-by: lvliang-intel <[email protected]>
- Loading branch information
1 parent
3341e3f
commit 1f6c1a5
Showing
11 changed files
with
68 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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. | ||
|
||
import os | ||
|
||
from langchain_community.embeddings import HuggingFaceHubEmbeddings | ||
|
||
from comps import EmbedDoc1024, TextDoc, opea_microservices, register_microservice | ||
|
||
|
||
@register_microservice( | ||
name="opea_service@embedding_tgi_gaudi", | ||
expose_endpoint="/v1/embeddings", | ||
port=8020, | ||
input_datatype=TextDoc, | ||
output_datatype=TextDoc, | ||
) | ||
def safety_guard(input: TextDoc) -> TextDoc: | ||
embed_vector = embeddings.embed_query(input.text) | ||
res = EmbedDoc1024(text=input.text, embedding=embed_vector) | ||
return res | ||
|
||
|
||
if __name__ == "__main__": | ||
tei_embedding_endpoint = os.getenv("TEI_ENDPOINT", "http://localhost:8080") | ||
embeddings = HuggingFaceHubEmbeddings(model=tei_embedding_endpoint) | ||
print("TEI Gaudi Embedding initialized.") | ||
opea_microservices["opea_service@embedding_tgi_gaudi"].start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
comps/embeddings/requirements.txt → comps/embeddings/langchain/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
docarray[full] | ||
fastapi | ||
langchain | ||
sentence_transformers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.