GPT-4's Answer
It is possible to refactor only the internals of functions within a large class using GPT-4. Here's an approach to achieve that:
npx ts-node refactorAndCombine.ts /path/to/your/typescript/file.ts
refactor_function.py
GPT-4's Answer
It is possible to refactor only the internals of functions within a large class using GPT-4. Here's an approach to achieve that:
npx ts-node refactorAndCombine.ts /path/to/your/typescript/file.ts
refactor_function.py
import openai | |
import sys | |
import re | |
# Refactor specified file using OpenAI GPT-3 API | |
# Example usage | |
# | |
# target=/your/project/path | |
# for i in `ls -d $target/src/*.ts $target/test/*.ts`; |
# データの定義 | |
servers = [{"name": "serverA", "port": 80}, {"name": "serverB", "port": 3000}] | |
# ルールの定義: inputのリストの要素にportが1024以下のものがある | |
# 評価されるとルールのbodyの評結結果がtrueになり、ルールの評価結果はtrueになる。 | |
rule1 { servers[_].port <= 1024 } | |
# ルールの定義: inputのリストの要素にportが10000以上のものがある | |
# 評価されるとルールのbodyの評結結果がfalseになり、ルールの評価結果はundefinedになる。 | |
rule2 { servers[_].port >= 10000 } |
-- CAUTION: If you use this UDF to many images, you may lose many-many money. | |
CREATE TEMPORARY FUNCTION predictMnist(test ARRAY<FLOAT64>) | |
RETURNS FLOAT64 | |
LANGUAGE js AS """ | |
var nj = globalNumjs; | |
const ntest = nj.array(test); | |
const nw1 = nj.array(w1); | |
const nw2 = nj.array(w2); | |
const nw3 = nj.array(w3); |
var Q = require('q'); | |
var util = require('util'); | |
var fn = Q.makePromise.prototype; | |
fn.catchForceReturn = catchForceReturn; | |
function ForceReturn(value) { | |
Error.call(this, value); | |
this.name = "ForceReturn"; |
limitedParallelAsync = (array, limit, proc) -> | |
rest = array.concat() | |
doNext = (res) -> | |
Promise.resolve() | |
.then(-> | |
if rest.length == 0 | |
return | |
i = rest.shift() |
% coffee test.coffee | |
MEM: rss 0.02 Gb, vsize 2.91 Gb, heapTotal 0.01 Gb, heapUsed 0.01 Gb | |
File no. 1 | |
process: 2474ms | |
MEM: rss 0.24 Gb, vsize 3.11 Gb, heapTotal 0.23 Gb, heapUsed 0.22 Gb | |
File no. 2 | |
process: 4509ms | |
MEM: rss 0.64 Gb, vsize 3.5 Gb, heapTotal 0.63 Gb, heapUsed 0.6 Gb | |
File no. 3 | |
process: 3076ms |
_ = require("lodash") | |
esprima = require('esprima') | |
escodegen = require('escodegen') | |
handleFunctionBody = (body, newStatements) -> | |
body.body = newStatements.concat(body.body) | |
insertStatementsIntoFunction = (s, newStatements) -> | |
if s.type == 'FunctionDeclaration' && s.body && s.body.type == 'BlockStatement' | |
handleFunctionBody(s.body, newStatements) |