Skip to content

Commit

Permalink
add script for parse
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyt0313 committed Nov 13, 2023
1 parent 94640b5 commit 89ae64a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 14 deletions.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactgenie-lib",
"version": "1.1.45",
"version": "1.1.46",
"description": "A Toolkit for Multimodal Applications",
"author": "valkjsaaa",
"license": "Apache-2.0",
Expand All @@ -14,7 +14,8 @@
"bin": {
"get-prompt": "./scripts/prompt.js",
"dry-run": "./scripts/dry-run.js",
"set-script": "./scripts/set-script.js"
"set-script": "./scripts/set-script.js",
"parse":"./scripts/parse.js"
},
"devDependencies": {
"@babel/cli": "^7.23.0",
Expand Down
26 changes: 26 additions & 0 deletions scripts/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node

const args = process.argv.slice(2);
console.log("Input Command:\n", args);

// let fs = require("fs");
// fs.writeFileSync("./__test__/dry-run-input.txt", args[0]);

const { spawn } = require("child_process");
let command = "npx";

// Check if the operating system is Windows
if (process.platform === "win32") {
command = "npx.cmd";
}
const childProcess = spawn(command, ["jest", "./__test__/parse.test.ts", args[0]]);
console.log("Running Test ... ");
childProcess.stdout.pipe(process.stdout);



// console.log("Running Test ... ");
// childProcess.on("close", function(code, signal) {
// const result = fs.readFileSync("./__test__/dry-run-result.txt", "utf8");
// console.log("Result:\n", result);
// });
65 changes: 55 additions & 10 deletions scripts/set-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,61 @@ fs.writeFile("./__test__/prompt.txt", "", function (err) {
console.log("Created prompt output!");
});

const jest_config =
"module.exports = {\n" +
' testEnvironment: "jsdom",\n' +
' preset: "jest-expo",\n' +
' "moduleNameMapper": {\n' +
' "\\\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/mocks/fileMock.js",\n' +
' "\\\\.(css|less)$": "<rootDir>/mocks/fileMock.js",\n' +
" \"^uuid$\": require.resolve('uuid'),\n" +
" }\n" +
"}";
const parse_test = `
import {NlParser, DescriptorPromptGen, ClassDescriptor, GenieObject, sharedState} from "reactgenie-dsl";
import {initReactGenie, AllGenieObjects} from "reactgenie-lib";
import * as fs from 'fs';
let API_KEY = ""
test("test", async () => {
const files = fs.readdirSync("./genie");
const tsFiles = files.filter((file) => file.endsWith(".ts"));
tsFiles.forEach((file) => {
require("../genie/" + file);
});
const reactGenieStore = initReactGenie();
let descriptors:ClassDescriptor<GenieObject>[] = []
for (const key in AllGenieObjects) {
descriptors.push(AllGenieObjects[key].ClassDescriptor)
}
const testPath = process.argv;
const nl_interpreter = new DescriptorPromptGen(descriptors,sharedState["__EXAMPLES__"])
let NLP = new NlParser(nl_interpreter, API_KEY,"http://104.40.11.234:5000/v1");
// console.log(testPath);
let res = await NLP.parse(process.argv[3])
console.log(res)
// console.log(testPath[3]);
}, 100000);
`;

fs.writeFile("./__test__/parse.test.ts", prompt_test, function (err) {
if (err) throw err;
console.log("Created parse test!");
});



const jest_config = `
module.exports = {
testEnvironment: "jsdom",
preset: "jest-expo",
"moduleNameMapper": {
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/mocks/fileMock.js",
"\\.(css|less)$": "<rootDir>/mocks/fileMock.js",
"^uuid$": require.resolve('uuid'),
},
testEnvironmentOptions: {
url: 'http://104.40.11.234:5000/v1',
verbose: true,
},
}
`;

fs.writeFile("./jest.config.js", jest_config, function (err) {
if (err) throw err;
Expand Down

0 comments on commit 89ae64a

Please sign in to comment.