aimyapi 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -4
- package/lib/index.ts +5 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateCode = exports.createBasePrompt = void 0;
|
|
7
7
|
require('dotenv').config();
|
|
8
|
-
const openai_1 = require("openai");
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const openai_1 = require("openai");
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const sandbox_1 = __importDefault(require("./sandbox"));
|
|
12
12
|
const sandbox_wrappers_1 = require("./sandbox-wrappers");
|
|
@@ -91,14 +91,14 @@ async function createWithAPI(options) {
|
|
|
91
91
|
options = {
|
|
92
92
|
apiGlobalName: "api",
|
|
93
93
|
apiGlobals: {},
|
|
94
|
+
apiWhitelist: Object.getOwnPropertyNames(Object.getPrototypeOf(options.apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_")),
|
|
94
95
|
debug: false,
|
|
95
96
|
...options
|
|
96
97
|
};
|
|
97
98
|
if (!options.apiObject || !options.apiDefFilePath) {
|
|
98
99
|
throw new Error("apiObject and apiFilePath are required");
|
|
99
100
|
}
|
|
100
|
-
const { apiObject, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug } = options;
|
|
101
|
-
const whitelist = Object.getOwnPropertyNames(Object.getPrototypeOf(apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_"));
|
|
101
|
+
const { apiObject, apiWhitelist, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug } = options;
|
|
102
102
|
const createTaskPrompt = createBasePrompt(apiDefFilePath, apiDocsPath);
|
|
103
103
|
return {
|
|
104
104
|
generateCode: async function (queryText, userChatHistory, currentContext = undefined) {
|
|
@@ -127,7 +127,7 @@ async function createWithAPI(options) {
|
|
|
127
127
|
...apiGlobals,
|
|
128
128
|
[apiGlobalName]: {
|
|
129
129
|
value: apiObject,
|
|
130
|
-
|
|
130
|
+
apiWhitelist
|
|
131
131
|
}
|
|
132
132
|
}, options.debug);
|
|
133
133
|
try {
|
package/lib/index.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
require('dotenv').config()
|
|
2
|
-
import { ChatCompletionRequestMessage, Configuration, OpenAIApi } from "openai";
|
|
3
2
|
import fs from 'fs';
|
|
3
|
+
import { ChatCompletionRequestMessage, Configuration, OpenAIApi } from "openai";
|
|
4
4
|
import path from 'path';
|
|
5
5
|
|
|
6
6
|
import createSandbox from "./sandbox";
|
|
7
7
|
import { rejectOpenPromises } from './sandbox-wrappers';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
9
|
import { QuickJSWASMModule, getQuickJS } from "quickjs-emscripten";
|
|
12
10
|
|
|
13
11
|
const configuration = new Configuration({
|
|
@@ -102,6 +100,7 @@ let QuickJS:QuickJSWASMModule = null;
|
|
|
102
100
|
export interface AIMyAPIOptions {
|
|
103
101
|
apiObject: object;
|
|
104
102
|
apiExports: object;
|
|
103
|
+
apiWhitelist?: string[]; // List of functions to expose to the user. Necessary to pass this yourself if you are extending your api from another class.
|
|
105
104
|
apiGlobals?: object;
|
|
106
105
|
apiDefFilePath: string; // Full path to the api definition file so that it can be loaded into the prompt
|
|
107
106
|
apiGlobalName?: string;
|
|
@@ -123,6 +122,7 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<CreateWithAPIExpor
|
|
|
123
122
|
options = {
|
|
124
123
|
apiGlobalName: "api",
|
|
125
124
|
apiGlobals: {},
|
|
125
|
+
apiWhitelist: Object.getOwnPropertyNames(Object.getPrototypeOf(options.apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_")),
|
|
126
126
|
debug: false,
|
|
127
127
|
...options
|
|
128
128
|
};
|
|
@@ -131,9 +131,8 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<CreateWithAPIExpor
|
|
|
131
131
|
throw new Error("apiObject and apiFilePath are required");
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
const {apiObject, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug} = options;
|
|
134
|
+
const {apiObject, apiWhitelist, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug} = options;
|
|
135
135
|
|
|
136
|
-
const whitelist = Object.getOwnPropertyNames(Object.getPrototypeOf(apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_"));
|
|
137
136
|
const createTaskPrompt = createBasePrompt( apiDefFilePath, apiDocsPath);
|
|
138
137
|
|
|
139
138
|
return {
|
|
@@ -167,7 +166,7 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<CreateWithAPIExpor
|
|
|
167
166
|
...apiGlobals,
|
|
168
167
|
[apiGlobalName]: {
|
|
169
168
|
value: apiObject,
|
|
170
|
-
|
|
169
|
+
apiWhitelist
|
|
171
170
|
}
|
|
172
171
|
}, options.debug);
|
|
173
172
|
|