Commit 900930e3 authored by Bhargava Rellu's avatar Bhargava Rellu

Optimize imports

parent c05bf261
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,7 +3,7 @@ name = "reviewsense-ecom" ...@@ -3,7 +3,7 @@ name = "reviewsense-ecom"
version = "0.1.0" version = "0.1.0"
description = "" description = ""
authors = [ authors = [
{name = "BRellu",email = "brellu@nisum.com"} { name = "BRellu", email = "brellu@nisum.com" }
] ]
readme = "README.md" readme = "README.md"
requires-python = ">=3.12,<4.0" requires-python = ">=3.12,<4.0"
...@@ -22,7 +22,7 @@ dependencies = [ ...@@ -22,7 +22,7 @@ dependencies = [
[tool.poetry] [tool.poetry]
package-mode = false package-mode = false
packages = [{include = "reviewsense_ecom", from = "src"}] packages = [{ include = "reviewsense_ecom", from = "src" }]
[build-system] [build-system]
......
from langchain_groq import ChatGroq
from functools import lru_cache from functools import lru_cache
from langchain_core.messages import BaseMessage from langchain_groq import ChatGroq
from langchain_core.prompts import ChatPromptTemplate
@lru_cache(maxsize=1) # Cache only one instance (singleton behavior) @lru_cache(maxsize=1) # Cache only one instance (singleton behavior)
......
from fastapi import FastAPI from fastapi import FastAPI
from router.routes import router
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from router.routes import router
def create_app() -> FastAPI: def create_app() -> FastAPI:
""" """
......
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import List, Dict, Optional from typing import List
from bson import ObjectId
@dataclass @dataclass
class FeatureSentiment: class FeatureSentiment:
positive: List[str] = field(default_factory=list) positive: List[str] = field(default_factory=list)
negative: List[str] = field(default_factory=list) negative: List[str] = field(default_factory=list)
\ No newline at end of file
from pydantic import BaseModel from pydantic import BaseModel
class PercentageResponseModel(BaseModel): class PercentageResponseModel(BaseModel):
positive_percentage: str positive_percentage: str
negative_percentage: str negative_percentage: str
average_rating: float average_rating: float
\ No newline at end of file
...@@ -57,5 +57,3 @@ class Product: ...@@ -57,5 +57,3 @@ class Product:
"created_at": {"$date": self.created_at.isoformat() + "Z"} if self.created_at else None, "created_at": {"$date": self.created_at.isoformat() + "Z"} if self.created_at else None,
"updated_at": {"$date": self.updated_at.isoformat() + "Z"} if self.updated_at else None "updated_at": {"$date": self.updated_at.isoformat() + "Z"} if self.updated_at else None
} }
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import List, Dict, Optional, Any from typing import List, Dict, Optional, Any
from bson import ObjectId
from pydantic import Field from pydantic import Field
......
...@@ -7,4 +7,4 @@ class RatingSummary(BaseModel): ...@@ -7,4 +7,4 @@ class RatingSummary(BaseModel):
ratings_count: int ratings_count: int
average_rating: float average_rating: float
rating_distribution: Dict[str, int] rating_distribution: Dict[str, int]
total_reviews: List[str] total_reviews: List[str]
\ No newline at end of file
...@@ -4,4 +4,4 @@ from groq import BaseModel ...@@ -4,4 +4,4 @@ from groq import BaseModel
class ReviewResponseModel(BaseModel): class ReviewResponseModel(BaseModel):
reviews: List[str] reviews: List[str]
\ No newline at end of file
from pydantic import BaseModel, Field from pydantic import BaseModel
from typing import List, Optional
class UserMessage(BaseModel): class UserMessage(BaseModel):
message: str = "suggest me a mobile with okay battery backup" message: str = "suggest me a mobile with okay battery backup"
\ No newline at end of file
from pydantic import BaseModel, Field
from typing import List, Optional from typing import List, Optional
from pydantic import BaseModel, Field
class ProductReviewInput(BaseModel): class ProductReviewInput(BaseModel):
"""Input model for product review processing""" """Input model for product review processing"""
......
import urllib.parse import urllib.parse
from datetime import datetime, timezone
from pymongo import MongoClient from pymongo import MongoClient
from datetime import datetime, timezone
from src.reviewsense_ecom.model.ProductReview import ProductReview
from src.reviewsense_ecom.model.Product import Product
from src.reviewsense_ecom.model.FeatureSentiment import FeatureSentiment from src.reviewsense_ecom.model.FeatureSentiment import FeatureSentiment
from dotenv import load_dotenv from src.reviewsense_ecom.model.Product import Product
import os from src.reviewsense_ecom.model.ProductReview import ProductReview
# def get_db_connection(collection_name: str): #LOCAL DB # def get_db_connection(collection_name: str): #LOCAL DB
# client = MongoClient("mongodb://localhost:27017/") # Update with your MongoDB connection # client = MongoClient("mongodb://localhost:27017/") # Update with your MongoDB connection
...@@ -14,13 +14,15 @@ import os ...@@ -14,13 +14,15 @@ import os
# return db[collection_name] # db["productFeatureRater"] # Change to your collection name # return db[collection_name] # db["productFeatureRater"] # Change to your collection name
def get_db_connection(collection_name: str): #get_db_cloud_connection def get_db_connection(collection_name: str): # get_db_cloud_connection
password="nisum@123" password = "nisum@123"
escaped_password = urllib.parse.quote_plus(password) escaped_password = urllib.parse.quote_plus(password)
client = MongoClient(f"mongodb+srv://genai:{escaped_password}@productrater.hpbsn.mongodb.net/?retryWrites=true&w=majority&appName=productRater") # Update with your MongoDB connection client = MongoClient(
f"mongodb+srv://genai:{escaped_password}@productrater.hpbsn.mongodb.net/?retryWrites=true&w=majority&appName=productRater") # Update with your MongoDB connection
db = client["productRater"] # Change to your database name db = client["productRater"] # Change to your database name
return db[collection_name] return db[collection_name]
def insert_product(product_id): # Use this method to insert if null def insert_product(product_id): # Use this method to insert if null
collection = get_db_connection("productFeatureRater") collection = get_db_connection("productFeatureRater")
new_product = { new_product = {
......
# src/reviewsense/core/database.py # src/reviewsense/core/database.py
from functools import lru_cache from functools import lru_cache
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_astradb import AstraDBVectorStore
from langchain_astradb import AstraDBVectorStore
from langchain_huggingface import HuggingFaceEmbeddings
@lru_cache(maxsize=1) @lru_cache(maxsize=1)
......
...@@ -3,14 +3,14 @@ import logging ...@@ -3,14 +3,14 @@ import logging
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
from src.reviewsense_ecom.model.PercentageResponseModel import PercentageResponseModel from src.reviewsense_ecom.model.PercentageResponseModel import PercentageResponseModel
from src.reviewsense_ecom.model.Product import Product
from src.reviewsense_ecom.model.ReviewResponseModel import ReviewResponseModel 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
from src.reviewsense_ecom.service.FeatureUpdater import FeatureUpdater from src.reviewsense_ecom.service.FeatureUpdater import FeatureUpdater
from src.reviewsense_ecom.model.Product import Product
from src.reviewsense_ecom.service.ReviewService import ReviewService from src.reviewsense_ecom.service.ReviewService import ReviewService
from src.reviewsense_ecom.service.feature_extractor import FeatureExtractor from src.reviewsense_ecom.service.feature_extractor import FeatureExtractor
from src.reviewsense_ecom.mongo.mongo_db_config import get_product_by_id, update_product, add_review_features, \
insert_product, product_feature
from src.reviewsense_ecom.model.product_review_input import ProductReviewInput
router = APIRouter() router = APIRouter()
review_service = ReviewService() review_service = ReviewService()
......
from pydantic import BaseModel import os
import re
from typing import List, Dict
from dotenv import load_dotenv
from langchain.prompts import ChatPromptTemplate from langchain.prompts import ChatPromptTemplate
from langchain_core.output_parsers import JsonOutputParser from langchain_core.output_parsers import JsonOutputParser
from typing import List, Dict from pydantic import BaseModel
from src.reviewsense_ecom.llm.llm import get_llm from src.reviewsense_ecom.llm.llm import get_llm
import re
from dotenv import load_dotenv
import os
# Load environment variables from .env file # Load environment variables from .env file
load_dotenv() load_dotenv()
......
# router/review_rater.py # router/review_rater.py
from collections import defaultdict from collections import defaultdict
from typing import Dict, List, Optional from typing import Dict, List, Optional
import numpy as np import numpy as np
from transformers import pipeline from transformers import pipeline
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment