aimyapi 0.1.11 → 0.1.13
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/README.md +16 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -4
- package/lib/index.ts +7 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# AI My API
|
|
2
2
|
|
|
3
|
-
Build AI assistants that use your API's and respond to natural language queries by writing small programs that are executed in a [QuickJS](https://github.com/justjake/quickjs-emscripten) sandbox.
|
|
4
|
-
|
|
5
|
-
for example, being able to sort or filter your data in new ways, email or text yourself results, or combine the results of different operations and API's.
|
|
3
|
+
Build AI assistants that use your API's and respond to natural language queries by writing small programs that are executed in a [QuickJS](https://github.com/justjake/quickjs-emscripten) sandbox. Similar to chatGPT Code Interpreter but running on your servers and calling your own API.
|
|
4
|
+
|
|
5
|
+
AIMyAPI writes the glue between your various API functions unlocking new functionality without having to write any code. With the right building blocks, AIMyAPI can even invent new functionality you didn't originally plan for - for example, being able to sort or filter your data in new ways, email or text yourself results, or combine the results of different operations and API's.
|
|
6
6
|
|
|
7
7
|
Uses the OpenAI API and requires an API key.
|
|
8
8
|
|
|
@@ -45,7 +45,7 @@ declare global {
|
|
|
45
45
|
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
Implement it:
|
|
48
|
+
Implement it (`sales_api_impl.ts`):
|
|
49
49
|
```
|
|
50
50
|
export class API implements APIInterface {
|
|
51
51
|
|
|
@@ -53,6 +53,18 @@ export class API implements APIInterface {
|
|
|
53
53
|
...
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
Document it (`sales_api.md`):
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
Examples of how you should respond:
|
|
60
|
+
|
|
61
|
+
user: How are you today?
|
|
62
|
+
|
|
63
|
+
assistant:
|
|
64
|
+
|
|
65
|
+
api.print("I'm great, thanks for asking!");
|
|
66
|
+
```
|
|
67
|
+
|
|
56
68
|
Instantiate your api and AIMyAPI. AIMyAPI will wrap your API so that it can be called from within the QuickJS sandbox.
|
|
57
69
|
|
|
58
70
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface GenerateCodeResult {
|
|
|
6
6
|
loggableCode: string;
|
|
7
7
|
rawResponse?: string;
|
|
8
8
|
}
|
|
9
|
-
export declare const generateCode: (queryText: string, userChatHistory: ChatCompletionRequestMessage[], createTaskPrompt: string, apiPath: string, debug?: boolean) => Promise<GenerateCodeResult>;
|
|
9
|
+
export declare const generateCode: (queryText: string, userChatHistory: ChatCompletionRequestMessage[], createTaskPrompt: string, apiPath: string, debug?: boolean, model?: string) => Promise<GenerateCodeResult>;
|
|
10
10
|
export interface AIMyAPIOptions {
|
|
11
11
|
apiObject: object;
|
|
12
12
|
apiExports: object;
|
|
@@ -16,6 +16,7 @@ export interface AIMyAPIOptions {
|
|
|
16
16
|
apiGlobalName?: string;
|
|
17
17
|
apiDocsPath?: string;
|
|
18
18
|
debug?: boolean;
|
|
19
|
+
model?: string;
|
|
19
20
|
}
|
|
20
21
|
export interface AIMyAPIInstance {
|
|
21
22
|
options: AIMyAPIOptions;
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ function createBasePrompt(apiFilePath, documentationPath) {
|
|
|
30
30
|
}
|
|
31
31
|
exports.createBasePrompt = createBasePrompt;
|
|
32
32
|
// FIXME: add an options parameter and allow specifying the token limit
|
|
33
|
-
const generateCode = async function (queryText, userChatHistory, createTaskPrompt, apiPath, debug = false) {
|
|
33
|
+
const generateCode = async function (queryText, userChatHistory, createTaskPrompt, apiPath, debug = false, model = "gpt-4o") {
|
|
34
34
|
if (!queryText)
|
|
35
35
|
return { code: '', loggableCode: '' };
|
|
36
36
|
let generatedCode = '';
|
|
@@ -49,7 +49,7 @@ const generateCode = async function (queryText, userChatHistory, createTaskPromp
|
|
|
49
49
|
];
|
|
50
50
|
try {
|
|
51
51
|
const results = await openai.createChatCompletion({
|
|
52
|
-
model
|
|
52
|
+
model,
|
|
53
53
|
messages: messages,
|
|
54
54
|
temperature: 0.1,
|
|
55
55
|
max_tokens: 700,
|
|
@@ -86,19 +86,20 @@ async function createWithAPI(options) {
|
|
|
86
86
|
apiGlobals: {},
|
|
87
87
|
apiWhitelist: Object.getOwnPropertyNames(Object.getPrototypeOf(options.apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_")),
|
|
88
88
|
debug: false,
|
|
89
|
+
model: "gpt-4o",
|
|
89
90
|
...options
|
|
90
91
|
};
|
|
91
92
|
if (!options.apiObject || !options.apiDefFilePath) {
|
|
92
93
|
throw new Error("apiObject and apiFilePath are required");
|
|
93
94
|
}
|
|
94
|
-
const { apiObject, apiWhitelist, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug } = options;
|
|
95
|
+
const { apiObject, apiWhitelist, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug, model } = options;
|
|
95
96
|
const createTaskPrompt = createBasePrompt(apiDefFilePath, apiDocsPath);
|
|
96
97
|
return {
|
|
97
98
|
options,
|
|
98
99
|
generateCode: async function (queryText, userChatHistory, currentContext = undefined) {
|
|
99
100
|
if (!queryText)
|
|
100
101
|
return { code: '', loggableCode: '' };
|
|
101
|
-
return await (0, exports.generateCode)(queryText, userChatHistory, createTaskPrompt.replace("{{CONTEXT}}", currentContext ? "```" + JSON.stringify(currentContext, null, 2) + "```" : ""), apiDefFilePath, debug);
|
|
102
|
+
return await (0, exports.generateCode)(queryText, userChatHistory, createTaskPrompt.replace("{{CONTEXT}}", currentContext ? "```" + JSON.stringify(currentContext, null, 2) + "```" : ""), apiDefFilePath, debug, model);
|
|
102
103
|
},
|
|
103
104
|
runCode: async function (generatedCode) {
|
|
104
105
|
if (!QuickJS) {
|
package/lib/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface GenerateCodeResult {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// FIXME: add an options parameter and allow specifying the token limit
|
|
41
|
-
export const generateCode = async function(queryText:string, userChatHistory:ChatCompletionRequestMessage[], createTaskPrompt:string, apiPath:string, debug:boolean = false): Promise<GenerateCodeResult> {
|
|
41
|
+
export const generateCode = async function(queryText:string, userChatHistory:ChatCompletionRequestMessage[], createTaskPrompt:string, apiPath:string, debug:boolean = false, model="gpt-4o"): Promise<GenerateCodeResult> {
|
|
42
42
|
if(!queryText)
|
|
43
43
|
return { code: '', loggableCode: '' };
|
|
44
44
|
|
|
@@ -58,7 +58,7 @@ export const generateCode = async function(queryText:string, userChatHistory:Cha
|
|
|
58
58
|
];
|
|
59
59
|
try {
|
|
60
60
|
const results = await openai.createChatCompletion({
|
|
61
|
-
model
|
|
61
|
+
model,
|
|
62
62
|
messages: messages,
|
|
63
63
|
temperature: 0.1,
|
|
64
64
|
max_tokens: 700,
|
|
@@ -104,6 +104,7 @@ export interface AIMyAPIOptions {
|
|
|
104
104
|
apiGlobalName?: string;
|
|
105
105
|
apiDocsPath?: string;
|
|
106
106
|
debug?: boolean;
|
|
107
|
+
model?: string;
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
export interface AIMyAPIInstance {
|
|
@@ -122,7 +123,8 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<AIMyAPIInstance> {
|
|
|
122
123
|
apiGlobalName: "api",
|
|
123
124
|
apiGlobals: {},
|
|
124
125
|
apiWhitelist: Object.getOwnPropertyNames(Object.getPrototypeOf(options.apiObject)).filter((f) => f !== "constructor" && !f.startsWith("_")),
|
|
125
|
-
debug: false,
|
|
126
|
+
debug: false,
|
|
127
|
+
model: "gpt-4o",
|
|
126
128
|
...options
|
|
127
129
|
} as AIMyAPIOptions;
|
|
128
130
|
|
|
@@ -130,7 +132,7 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<AIMyAPIInstance> {
|
|
|
130
132
|
throw new Error("apiObject and apiFilePath are required");
|
|
131
133
|
}
|
|
132
134
|
|
|
133
|
-
const {apiObject, apiWhitelist, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug} = options;
|
|
135
|
+
const {apiObject, apiWhitelist, apiGlobalName, apiExports, apiDefFilePath, apiDocsPath, debug, model} = options;
|
|
134
136
|
|
|
135
137
|
const createTaskPrompt = createBasePrompt( apiDefFilePath, apiDocsPath);
|
|
136
138
|
|
|
@@ -140,7 +142,7 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<AIMyAPIInstance> {
|
|
|
140
142
|
if(!queryText)
|
|
141
143
|
return { code: '', loggableCode: '' };
|
|
142
144
|
|
|
143
|
-
return await generateCode(queryText, userChatHistory, createTaskPrompt.replace("{{CONTEXT}}", currentContext ? "```" + JSON.stringify(currentContext, null, 2) + "```" : ""), apiDefFilePath, debug);
|
|
145
|
+
return await generateCode(queryText, userChatHistory, createTaskPrompt.replace("{{CONTEXT}}", currentContext ? "```" + JSON.stringify(currentContext, null, 2) + "```" : ""), apiDefFilePath, debug, model);
|
|
144
146
|
},
|
|
145
147
|
runCode: async function(generatedCode:string) {
|
|
146
148
|
if(!QuickJS) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aimyapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "AI My API! Use LLMs to create small programs that safely* run and make calls against your API. Similar to ChatGPT's Code Interpreter.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|