From 79363233d55cf654d72b1615ec34a63083560218 Mon Sep 17 00:00:00 2001 From: Thadeu Castelo Branco Ramos Date: Mon, 30 Sep 2024 17:42:45 +0000 Subject: [PATCH 1/3] Refactor AI middleware and service to include firstContext parameter --- src/middleware/ai/gpt.middleware.js | 4 +++- src/service/ai/ai.service.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/middleware/ai/gpt.middleware.js b/src/middleware/ai/gpt.middleware.js index 7c82913..8b285f4 100644 --- a/src/middleware/ai/gpt.middleware.js +++ b/src/middleware/ai/gpt.middleware.js @@ -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) => { 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 }); diff --git a/src/service/ai/ai.service.js b/src/service/ai/ai.service.js index a6d6cbd..79edbda 100644 --- a/src/service/ai/ai.service.js +++ b/src/service/ai/ai.service.js @@ -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 } ]; From 8cc1694dcc6c83387c99868a1333a9d0d7a108a3 Mon Sep 17 00:00:00 2001 From: Thadeu Castelo Branco Ramos Date: Mon, 30 Sep 2024 14:47:37 -0300 Subject: [PATCH 2/3] Update reviewer.yml --- .github/workflows/reviewer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reviewer.yml b/.github/workflows/reviewer.yml index f3f7d6b..470d734 100644 --- a/.github/workflows/reviewer.yml +++ b/.github/workflows/reviewer.yml @@ -14,9 +14,9 @@ jobs: uses: actions/checkout@v3 - name: AI Code Reviewer - uses: Ostrich-Cyber-Risk/ai-codereviewer@main + uses: thadeucbr/ai-codereviewer@main with: GITHUB_TOKEN: ${{ secrets.OCTOKIT_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} OPENAI_API_MODEL: "gpt-4o-mini" # Optional: defaults to "gpt-4" - exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas \ No newline at end of file + exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas From 3bf5624af3c8d85e5db5b47c60cfc852a9d74bbc Mon Sep 17 00:00:00 2001 From: Thadeu Castelo Branco Ramos Date: Mon, 30 Sep 2024 14:54:03 -0300 Subject: [PATCH 3/3] Update reviewer.yml --- .github/workflows/reviewer.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/reviewer.yml b/.github/workflows/reviewer.yml index 470d734..77f51e0 100644 --- a/.github/workflows/reviewer.yml +++ b/.github/workflows/reviewer.yml @@ -1,5 +1,4 @@ -name: AI Code Reviewer - +name: Code Review with OpenAI on: pull_request: types: @@ -7,16 +6,15 @@ on: - synchronize permissions: write-all jobs: - review: + code_review: runs-on: ubuntu-latest steps: - - name: Checkout Repo + - name: Checkout repository uses: actions/checkout@v3 - - - name: AI Code Reviewer - uses: thadeucbr/ai-codereviewer@main + - name: Code Review + uses: freeedcom/ai-codereviewer@main with: GITHUB_TOKEN: ${{ secrets.OCTOKIT_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - OPENAI_API_MODEL: "gpt-4o-mini" # Optional: defaults to "gpt-4" - exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas + OPENAI_API_MODEL: "gpt-4o-mini" + exclude: "yarn.lock,dist/**"