Skip to content

Commit

Permalink
feat: add skeleton chat GPT service integration
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemccoll committed Mar 10, 2023
1 parent e78cdc3 commit 75f08a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/routes/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default async function review(fastify) {
},
},
},
async (request) => {
async (request, reply) => {
const dynamicPrompt = promptEngine.build(JSON.parse(request.body));
const response = await suggestions.create({
transformerType: "chatGPT",
payload: dynamicPrompt,
});
return response;
return reply.status(200).send(response);
}
);
}
26 changes: 24 additions & 2 deletions backend/services/suggestions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import * as dotenv from "dotenv";

dotenv.config();

const suggestions = {
buildMessages(payload) {},
async create({ transformerType, payload }) {
switch (transformerType) {
case "chatGPT": {
// handle ChatGPT
console.log("handle chat gpt");
try {
const apiUrl = "https://api.openai.com/v1/completions";
const messages = this.buildMessages(payload);
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.CHAT_GPT_API_KEY}`,
},
body: JSON.stringify({
model: "text-davinci-003",
prompt: "Say this is a test",
}),
});
const body = await response.json();
console.log(body);
} catch (error) {
throw new Error(`received error from chatGPT API + ${error.message}`);
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion github-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = async (app) => {
if (response.status !== 200) {
app.log.error("[reviewbot] - error scheduling review request");
throw new Error(
`received status code ${response.status} instead of 201`
`received status code ${response.status} instead of 200`
);
}
} catch (error) {
Expand Down

0 comments on commit 75f08a5

Please sign in to comment.