Skip to content
Open
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
13 changes: 11 additions & 2 deletions app/routes/research.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ const needle = require("needle");
const {
environmentalScripts
} = require("../../config/config");
const { Configuration, OpenAIApi } = require("openai")
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
})
const openai = new OpenAIApi(configuration)

function ResearchHandler(db) {
"use strict";

const researchDAO = new ResearchDAO(db);

this.displayResearch = (req, res) => {

this.displayResearch = async (req, res) => {
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: `find stocks ${req.user.email} might enjoy like ${req.query.symbol}`,
})
if (req.query.symbol) {
const url = req.query.url + req.query.symbol;
return needle.get(url, (error, newResponse, body) => {
Expand All @@ -24,6 +32,7 @@ function ResearchHandler(db) {
if (body) {
res.write(body);
}
res.write("You might also want to check out "+completion.data.choices[0].text)
return res.end();
});
}
Expand Down