Skip to content

Commit

Permalink
Sdfs
Browse files Browse the repository at this point in the history
sdsf
  • Loading branch information
Misterr-H committed Nov 5, 2022
1 parent c06cc21 commit ffaefe3
Show file tree
Hide file tree
Showing 5 changed files with 548 additions and 1 deletion.
Binary file added backend-code/.DS_Store
Binary file not shown.
68 changes: 68 additions & 0 deletions backend-code/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// initialise express for cors and json
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
app.use(express.json());
const PORT = process.env.PORT || 5000;

const prompt_text = "Angela is a virtual assistant of Himanshu who talks to himanshu's friends. Angela is smart, intelligent, polite, caring and can answer all questions using openai intelligence. Angela is created using gpt 3 ai model. \n\nFriend: Hi\nAngela: Hi, Angela is here. Himanshu's virtual assistant. How can I help?\nFriend: Where's Himanshu?\nAngela: Himanshu sir seems busy with coding stuff.\nFriend:"


const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: "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",
});
const openai = new OpenAIApi(configuration);

// const response = await openai.createCompletion({
// model: "text-davinci-002",
// temperature: 0.7,
// max_tokens: 256,
// top_p: 1,
// frequency_penalty: 0,
// presence_penalty: 0,
// });

//setup express listener for autoresponder for wa
app.post('/angela', async (req, res) => {
const message = req.body.query.message;
console.log(message);
const prompt = prompt_text + message + "\nAngela:";
console.log(prompt);
const response = await openai.createCompletion({
model: "text-davinci-002",
temperature: 0.9,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0.6,
prompt: prompt,
stop: [" Friend:", " Angela:"],
suffix: ""
});
console.log(response.data);
if(response.data.choices[0].text.trim()==="")
res.status(200).json({
"replies":[
{
"message": "Angela:" + "Didn't get you!"
}
]
});
else
res.status(200).json({
"replies":[
{
"message": "Angela:" + response.data.choices[0].text.trim()
}
]
});
});

// start express server
app.listen(PORT, () => {
console.log('Server started on port 4000');
}
);
16 changes: 16 additions & 0 deletions backend-code/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "angelaopenai",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.2",
"openai": "^3.0.0"
}
}
Loading

0 comments on commit ffaefe3

Please sign in to comment.