npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

saksh-real-estate

v1.0.4

Published

A package for managing properties and generating recommendations using ChatGPT.

Downloads

208

Readme

Saksh Real Estate

A powerful Node.js package designed for managing properties and generating personalized recommendations using ChatGPT.

Features

  • Property Management: Create, read, update, and delete properties effortlessly.
  • Advanced Search: Search properties based on various criteria such as location, type, price range, and more.
  • Similar Properties: Discover properties similar to a given property based on location, type, and price range.
  • Property Recommendations: Generate tailored property recommendations based on user browsing history and preferences using ChatGPT.
  • Predict Property Value: Leverage AI to predict the value of a property.
  • Change Logs: Maintain a comprehensive log of changes made to properties.

Installation

To install the package, use npm:

npm install saksh-real-estate

Usage

Setting Up

Begin by setting up your Express server and MongoDB connection:

const express = require('express');
const mongoose = require('mongoose');
const SakshPropertyClass = require('saksh-real-estate/classes/SakshPropertyClass');
const SakshChatGPTClass = require('saksh-real-estate/classes/SakshChatGPTClass');

const app = express();
app.use(express.json());

mongoose.connect('mongodb://localhost:27017/real-estate', {
  useNewUrlParser: true,
  useUnifiedTopology: true
});

// Middleware to simulate a logged-in user
const fakeAuth = (req, res, next) => {
  req.user = { id: 'fakeUserId', name: 'Fake User' };
  next();
};

app.use(fakeAuth);

// Initialize SakshPropertyClass and SakshChatGPTClass with your OpenAI API key
const propertyClass = new SakshPropertyClass();
const chatGPTClass = new SakshChatGPTClass('your-openai-api-key');

// Define your routes here...

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Event Handling with SakshChatGPTClass

You can enhance your application by using event handling with the SakshChatGPTClass. Here’s how:

const SakshChatGPTClass = require('./SakshChatGPTClass');

const chatGPT = new SakshChatGPTClass('your-openai-api-key');

chatGPT.on('requestStarted', (data) => {
  console.log('Request started:', data);
});

chatGPT.on('requestCompleted', (data) => {
  console.log('Request completed:', data);
});

chatGPT.on('requestFailed', (data) => {
  console.error('Request failed:', data);
});

chatGPT.on('recommendationStarted', (data) => {
  console.log('Recommendation started:', data);
});

chatGPT.on('recommendationCompleted', (data) => {
  console.log('Recommendation completed:', data);
});

chatGPT.on('recommendationFailed', (data) => {
  console.error('Recommendation failed:', data);
});

// Example usage
(async () => {
  try {
    const browsingHistory = { /* your browsing history data */ };
    const userPreferences = { /* your user preferences data */ };
    const result = await chatGPT.sakshRecommendPropertiesFromHistory(browsingHistory, userPreferences);
    console.log('Recommendations:', result);
  } catch (error) {
    console.error('Error:', error);
  }
})();

Event Handling with SakshPropertyClass

You can also handle events related to property management with the SakshPropertyClass. Here’s how:

propertyClass.on('propertyCreated', (property) => {
  console.log(`Property created: ${property._id}`);
});

propertyClass.on('propertyUpdated', (property) => {
  console.log(`Property updated: ${property._id}`);
});

propertyClass.on('propertyDeleted', (property) => {
  console.log(`Property deleted: ${property._id}`);
});

// Create a new property
propertyClass.sakshCreate({
  address: '123 Main St',
  price: 500000,
  location: 'Downtown',
  type: 'Apartment',
  bedrooms: 2,
  bathrooms: 2,
  amenities: ['Gym', 'Pool']
}).then(property => {
  console.log('Created property:', property);
}).catch(error => {
  console.error('Error creating property:', error);
});

API Endpoints

Create Property

app.post('/properties', async (req, res) => {
  try {
    const property = await propertyClass.sakshCreate(req.body);
    res.status(201).send(property);
  } catch (error) {
    res.status(400).send(error);
  }
});

Read Properties

app.get('/properties', async (req, res) => {
  try {
    const properties = await propertyClass.sakshGetAll();
    res.send(properties);
  } catch (error) {
    res.status(500).send();
  }
});

Update Property

app.patch('/properties/:id', async (req, res) => {
  try {
    const property = await propertyClass.sakshUpdate(req.params.id, req.body);
    res.send(property);
  } catch (error) {
    res.status(400).send(error.message);
  }
});

Delete Property

app.delete('/properties/:id', async (req, res) => {
  try {
    const property = await propertyClass.sakshDelete(req.params.id);
    res.send(property);
  } catch (error) {
    res.status(500).send(error.message);
  }
});

Predict Property Value

app.get('/properties/:id/predict', async (req, res) => {
  try {
    const predictedValue = await chatGPTClass.sakshGenerateResponse(req.params.id);
    res.send({ predictedValue });
  } catch (error) {
    res.status(500).send(error.message);
  }
});

Get Similar Properties

app.get('/properties/:id/similar', async (req, res) => {
  try {
    const similarProperties = await propertyClass.sakshGetSimilarProperties(req.params.id);
    res.send(similarProperties);
  } catch (error) {
    res.status(500).send(error.message);
  }
});

Recommend Properties Based on Browsing History and User Preferences

app.post('/properties/recommend/history', async (req, res) => {
  try {
    const { browsingHistory, userPreferences } = req.body;
    const { recommendations, recommendedProperties } = await chatGPTClass.sakshRecommendPropertiesFromHistory(browsingHistory, userPreferences);
    res.send({ recommendations, recommendedProperties });
  } catch (error) {
    res.status(500).send(error.message);
  }
});

Example Request

Here’s an example of the data you can pass in the req.body for the /properties/recommend/history endpoint:

{
  "browsingHistory": {
    "viewedProperties": [
      {
        "id": "property1",
        "location": "Downtown",
        "type": "Apartment",
        "price": 500000,
        "bedrooms": 2,
        "bathrooms": 2,
        "amenities": ["Gym", "Pool"]
      },
      {
        "id": "property2",
        "location": "Suburbs",
        "type": "House",
        "price": 750000,
        "bedrooms": 3,
        "bathrooms": 3,
        "amenities": ["Garage", "Garden"]
      }
    ],
    "savedProperties": [
      {
        "id": "property3",
        "location": "Downtown",
        "type": "Apartment",
        "price": 600000,
        "bedrooms": 2,
        "bathrooms": 2,
        "amenities": ["Gym", "Pool"]
      }
    ]
  },
  "userPreferences": {
    "location": "Downtown",
    "type": "Apartment",
    "minPrice": 400000,
    "maxPrice": 700000,
    "bedrooms": 2,
    "bathrooms": 2,
    "amenities": ["Gym", "Pool"]
  }
}

License

MIT

Contact

For any inquiries or support, please contact: [email protected]