From 575cf2d02f9250b87a1e084227bb57e0852e4c64 Mon Sep 17 00:00:00 2001 From: Evan Thomas Date: Wed, 6 Sep 2023 16:29:01 +0100 Subject: [PATCH] Remove SerpAPI Client from event controller. Update README to reflect this. --- README.md | 3 +-- api/clients/openAiClient.js | 2 +- api/clients/serpApiClient.js | 3 +++ api/controller/eventController.js | 26 +++++++------------------- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index c9c3b6d..09e5b2b 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,11 @@ Put your IP address in a .env file in the main directory IP=YOUR_IP_HERE ``` -You'll need API keys for [OpenAI](https://platform.openai.com/) and [SerpAPI](https://serpapi.com/), which are used for generating the location-based activities. Put the api keys in a .env file in the api directory. +You'll need an API key for [OpenAI](https://platform.openai.com/), which is used for generating the location-based activities. Put the api key in a .env file in the api directory. ```bash # Flock/api/.env -SERPAPI_KEY=YOUR_API_KEY_HERE OPENAI_API_KEY=YOUR_API_KEY_HERE ``` diff --git a/api/clients/openAiClient.js b/api/clients/openAiClient.js index ec33cc8..a06bf51 100644 --- a/api/clients/openAiClient.js +++ b/api/clients/openAiClient.js @@ -7,7 +7,7 @@ class OpenAiClient { apiKey: process.env.OPENAI_API_KEY, }); this.openai = new OpenAIApi(configuration); - this.prompt = `What are 3 activities I can do with friends in ${location}? Only give me the list. Make each suggestion less than 10 words. Make output new line seperated without numbers.`; + this.prompt = `What are 5 activities I can do with friends in ${location}? Only give me the list. Make each suggestion less than 10 words. Make output new line seperated without numbers.`; } activitySearch(callback) { diff --git a/api/clients/serpApiClient.js b/api/clients/serpApiClient.js index 25899da..7b52f1c 100644 --- a/api/clients/serpApiClient.js +++ b/api/clients/serpApiClient.js @@ -1,3 +1,6 @@ +// The app does not currently use this API due to restrictive rate limits. +// It was previously used when we presented the app at Makers Demo Day. + const SerpApi = require("google-search-results-nodejs"); require("dotenv").config(); diff --git a/api/controller/eventController.js b/api/controller/eventController.js index a6eebd5..a32e643 100644 --- a/api/controller/eventController.js +++ b/api/controller/eventController.js @@ -2,12 +2,10 @@ const Event = require('../models/eventModel') const User = require('../models/userModel') const mongoose = require('mongoose') const OpenAiClient = require('../clients/openAiClient') -const SerpApiClient = require('../clients/serpApiClient') const EventController = { Index: async (req, res) => { const { id } = req.params - // console.log(id) if (!mongoose.Types.ObjectId.isValid(id)){ return res.status(404).json({error: 'Id param is invalid'}) } @@ -31,26 +29,16 @@ const EventController = { return await User.create({ name }); })); - const client = new SerpApiClient(location) const clientAi = new OpenAiClient(location) - - await client.activitySearch(async (data) => { - const serpActivities = data.map(activity => { - return `Go to ${activity.title} at ${activity.venue.name}` - }) - await clientAi.activitySearch(async (data) => { - const activities = [...serpActivities.slice(0, 2), ...data] - const shuffledActivies = activities.sort(() => Math.random() - 0.5) - try { - const newEvent = await Event.create({ eventName: eventName, names: users, activities: shuffledActivies }) - res.status(200).json(newEvent._id) - } catch (error) { - res.status(400).json({ error: error.message }) - } - }) + clientAi.activitySearch(async (data) => { + try { + const newEvent = await Event.create({ eventName: eventName, names: users, activities: data }) + res.status(200).json(newEvent._id) + } catch (error) { + res.status(400).json({ error: error.message }) + } }) - } }