diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index c961acb..0000000 --- a/.dockerignore +++ /dev/null @@ -1,12 +0,0 @@ -**/node_modules/ -**/.git -**/README.md -**/LICENSE -**/.vscode -**/npm-debug.log -**/coverage -**/.env -**/.editorconfig -**/dist -**/*.pem -Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index c1cd23e..0000000 --- a/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM node:18-slim -WORKDIR /usr/src/app -COPY package.json package-lock.json ./ -RUN npm ci --production -RUN npm cache clean --force -ENV NODE_ENV="production" -COPY . . -CMD [ "npm", "start" ] diff --git a/app.yml b/app.yml index e8c3b71..ad8ff0e 100644 --- a/app.yml +++ b/app.yml @@ -35,7 +35,7 @@ default_events: # - project_card # - project_column # - public -# - pull_request +- pull_request - pull_request_review - pull_request_review_comment # - push diff --git a/example/case.js b/example/case.js new file mode 100644 index 0000000..ea2afd4 --- /dev/null +++ b/example/case.js @@ -0,0 +1,58 @@ +// callback hell example +app.get("/details", function (req, res) { + var name = req.query.name; + console.log(name); + + Scopus.find({ name: name }, + { '_id': 0, 'authorId': 1 }, + function (err, result) { + if (err) { } + else { + var searchResult = result[0]["authorId"]; + console.log(searchResult); + var options = { + url: "https://api.elsevier.com/content/author/author_id/" + + searchResult + "?apiKey", + headers: { 'Accept': 'application/json' } + }; + request(options, function (error, response, body) { + if (error) { + + // Print the error if one occurred + console.error('error in Authors :', error); + + // Print the response status code if a response was received + console.log('statusCode:', response && response.statusCode); + res.send("error") + } + else if (!error) { + var jsonObj = JSON.parse(body); + if (jsonObj['author-retrieval-response'] == undefined) { + res.send("No details"); + } + else { + var reqData = jsonObj['author-retrieval-response'][0]; + var authprofile = reqData["author-profile"] + var names = authprofile["preferred-name"]["indexed-name"] + console.log(names); + var citation = reqData["coredata"]["citation-count"]; + var query = { authorId: searchResult }; + + Scopus.findOneAndUpdate(query, { + name: names, + citationCount: citation + }, function (err, doc, res) { + if (err) { + console.log("error"); + } + else { + console.log("success"); + } + }) + res.render("details", { data: reqData }); + } + } + }); + } + }) +}); diff --git a/example/react.tsx b/example/react.tsx new file mode 100644 index 0000000..4d5136d --- /dev/null +++ b/example/react.tsx @@ -0,0 +1,42 @@ +import { useState } from 'react' +import { Button } from '@mui/material' +import reactLogo from '@/assets/react.svg' +import '@/App.css' + +function App() { + const [count, setCount] = useState(0) + + return ( +
+
+ + Vite logo + + + React logo + +
+

Vite + React + Redux + RTK + Rect-router + Typescript + MUI 5

+ + + +
+ +

+ Edit src/App.tsx and save to test HMR +

+
+

+ Click on the Vite and React logos to learn more +

+
+ ) +} + +export default App diff --git a/index.js b/index.js index 499ae12..1b6b59b 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const search = require('./src/client.js') +const { search, review, refactor } = require('./src/client.js') const commands = require('probot-commands-pro') module.exports = (app) => { @@ -9,38 +9,52 @@ module.exports = (app) => { return await context.octokit.issues.createComment(issueComment) }) - app.on(['issues.opened', 'issues.edited'], async (context) => { + commands(app, 'chatgpt', async (context) => { if (context.isBot) return - const { issue } = context.payload - // if the robot is mentioned in the issue body, reponse with a greeting - if ( - issue - && issue.body - && issue.body.includes(`/chatgpt`) - ) { - const response = await search(issue.body) - const issueComment = context.issue({ - body: response, - }) - return await context.octokit.issues.createComment(issueComment) - } + const { comment, issue } = context.payload + const { body } = comment || issue + const prompt = body.replace('/chatgpt', '').trim() + const response = await search(prompt) + const issueComment = context.issue({ + body: response, + }) + return await context.octokit.issues.createComment(issueComment) }) - app.on(['issue_comment.created'], async (context) => { + + // wip: review code from code & add test + // https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-an-issue + app.on('issues.opened', async (context) => { }) + // configure something + app.on(['installation'], async (context) => { }) + + // add test && review && refactor + app.on(['pull_request_review_comment'], async (context) => { if (context.isBot) return const { comment } = context.payload - // if the robot is mentioned in the issue body, reponse with a greeting - if ( - comment - && comment.body - && comment.body.includes(`/chatgpt`) - ) { - const response = await search(comment.body) - const issueComment = context.issue({ - body: response, - }) - return await context.octokit.issues.createComment(issueComment) - } + const { body, diff_hunk } = comment || issue + + if (!body.includes(`/review`)) return + const prompt = body.replace('/review', '').trim() + const response = await review({ prompt, lang: 'javascript', code: diff_hunk }) + const issueComment = context.issue({ + body: response, + }) + return await context.octokit.issues.createComment(issueComment) }) + + // app.on(['issue_comment.created', 'issue_comment.edited', 'issues.opened', 'issues.edited'], async (context) => { + // if (context.isBot) + // return + // const { comment, issue } = context.payload + // const { body } = comment || issue + // if (!body.includes(`/chatgpt`)) return + // const prompt = body.replace('/chatgpt', '').trim() + // const response = await search(prompt) + // const issueComment = context.issue({ + // body: response, + // }) + // return await context.octokit.issues.createComment(issueComment) + // }) }; diff --git a/package.json b/package.json index 5bcd806..85ea7d7 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@antfu/eslint-config": "^0.33.1", "@rollup/plugin-commonjs": "^23.0.3", "@rollup/plugin-node-resolve": "^15.0.1", + "@rollup/plugin-terser": "^0.2.0", "eslint": "^8.29.0", "jest": "^29.0.0", "nock": "^13.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 665f0de..db058c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,10 +1,11 @@ -lockfileVersion: 5.3 +lockfileVersion: 5.4 specifiers: '@antfu/eslint-config': ^0.33.1 '@oceanlvr/chatgpt': ^1.0.5 '@rollup/plugin-commonjs': ^23.0.3 '@rollup/plugin-node-resolve': ^15.0.1 + '@rollup/plugin-terser': ^0.2.0 eslint: ^8.29.0 jest: ^29.0.0 nock: ^13.0.5 @@ -23,6 +24,7 @@ devDependencies: '@antfu/eslint-config': 0.33.1_eslint@8.29.0 '@rollup/plugin-commonjs': 23.0.3_rollup@3.5.1 '@rollup/plugin-node-resolve': 15.0.1_rollup@3.5.1 + '@rollup/plugin-terser': 0.2.0_rollup@3.5.1 eslint: 8.29.0 jest: 29.3.1 nock: 13.2.9 @@ -40,7 +42,7 @@ packages: '@jridgewell/trace-mapping': 0.3.17 dev: true - /@antfu/eslint-config-basic/0.33.1_eslint@8.29.0: + /@antfu/eslint-config-basic/0.33.1_ub3senzxbs32f65wl7xoyha6lu: resolution: {integrity: sha512-2aubzjJSGcPJkHgNWOzOWaVdya9km0985wQTWJhT7WZEgZRMSjX+KIzMSz0l6HxvTmCCV71uAhBI1+5C+X2YQg==} peerDependencies: eslint: '>=7.4.0' @@ -49,7 +51,7 @@ packages: eslint-plugin-antfu: 0.33.1_eslint@8.29.0 eslint-plugin-eslint-comments: 3.2.0_eslint@8.29.0 eslint-plugin-html: 7.1.0 - eslint-plugin-import: 2.26.0_eslint@8.29.0 + eslint-plugin-import: 2.26.0_ub3senzxbs32f65wl7xoyha6lu eslint-plugin-jsonc: 2.5.0_eslint@8.29.0 eslint-plugin-markdown: 3.0.0_eslint@8.29.0 eslint-plugin-n: 15.5.1_eslint@8.29.0 @@ -60,6 +62,9 @@ packages: jsonc-eslint-parser: 2.1.0 yaml-eslint-parser: 1.1.0 transitivePeerDependencies: + - '@typescript-eslint/parser' + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack - supports-color - typescript dev: true @@ -70,25 +75,30 @@ packages: eslint: '>=7.4.0' typescript: '>=3.9' dependencies: - '@antfu/eslint-config-basic': 0.33.1_eslint@8.29.0 - '@typescript-eslint/eslint-plugin': 5.45.0_a0772237370cb7a2fbb65feeec1c1e5d + '@antfu/eslint-config-basic': 0.33.1_ub3senzxbs32f65wl7xoyha6lu + '@typescript-eslint/eslint-plugin': 5.45.0_ub3senzxbs32f65wl7xoyha6lu '@typescript-eslint/parser': 5.45.0_eslint@8.29.0 eslint: 8.29.0 transitivePeerDependencies: + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack - supports-color dev: true - /@antfu/eslint-config-vue/0.33.1_eslint@8.29.0: + /@antfu/eslint-config-vue/0.33.1_ub3senzxbs32f65wl7xoyha6lu: resolution: {integrity: sha512-zIO8Y7/lAnxcbz9Vo68IYX9ujRAHwpWx3uurirAkH+/UNREen+SP/obPab/C9ts3kgEsIQXNxBzwXYf4VpAUUQ==} peerDependencies: eslint: '>=7.4.0' dependencies: - '@antfu/eslint-config-basic': 0.33.1_eslint@8.29.0 + '@antfu/eslint-config-basic': 0.33.1_ub3senzxbs32f65wl7xoyha6lu '@antfu/eslint-config-ts': 0.33.1_eslint@8.29.0 eslint: 8.29.0 eslint-plugin-vue: 9.8.0_eslint@8.29.0 local-pkg: 0.4.2 transitivePeerDependencies: + - '@typescript-eslint/parser' + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack - supports-color - typescript dev: true @@ -98,13 +108,13 @@ packages: peerDependencies: eslint: '>=7.4.0' dependencies: - '@antfu/eslint-config-vue': 0.33.1_eslint@8.29.0 - '@typescript-eslint/eslint-plugin': 5.45.0_a0772237370cb7a2fbb65feeec1c1e5d + '@antfu/eslint-config-vue': 0.33.1_ub3senzxbs32f65wl7xoyha6lu + '@typescript-eslint/eslint-plugin': 5.45.0_ub3senzxbs32f65wl7xoyha6lu '@typescript-eslint/parser': 5.45.0_eslint@8.29.0 eslint: 8.29.0 eslint-plugin-eslint-comments: 3.2.0_eslint@8.29.0 eslint-plugin-html: 7.1.0 - eslint-plugin-import: 2.26.0_eslint@8.29.0 + eslint-plugin-import: 2.26.0_ub3senzxbs32f65wl7xoyha6lu eslint-plugin-jsonc: 2.5.0_eslint@8.29.0 eslint-plugin-n: 15.5.1_eslint@8.29.0 eslint-plugin-promise: 6.1.1_eslint@8.29.0 @@ -114,6 +124,8 @@ packages: jsonc-eslint-parser: 2.1.0 yaml-eslint-parser: 1.1.0 transitivePeerDependencies: + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack - supports-color - typescript dev: true @@ -756,6 +768,13 @@ packages: engines: {node: '>=6.0.0'} dev: true + /@jridgewell/source-map/0.3.2: + resolution: {integrity: sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==} + dependencies: + '@jridgewell/gen-mapping': 0.3.2 + '@jridgewell/trace-mapping': 0.3.17 + dev: true + /@jridgewell/sourcemap-codec/1.4.14: resolution: {integrity: sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==} dev: true @@ -1141,6 +1160,21 @@ packages: rollup: 3.5.1 dev: true + /@rollup/plugin-terser/0.2.0_rollup@3.5.1: + resolution: {integrity: sha512-UBr4WNXBFipKW2C2db9JIzIdq9bFZsaTZwKeAd9Y0N9Pv9G2XgRhaimGdotx1+Wf/2XTuTJ+FVS2SO+y2WyiUQ==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.x || ^3.x + peerDependenciesMeta: + rollup: + optional: true + dependencies: + rollup: 3.5.1 + serialize-javascript: 6.0.0 + smob: 0.0.6 + terser: 5.16.1 + dev: true + /@rollup/pluginutils/5.0.2_rollup@3.5.1: resolution: {integrity: sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==} engines: {node: '>=14.0.0'} @@ -1450,7 +1484,7 @@ packages: '@types/yargs-parser': 21.0.0 dev: true - /@typescript-eslint/eslint-plugin/5.45.0_a0772237370cb7a2fbb65feeec1c1e5d: + /@typescript-eslint/eslint-plugin/5.45.0_ub3senzxbs32f65wl7xoyha6lu: resolution: {integrity: sha512-CXXHNlf0oL+Yg021cxgOdMHNTXD17rHkq7iW6RFHoybdFgQBjU3yIXhhcPpGwr1CjZlo6ET8C6tzX5juQoXeGA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -1848,6 +1882,8 @@ packages: raw-body: 2.5.1 type-is: 1.6.18 unpipe: 1.0.0 + transitivePeerDependencies: + - supports-color dev: false /boolbase/1.0.0: @@ -2174,15 +2210,37 @@ packages: /debug/2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.0.0 /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: ms: 2.1.3 dev: true + /debug/3.2.7_supports-color@5.5.0: + resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true + dependencies: + ms: 2.1.3 + supports-color: 5.5.0 + dev: true + /debug/4.3.4: resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} engines: {node: '>=6.0'} @@ -2439,19 +2497,37 @@ packages: dependencies: debug: 3.2.7 resolve: 1.22.1 + transitivePeerDependencies: + - supports-color dev: true - /eslint-module-utils/2.7.4_eslint@8.29.0: + /eslint-module-utils/2.7.4_ka2zl4kbfnnb6pzn3mgzpmhlt4: resolution: {integrity: sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==} engines: {node: '>=4'} peerDependencies: + '@typescript-eslint/parser': '*' eslint: '*' + eslint-import-resolver-node: '*' + eslint-import-resolver-typescript: '*' + eslint-import-resolver-webpack: '*' peerDependenciesMeta: + '@typescript-eslint/parser': + optional: true eslint: optional: true + eslint-import-resolver-node: + optional: true + eslint-import-resolver-typescript: + optional: true + eslint-import-resolver-webpack: + optional: true dependencies: + '@typescript-eslint/parser': 5.45.0_eslint@8.29.0 debug: 3.2.7 eslint: 8.29.0 + eslint-import-resolver-node: 0.3.6 + transitivePeerDependencies: + - supports-color dev: true /eslint-plugin-antfu/0.33.1_eslint@8.29.0: @@ -2492,19 +2568,24 @@ packages: htmlparser2: 8.0.1 dev: true - /eslint-plugin-import/2.26.0_eslint@8.29.0: + /eslint-plugin-import/2.26.0_ub3senzxbs32f65wl7xoyha6lu: resolution: {integrity: sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==} engines: {node: '>=4'} peerDependencies: + '@typescript-eslint/parser': '*' eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 + peerDependenciesMeta: + '@typescript-eslint/parser': + optional: true dependencies: + '@typescript-eslint/parser': 5.45.0_eslint@8.29.0 array-includes: 3.1.6 array.prototype.flat: 1.3.1 debug: 2.6.9 doctrine: 2.1.0 eslint: 8.29.0 eslint-import-resolver-node: 0.3.6 - eslint-module-utils: 2.7.4_eslint@8.29.0 + eslint-module-utils: 2.7.4_ka2zl4kbfnnb6pzn3mgzpmhlt4 has: 1.0.3 is-core-module: 2.11.0 is-glob: 4.0.3 @@ -2512,6 +2593,10 @@ packages: object.values: 1.1.6 resolve: 1.22.1 tsconfig-paths: 3.14.1 + transitivePeerDependencies: + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack + - supports-color dev: true /eslint-plugin-jsonc/2.5.0_eslint@8.29.0: @@ -2882,6 +2967,8 @@ packages: type-is: 1.6.18 utils-merge: 1.0.1 vary: 1.1.2 + transitivePeerDependencies: + - supports-color dev: false /extend/3.0.2: @@ -2974,6 +3061,8 @@ packages: parseurl: 1.3.3 statuses: 2.0.1 unpipe: 1.0.0 + transitivePeerDependencies: + - supports-color dev: false /find-up/3.0.0: @@ -4651,6 +4740,8 @@ packages: depd: 2.0.0 on-finished: 2.3.0 on-headers: 1.0.2 + transitivePeerDependencies: + - supports-color dev: true /mri/1.1.4: @@ -4736,7 +4827,7 @@ packages: hasBin: true dependencies: chokidar: 3.5.3 - debug: 3.2.7 + debug: 3.2.7_supports-color@5.5.0 ignore-by-default: 1.0.1 minimatch: 3.1.2 pstree.remy: 1.1.8 @@ -5240,6 +5331,12 @@ packages: resolution: {integrity: sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==} dev: false + /randombytes/2.1.0: + resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} + dependencies: + safe-buffer: 5.2.1 + dev: true + /range-parser/1.2.1: resolution: {integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==} engines: {node: '>= 0.6'} @@ -5513,8 +5610,16 @@ packages: on-finished: 2.4.1 range-parser: 1.2.1 statuses: 2.0.1 + transitivePeerDependencies: + - supports-color dev: false + /serialize-javascript/6.0.0: + resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} + dependencies: + randombytes: 2.1.0 + dev: true + /serve-static/1.15.0: resolution: {integrity: sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==} engines: {node: '>= 0.8.0'} @@ -5523,6 +5628,8 @@ packages: escape-html: 1.0.3 parseurl: 1.3.3 send: 0.18.0 + transitivePeerDependencies: + - supports-color dev: false /setprototypeof/1.2.0: @@ -5581,6 +5688,10 @@ packages: - supports-color dev: true + /smob/0.0.6: + resolution: {integrity: sha512-V21+XeNni+tTyiST1MHsa84AQhT1aFZipzPpOFAVB8DkHzwJyjjAmt9bgwnuZiZWnIbMo2duE29wybxv/7HWUw==} + dev: true + /sonic-boom/1.4.1: resolution: {integrity: sha512-LRHh/A8tpW7ru89lrlkU4AszXt1dbwSjVWguGrmlxE7tawVmDBlI1PILMkXAxJTwqhgsEeTHzj36D5CmHgQmNg==} dependencies: @@ -5607,6 +5718,13 @@ packages: source-map: 0.6.1 dev: true + /source-map-support/0.5.21: + resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==} + dependencies: + buffer-from: 1.1.2 + source-map: 0.6.1 + dev: true + /source-map/0.6.1: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} @@ -5789,6 +5907,17 @@ packages: resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} engines: {node: '>= 0.4'} + /terser/5.16.1: + resolution: {integrity: sha512-xvQfyfA1ayT0qdK47zskQgRZeWLoOQ8JQ6mIgRGVNwZKdQMU+5FkCBjmv4QjcrTzyZquRw2FVtlJSRUmMKQslw==} + engines: {node: '>=10'} + hasBin: true + dependencies: + '@jridgewell/source-map': 0.3.2 + acorn: 8.8.1 + commander: 2.20.3 + source-map-support: 0.5.21 + dev: true + /test-exclude/6.0.0: resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} engines: {node: '>=8'} diff --git a/rollup.config.js b/rollup.config.js index c7f9135..4c31d71 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,5 +1,6 @@ import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; +import terser from '@rollup/plugin-terser'; export default { input: 'index.js', @@ -10,5 +11,6 @@ export default { plugins: [ resolve({ preferBuiltins: true, }), commonjs(), + terser() ], } diff --git a/src/client.js b/src/client.js index c71f74c..982fd66 100644 --- a/src/client.js +++ b/src/client.js @@ -1,8 +1,32 @@ const { ChatGPTAPI } = require('@oceanlvr/chatgpt') const client = new ChatGPTAPI({ sessionToken: process.env.SESSION_TOKEN }) -module.exports = async function search(searchPrompt) { + +async function search(searchPrompt) { // await client.ensureAuth() const reponse = await client.sendMessage(searchPrompt) return reponse } + +async function refactor({ code, lang, prompt }) { + const searchPrompt = `Refactor folloing ${lang} code. Do not include example usage. ${prompt}. + ${code} +` + const reponse = await client.sendMessage(searchPrompt) + return reponse +} + +async function review({ code, lang, prompt }) { + const searchPrompt = `Review folloing ${lang} code. ${prompt}. + ${code} +` + const reponse = await client.sendMessage(searchPrompt) + return reponse +} + +module.exports = { + search, + review, + refactor, +} +