Skip to content

Commit

Permalink
Merge pull request #91 from MakanMatch/joshua
Browse files Browse the repository at this point in the history
MakanBot API, conversationHistory and enhanced approximate address calculation
  • Loading branch information
Prakhar896 authored Aug 1, 2024
2 parents 5550ab3 + 22db344 commit 70cde8f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
27 changes: 27 additions & 0 deletions routes/chatbot/MakanBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const express = require("express");
const router = express.Router();
const Logger = require("../../services/Logger")
const OpenAIChat = require("../../services/OpenAIChat");

router.post("/queryMakanBotWithUserPrompt", async (req, res) => {
const { messagePrompt, conversationHistory } = req.body;

if (!OpenAIChat.checkPermission()) {
return res.status(400).send("ERROR: OpenAIChat is not available at this time.");
}

const message = await OpenAIChat.prompt(
messagePrompt,
true,
conversationHistory
)

if (typeof message === "string" && message.startsWith("ERROR:")) {
Logger.log(`CHATBOT MAKANBOT QUERYMAKANBOTWITHUSERPROMPT ERROR: Failed to run prompt through OpenAIChat; response: ${message}`)
return res.status(400).send("ERROR: Failed to run prompt. Try again later.");
} else {
return res.status(200).json({ message: message.content });
}
});

module.exports = { router, at: '/makanBot' };
4 changes: 3 additions & 1 deletion routes/identity/myAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ router.put('/changeAddress', validateToken, async (req, res) => {
const coordinates = { lat: geoLocation.lat, lng: geoLocation.lng };
const updatedListings = await FoodListing.update(
{
coordinates: `${coordinates.lat},${coordinates.lng}`
coordinates: `${coordinates.lat},${coordinates.lng}`,
address: address,
approxAddress: `${street} ${postalCode}`
},
{
where: { hostID: user.userID }
Expand Down
12 changes: 10 additions & 2 deletions routes/listings/listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ router.post("/addListing", validateToken, async (req, res) => {
state = component.long_name;
}
});
let approximateAddress = `${street}, ${city}`;

let approximateAddress = '';
if (street) {
approximateAddress += street;
}
if (city) {
if (approximateAddress) approximateAddress += ', ';
approximateAddress += city;
}
if (state) {
approximateAddress += `, ${state}`;
if (approximateAddress) approximateAddress += `, ${state}`;
}

const listingDetails = {
Expand Down
6 changes: 3 additions & 3 deletions services/OpenAIChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class OpenAIChat {
*/
static initialised = false;
static client;
static model = "gpt-3.5-turbo";
static model = "gpt-4o-mini";
static maxTokens = 512;
static temperature = 0.5;

Expand Down Expand Up @@ -74,10 +74,10 @@ class OpenAIChat {
}

static checkPermission() {
return process.env.OPENAI_API_KEY && process.env.OPENAI_CHAT_ENABLED === 'True';
return process.env.OPENAI_API_KEY !== undefined && process.env.OPENAI_CHAT_ENABLED === 'True';
}

static initialise(configOptions={ model: "gpt-3.5-turbo", maxTokens: 512, temperature: 0.5 }) {
static initialise(configOptions={ model: "gpt-4o-mini", maxTokens: 512, temperature: 0.5 }) {
if (!this.checkPermission()) {
return "ERROR: OpenAIChat operation permission denied.";
}
Expand Down

0 comments on commit 70cde8f

Please sign in to comment.