Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ecom-svc-reviewsense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bhargava Rellu
ecom-svc-reviewsense
Commits
3b6c3e15
Commit
3b6c3e15
authored
Apr 18, 2025
by
BRellu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding the product name param for product reviews
parent
81afdc4b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
20 deletions
+22
-20
ProductReview.py
src/reviewsense_ecom/model/ProductReview.py
+1
-0
mongo_db_config.py
src/reviewsense_ecom/mongo/mongo_db_config.py
+15
-14
routes.py
src/reviewsense_ecom/router/routes.py
+4
-4
review_adder.py
src/reviewsense_ecom/service/review_adder.py
+2
-2
No files found.
src/reviewsense_ecom/model/ProductReview.py
View file @
3b6c3e15
...
...
@@ -9,6 +9,7 @@ class ProductReview:
# id: Optional[ObjectId] = None
product_id
:
str
=
""
review
:
Optional
[
str
]
=
Field
(
default
=
None
,
max_length
=
5000
,
description
=
"Review text"
)
product_Name
:
Optional
[
str
]
=
None
rating
:
float
=
0.0
# features: List[Dict[str, FeatureSentiment]] = field(default_factory=list)
features
:
List
[
Dict
[
str
,
Dict
[
str
,
Any
]]]
=
field
(
default_factory
=
list
)
src/reviewsense_ecom/mongo/mongo_db_config.py
View file @
3b6c3e15
...
...
@@ -21,17 +21,17 @@ password = urllib.parse.quote_plus(os.getenv("MONGODB_PASSWORD")) # escape spec
cluster
=
os
.
getenv
(
"MONGODB_CLUSTER"
)
appname
=
os
.
getenv
(
"MONGODB_APPNAME"
)
#
def get_db_connection(collection_name: str): #LOCAL DB
#
client = MongoClient("mongodb://localhost:27017/") # Update with your MongoDB connection
#
db = client["productRater"] # Change to your database name
#
return db[collection_name] # db["productFeatureRater"] # Change to your collection name
def
get_db_connection
(
collection_name
:
str
):
#LOCAL DB
client
=
MongoClient
(
"mongodb://localhost:27017/"
)
# Update with your MongoDB connection
db
=
client
[
"productRater"
]
# Change to your database name
return
db
[
collection_name
]
# db["productFeatureRater"] # Change to your collection name
def
get_db_connection
(
collection_name
:
str
):
# get_db_cloud_connection
mongo_uri
=
f
"mongodb+srv://{username}:{password}@{cluster}/?retryWrites=true&w=majority&appName={appname}"
client
=
MongoClient
(
mongo_uri
)
db
=
client
[
"productRater"
]
# Change to your database name
return
db
[
collection_name
]
#
def get_db_connection(collection_name: str): # get_db_cloud_connection
#
mongo_uri = f"mongodb+srv://{username}:{password}@{cluster}/?retryWrites=true&w=majority&appName={appname}"
#
client = MongoClient(mongo_uri)
#
db = client["productRater"] # Change to your database name
#
return db[collection_name]
def
insert_product
(
product_id
):
# Use this method to insert if null
...
...
@@ -109,7 +109,7 @@ def add_review(input_data, reviews_by_feature):
# adding New Reviews to productReview Collection
def
add_review_features
(
input_data
,
reviews_by_feature
):
def
add_review_features
(
input_data
,
reviews_by_feature
,
productName
):
collection
=
get_db_connection
(
"productReviews"
)
# Create a dictionary to store features with their corresponding sentiments
...
...
@@ -136,6 +136,7 @@ def add_review_features(input_data, reviews_by_feature):
# Create the ProductReview object
new_review
=
ProductReview
(
product_id
=
input_data
.
product_id
,
product_Name
=
productName
,
review
=
input_data
.
new_review
,
rating
=
input_data
.
new_rating
,
features
=
features_list
...
...
@@ -149,7 +150,7 @@ def add_review_features(input_data, reviews_by_feature):
# ✅ Add review to vector DB
try
:
review_adder
=
ReviewAdder
()
vector_id
=
review_adder
.
add_review_vector
(
input_data
.
product_id
,
input_data
.
new_review
)
vector_id
=
review_adder
.
add_review_vector
(
productName
,
input_data
.
product_id
,
input_data
.
new_review
)
print
(
f
"Review also added to Vector DB with ID: {vector_id} "
)
except
Exception
as
e
:
print
(
f
"Failed to add review to vector DB: {e}"
)
...
...
@@ -158,10 +159,10 @@ def add_review_features(input_data, reviews_by_feature):
return
new_review
.
__dict__
def
product_
feature
(
product_id
):
def
product_
details
(
product_id
):
collection
=
get_db_connection
(
"productFeatures"
)
product
=
collection
.
find_one
({
"product_id"
:
product_id
},
{
"_id"
:
0
,
"feature"
:
1
})
product
=
collection
.
find_one
({
"product_id"
:
product_id
},
{
"_id"
:
0
,
"feature"
:
1
,
"name"
:
1
})
if
product
and
"feature"
in
product
:
return
product
[
"feature"
]
return
{
"features"
:
product
[
"feature"
],
"name"
:
product
[
"name"
]}
return
[]
src/reviewsense_ecom/router/routes.py
View file @
3b6c3e15
...
...
@@ -7,7 +7,7 @@ from src.reviewsense_ecom.model.Product import Product
from
src.reviewsense_ecom.model.ReviewResponseModel
import
ReviewResponseModel
from
src.reviewsense_ecom.model.product_review_input
import
ProductReviewInput
from
src.reviewsense_ecom.mongo.mongo_db_config
import
get_product_by_id
,
update_product
,
add_review_features
,
\
insert_product
,
product_
feature
insert_product
,
product_
details
from
src.reviewsense_ecom.service.FeatureExtractor
import
FeatureExtractor
from
src.reviewsense_ecom.service.FeatureUpdater
import
FeatureUpdater
from
src.reviewsense_ecom.service.ReviewService
import
ReviewService
...
...
@@ -89,14 +89,14 @@ async def fetch_review_by_feature(product_id: str, features: str): # Required
async
def
update_product_data
(
input_data
,
product_data
):
# ✅ Second Flow: Update Feature Ratings in Another Collection FROM LLM
features
=
product_feature
(
input_data
.
product_id
)
productDetails
=
product_details
(
input_data
.
product_id
)
reviews_by_feature
=
feature_extractor
.
extract_feature_reviews
(
input_data
.
new_review
,
features
)
input_data
.
new_review
,
productDetails
[
"features"
]
)
ratings
=
review_service
.
fetch_feature_ratings
(
reviews_by_feature
)
logger
.
info
(
f
"Generated ratings: {ratings}"
)
# ✅ First Flow: Add Review to a Separate Collection TO REVIEWS
new_review_data
=
add_review_features
(
input_data
,
reviews_by_feature
)
new_review_data
=
add_review_features
(
input_data
,
reviews_by_feature
,
productDetails
[
"name"
]
)
if
new_review_data
:
logger
.
info
(
f
"Successfully added review data: {new_review_data}"
)
else
:
...
...
src/reviewsense_ecom/service/review_adder.py
View file @
3b6c3e15
...
...
@@ -9,6 +9,6 @@ class ReviewAdder:
def
__init__
(
self
):
self
.
vector_store
=
get_vector_store
()
def
add_review_vector
(
self
,
product_id
:
str
,
review
:
str
)
->
str
:
review_document
=
Document
(
page_content
=
review
,
metadata
=
{
"title"
:
product_id
})
def
add_review_vector
(
self
,
product_
name
:
str
,
product_
id
:
str
,
review
:
str
)
->
str
:
review_document
=
Document
(
page_content
=
review
,
metadata
=
{
"title"
:
product_
name
,
"product_id"
:
product_
id
})
return
self
.
vector_store
.
add_documents
([
review_document
])[
0
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment