Skip to content

Commit

Permalink
Merge branch 'main' into feature/text-splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisoSouza authored Jan 31, 2024
2 parents a18c561 + ec1c24b commit 7d7f75e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.1.1
----------
* Sentry integration
* Elasticsearch timeout configuration
* Route for / with status 200

v0.1.0
----------
* Index, Delete and Search products
Expand Down
3 changes: 2 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def __init__(self):
"HUGGINGFACE_API_TOKEN", "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"
),
}

self.sagemaker_aws ={
"endpoint_name": os.environ.get(
"SAGEMAKER_ENDPOINT_NAME",
Expand All @@ -41,3 +40,5 @@ def __init__(self):
self.content_base_index_name = os.environ.get(
"INDEX_CONTENTBASES_NAME", "content_bases"
)
self.sentry_dsn = os.environ.get("SENTRY_DSN", "")
self.es_timeout = os.environ.get("ELASTICSEARCH_TIMEOUT", "30")
5 changes: 0 additions & 5 deletions app/handlers/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def index(self, request: ProductIndexRequest):
docs = self.product_indexer.index(request.catalog_id, request.product)
return ProductIndexResponse(catalog_id=request.catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def batch_index(self, request: ProductBatchIndexRequest):
Expand All @@ -91,7 +90,6 @@ def batch_index(self, request: ProductBatchIndexRequest):
)
return ProductIndexResponse(catalog_id=request.catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def search(self, request: ProductSearchRequest):
Expand All @@ -101,7 +99,6 @@ def search(self, request: ProductSearchRequest):
)
return ProductSearchResponse(products=matched_products)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def delete(
Expand All @@ -117,7 +114,6 @@ def delete(
docs = self.product_indexer.delete(catalog_id, product_retailer_id)
return ProductIndexResponse(catalog_id=catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])

def delete_batch(self, request: ProductDeleteRequest):
Expand All @@ -127,5 +123,4 @@ def delete_batch(self, request: ProductDeleteRequest):
)
return ProductIndexResponse(catalog_id=request.catalog_id, documents=docs)
except Exception as e:
logger.error(msg=str(e))
raise HTTPException(status_code=500, detail=[{"msg": str(e)}])
15 changes: 15 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sentry_sdk
from elasticsearch import Elasticsearch
from fastapi import FastAPI
from langchain.embeddings import SagemakerEndpointEmbeddings, HuggingFaceHubEmbeddings
from langchain.embeddings.base import Embeddings
Expand Down Expand Up @@ -43,12 +45,20 @@ def __init__(self, config: AppConfig):
content_handler=content_handler,
)

if config.sentry_dsn != "":
sentry_sdk.init(
dsn=config.sentry_dsn,
)

self.api = FastAPI()
self.vectorstore = ElasticVectorSearch(
elasticsearch_url=config.es_url,
index_name=config.product_index_name,
embedding=self.embeddings,
)
self.vectorstore.client = Elasticsearch(
hosts=config.es_url, timeout=int(config.es_timeout)
)
self.elasticStore = ElasticsearchVectorStoreIndex(self.vectorstore)
self.products_indexer = ProductsIndexer(self.elasticStore)
self.products_handler = ProductsHandler(self.products_indexer)
Expand All @@ -74,3 +84,8 @@ def __init__(self, config: AppConfig):

config = AppConfig()
main_app = App(config)


@main_app.api.get('/', status_code=200)
def home():
return {}
50 changes: 49 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ docx2txt = "^0.8"
networkx = "^3.2.1"
pandas = "^2.1.2"
openpyxl = "^3.1.2"

python-dotenv = "^1.0.0"
pydantic = "2.3.0"
celery = "^5.3.6"
redis = "^5.0.1"
sentry-sdk = {extras = ["fastapi"], version = "^1.35.0"}


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit 7d7f75e

Please sign in to comment.