Skip to content

Commit

Permalink
Merge pull request Code-For-Humans-School#21 from rogercortez-dev/bac…
Browse files Browse the repository at this point in the history
…kend-implementations

Backend implementations
  • Loading branch information
rogershi-dev authored Jun 27, 2024
2 parents bf77ccf + de7c895 commit 6e7bab9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
12 changes: 2 additions & 10 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ router.get('/', function(req, res, next) {
// Function to expand commit message and generate a full post using ChatGPT API
async function expandCommitMessage(commitMessage) {
try {
// const response = await axios.post('https://api.openai.com/v1/engines/davinci/completions', {
// prompt: commitMessage,
// max_tokens: 150,
// api_key: CHATGPT_API_KEY
// });
const completion = await openai.chat.completions.create({
messages: [{ role: "system", content: `You are a professional LinkedIn user, help me expand the following text into a full post that can be posted on LinkedIn, ${commitMessage}` }],
messages: [{ role: "system", content: `You are a professional LinkedIn user, help me expand the following text into a full post that can be posted on LinkedIn. Remember that you are an experienced software engineer and you are collaborating with teammates all cross the globe. Each teammate can push a commit to the code base, so when you try to expand the commit message, you should use we, instead of I, since this is the official LinkedIn account of the whole team. Below is the commit message to be expanded: ${commitMessage}` }],
model: "gpt-4o",
});

Expand All @@ -41,10 +36,8 @@ router.post('/webhook', async (req, res) => {

try {
// Expand the commit message into a full post
const expandedMessage = await expandCommitMessage(`Expand the following text into a LinkedIn post, ${commitMessage}`);
const expandedMessage = await expandCommitMessage(commitMessage);
console.log('Expanded Message:', expandedMessage);
res.render('index', { gptprompt: commitMessage })
res.render('index', { gptmessage: expandedMessage });

// Post to LinkedIn

Expand All @@ -53,7 +46,6 @@ router.post('/webhook', async (req, res) => {
} catch (error) {
// Log the error to the server
console.error('Error processing webhook:', error);
res.render('error', { gpterror: error });

// Send an error response to GitHub
res.status(500).send('Internal Server Error');
Expand Down
1 change: 0 additions & 1 deletion server/views/error.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ block content
h1= message
h2= error.status
pre #{error.stack}
p= gpterror
2 changes: 0 additions & 2 deletions server/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ block content
p Updated local repo on remote server to keep synced with the existing repository
p Rebooted remote server and push again to test.
h1 ChatGPT Integration Progress Check
p= gptprompt
p= gptmessage
p Test GitHub Webhook
p Added chatgpt api key
p Implemented a function to expand the commit message using OpenAI API
Expand Down

0 comments on commit 6e7bab9

Please sign in to comment.