diff --git a/.github/workflows/reviewer.yml b/.github/workflows/reviewer.yml index f3f7d6b..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: Ostrich-Cyber-Risk/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 \ No newline at end of file + OPENAI_API_MODEL: "gpt-4o-mini" + exclude: "yarn.lock,dist/**" 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 } ];