Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion api/clients/openAiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions api/clients/serpApiClient.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
26 changes: 7 additions & 19 deletions api/controller/eventController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
}
Expand All @@ -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 })
}
})

}
}

Expand Down