Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor AI middleware and service to include firstContext parameter #5

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
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
Next Next commit
Refactor AI middleware and service to include firstContext parameter
  • Loading branch information
thadeucbr committed Sep 30, 2024
commit 79363233d55cf654d72b1615ec34a63083560218
4 changes: 3 additions & 1 deletion src/middleware/ai/gpt.middleware.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import aiService from '../../service/ai/ai.service.js';

const context = 'You are an AI that manage api responses, you will receive body and header and analyse with your tools which function to call and send responses. Your response must always be in JSON in this format: { message, statusCode, status }. Important, don’t send JSON in the response';

const gptMiddleware = async (req, res, _next) => {

Check warning on line 5 in src/middleware/ai/gpt.middleware.js

GitHub Actions / lint

'_next' is defined but never used

Check warning on line 5 in src/middleware/ai/gpt.middleware.js

GitHub Actions / lint

'_next' is defined but never used
console.log(`Request Method: ${req.method}, Request URL: ${req.url}`);
console.log(`Request Body: ${JSON.stringify(req.body)}`);
console.log(`Request Query: ${JSON.stringify(req.query)}`);
console.log(`Request Headers: ${JSON.stringify(req.headers)}`);

const response = await aiService({ body: req.body, header: req.headers, query: req.query, method: req.method, url: req.url });
const response = await aiService({ body: req.body, header: req.headers, query: req.query, method: req.method, url: req.url, firstContext: context });

const { message, statusCode, status } = JSON.parse(response.content);
res.status(statusCode).json({ status, message });
4 changes: 2 additions & 2 deletions src/service/ai/ai.service.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import gpt from '../../helper/gpt/config/gpt.config.js';
import functions from '../../service/index.js';

const aiService = async ({ body, header, query, method, url }) => {
const aiService = async ({ body, header, query, method, url, firstContext }) => {
try {
const context = [
{
role: 'system',
content: 'You are an AI that manage api responses, you will receive body and header and analyse with your tools which function to call and send responses. Your response must always be in JSON in this format: { message, statusCode, status }. Important, don’t send JSON in the response'
content: firstContext
}
];

Loading
Oops, something went wrong.