aimyapi 1.0.8 → 1.0.9
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/LICENSE +21 -21
- package/README.md +195 -195
- package/dist/index.cjs +2 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -0
- package/example/example1.ts +30 -30
- package/example/example2.ts +58 -58
- package/example/example3.ts +69 -69
- package/example/ordering_api.md +94 -94
- package/example/ordering_api.ts +191 -191
- package/example/ordering_api_impl.ts +207 -207
- package/example/sales_api.md +4 -4
- package/example/sales_api.ts +29 -29
- package/example/sales_api_impl.ts +60 -60
- package/package.json +1 -1
- package/prompts/create-task-prompt.md +37 -37
- package/src/index.ts +495 -495
- package/src/sandbox-wrappers.ts +251 -249
- package/src/sandbox.ts +277 -277
- package/src/utils.ts +2 -2
- package/tsconfig.json +12 -12
package/example/example3.ts
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
import { AIMyAPI } from "../src";
|
|
3
|
-
import { Menu } from "./ordering_api";
|
|
4
|
-
import { OrderingAPI } from "./ordering_api_impl";
|
|
5
|
-
|
|
6
|
-
import readline from 'readline';
|
|
7
|
-
|
|
8
|
-
function getInput(query: string): Promise<string> {
|
|
9
|
-
const rl = readline.createInterface({
|
|
10
|
-
input: process.stdin,
|
|
11
|
-
output: process.stdout,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
return new Promise(resolve => rl.question(query, ans => {
|
|
15
|
-
rl.close();
|
|
16
|
-
resolve(ans);
|
|
17
|
-
}))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// More complex fast food ordering example that uses chat history.
|
|
21
|
-
// Fast food ordering example.
|
|
22
|
-
// -- Interactive version
|
|
23
|
-
(async () => {
|
|
24
|
-
const orderingApi = new OrderingAPI();
|
|
25
|
-
|
|
26
|
-
const options = {
|
|
27
|
-
apiObject: orderingApi,
|
|
28
|
-
apiGlobalName: "orderingApi", // Should match whatever you declared as your global in your ordering api.
|
|
29
|
-
apiGlobals: {
|
|
30
|
-
Menu: Menu,
|
|
31
|
-
},
|
|
32
|
-
apiDefFilePath: "./example/ordering_api.ts",
|
|
33
|
-
apiDocsPath: "./example/ordering_api.md",
|
|
34
|
-
debug: false,
|
|
35
|
-
};
|
|
36
|
-
const aimyapi = await AIMyAPI.createWithAPI(options)
|
|
37
|
-
|
|
38
|
-
async function runQuery(query:string) {
|
|
39
|
-
console.log(`Query: ${query}`)
|
|
40
|
-
|
|
41
|
-
// generate the code for this query
|
|
42
|
-
const result = await aimyapi.generateCode(query, orderingApi._getHistory());
|
|
43
|
-
|
|
44
|
-
if(result) {
|
|
45
|
-
orderingApi._addMessageToHistory({
|
|
46
|
-
content: query,
|
|
47
|
-
role: "user",
|
|
48
|
-
name: "user",
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
orderingApi._addMessageToHistory({
|
|
52
|
-
content: result.comments || "done",
|
|
53
|
-
role: "assistant",
|
|
54
|
-
name: "assistant",
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// run the code in the sandbox
|
|
58
|
-
if(result.code) {
|
|
59
|
-
await aimyapi.runCode(result.code);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log("Welcome to the restaurant. You can ask to hear the menu or order something. What would you like to do?");
|
|
65
|
-
while (!orderingApi._isCompleted) {
|
|
66
|
-
const query:string = await getInput("Your query: ");
|
|
67
|
-
await runQuery(query);
|
|
68
|
-
}
|
|
69
|
-
|
|
1
|
+
|
|
2
|
+
import { AIMyAPI } from "../src";
|
|
3
|
+
import { Menu } from "./ordering_api";
|
|
4
|
+
import { OrderingAPI } from "./ordering_api_impl";
|
|
5
|
+
|
|
6
|
+
import readline from 'readline';
|
|
7
|
+
|
|
8
|
+
function getInput(query: string): Promise<string> {
|
|
9
|
+
const rl = readline.createInterface({
|
|
10
|
+
input: process.stdin,
|
|
11
|
+
output: process.stdout,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return new Promise(resolve => rl.question(query, ans => {
|
|
15
|
+
rl.close();
|
|
16
|
+
resolve(ans);
|
|
17
|
+
}))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// More complex fast food ordering example that uses chat history.
|
|
21
|
+
// Fast food ordering example.
|
|
22
|
+
// -- Interactive version
|
|
23
|
+
(async () => {
|
|
24
|
+
const orderingApi = new OrderingAPI();
|
|
25
|
+
|
|
26
|
+
const options = {
|
|
27
|
+
apiObject: orderingApi,
|
|
28
|
+
apiGlobalName: "orderingApi", // Should match whatever you declared as your global in your ordering api.
|
|
29
|
+
apiGlobals: {
|
|
30
|
+
Menu: Menu,
|
|
31
|
+
},
|
|
32
|
+
apiDefFilePath: "./example/ordering_api.ts",
|
|
33
|
+
apiDocsPath: "./example/ordering_api.md",
|
|
34
|
+
debug: false,
|
|
35
|
+
};
|
|
36
|
+
const aimyapi = await AIMyAPI.createWithAPI(options)
|
|
37
|
+
|
|
38
|
+
async function runQuery(query:string) {
|
|
39
|
+
console.log(`Query: ${query}`)
|
|
40
|
+
|
|
41
|
+
// generate the code for this query
|
|
42
|
+
const result = await aimyapi.generateCode(query, orderingApi._getHistory());
|
|
43
|
+
|
|
44
|
+
if(result) {
|
|
45
|
+
orderingApi._addMessageToHistory({
|
|
46
|
+
content: query,
|
|
47
|
+
role: "user",
|
|
48
|
+
name: "user",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
orderingApi._addMessageToHistory({
|
|
52
|
+
content: result.comments || "done",
|
|
53
|
+
role: "assistant",
|
|
54
|
+
name: "assistant",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// run the code in the sandbox
|
|
58
|
+
if(result.code) {
|
|
59
|
+
await aimyapi.runCode(result.code);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log("Welcome to the restaurant. You can ask to hear the menu or order something. What would you like to do?");
|
|
65
|
+
while (!orderingApi._isCompleted) {
|
|
66
|
+
const query:string = await getInput("Your query: ");
|
|
67
|
+
await runQuery(query);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
70
|
})();
|
package/example/ordering_api.md
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
# Documentation
|
|
2
|
-
|
|
3
|
-
You work at a restaurant.
|
|
4
|
-
Your responses should be energetic, positive and polite.
|
|
5
|
-
Help the customer with whatever questions they may have and ring up their orders.
|
|
6
|
-
Do not complete the order until the user says they are finished ordering.
|
|
7
|
-
Your code should check for errors or for cases where items may not be found.
|
|
8
|
-
|
|
9
|
-
## Examples of how you should respond:
|
|
10
|
-
|
|
11
|
-
user: How are you today?
|
|
12
|
-
|
|
13
|
-
code:
|
|
14
|
-
```typescript
|
|
15
|
-
orderingApi.respondToUser("I'm great, thanks for asking!");
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
user: Add a hamburger with no cheese to my order
|
|
19
|
-
|
|
20
|
-
code:
|
|
21
|
-
```typescript
|
|
22
|
-
const itemName = "Hamburger";
|
|
23
|
-
const item = Menu.find((item) => item.name === itemName);
|
|
24
|
-
if (!item) {
|
|
25
|
-
throw new Error(`Item with name "${itemName}" not found`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
orderingApi.addItemToOrder(itemName, undefined, item.toppings.filter( topping => topping.name != "cheese") );
|
|
29
|
-
orderingApi.respondToUser("Ok, I added a Hamburger. What else would you like?");
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
log: Added Hamburger with id 1
|
|
33
|
-
|
|
34
|
-
user: I'd like a large pizza with mushrooms
|
|
35
|
-
|
|
36
|
-
code:
|
|
37
|
-
```typescript
|
|
38
|
-
orderingApi.addItemToOrder("Pizza", ["Large"], ["mushrooms"]);
|
|
39
|
-
orderingApi.respondToUser("Ok, I added a Large Pizza with mushrooms");
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
user: Add a hamburger with bacon
|
|
43
|
-
|
|
44
|
-
code:
|
|
45
|
-
```typescript
|
|
46
|
-
const itemName = "Hamburger";
|
|
47
|
-
const item = Menu.find((item) => item.name === itemName);
|
|
48
|
-
if (!item) {
|
|
49
|
-
throw new Error(`Item with name "${itemName}" not found`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
orderingApi.addItemToOrder(itemName, undefined, [...item.toppings, "bacon"]);
|
|
53
|
-
orderingApi.respondToUser("Ok, I added a Hamburger with no cheese or onions. What else would you like?");
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
log: Added Hamburger with id 2
|
|
57
|
-
|
|
58
|
-
user: Add jalapenos to that
|
|
59
|
-
|
|
60
|
-
code:
|
|
61
|
-
```typescript
|
|
62
|
-
const existingItem = orderingApi.getItemInOrder("2");
|
|
63
|
-
|
|
64
|
-
if(existingItem) {
|
|
65
|
-
orderingApi.modifyItemInOrder("2", existingItem.customizations.map(item => item.name), [...existingItem.toppings, "jalapenos"]);
|
|
66
|
-
orderingApi.respondToUser("Ok, I added jalapenos to your Hamburger");
|
|
67
|
-
} else {
|
|
68
|
-
orderingApi.respondToUser("Hmm, I can't find that item.");
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
user: Add a hamburger with no lettuce
|
|
73
|
-
|
|
74
|
-
code:
|
|
75
|
-
```typescript
|
|
76
|
-
const itemName = "Hamburger";
|
|
77
|
-
const item = Menu.find((item) => item.name === itemName);
|
|
78
|
-
if (!item) {
|
|
79
|
-
throw new Error(`Item with name "${itemName}" not found`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
orderingApi.addItemToOrder(itemName, undefined, [...item.toppings.filter(topping => topping != "lettuce")]);
|
|
83
|
-
orderingApi.respondToUser("Ok, I added a Hamburger with no cheese or onions. What else would you like?");
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
log: Added Hamburger with id 2
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
user: I want an elephant.
|
|
90
|
-
|
|
91
|
-
code:
|
|
92
|
-
```typescript
|
|
93
|
-
orderingApi.respondToUser("I'm sorry, but that isn't on our menu.");
|
|
94
|
-
```
|
|
1
|
+
# Documentation
|
|
2
|
+
|
|
3
|
+
You work at a restaurant.
|
|
4
|
+
Your responses should be energetic, positive and polite.
|
|
5
|
+
Help the customer with whatever questions they may have and ring up their orders.
|
|
6
|
+
Do not complete the order until the user says they are finished ordering.
|
|
7
|
+
Your code should check for errors or for cases where items may not be found.
|
|
8
|
+
|
|
9
|
+
## Examples of how you should respond:
|
|
10
|
+
|
|
11
|
+
user: How are you today?
|
|
12
|
+
|
|
13
|
+
code:
|
|
14
|
+
```typescript
|
|
15
|
+
orderingApi.respondToUser("I'm great, thanks for asking!");
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
user: Add a hamburger with no cheese to my order
|
|
19
|
+
|
|
20
|
+
code:
|
|
21
|
+
```typescript
|
|
22
|
+
const itemName = "Hamburger";
|
|
23
|
+
const item = Menu.find((item) => item.name === itemName);
|
|
24
|
+
if (!item) {
|
|
25
|
+
throw new Error(`Item with name "${itemName}" not found`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
orderingApi.addItemToOrder(itemName, undefined, item.toppings.filter( topping => topping.name != "cheese") );
|
|
29
|
+
orderingApi.respondToUser("Ok, I added a Hamburger. What else would you like?");
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
log: Added Hamburger with id 1
|
|
33
|
+
|
|
34
|
+
user: I'd like a large pizza with mushrooms
|
|
35
|
+
|
|
36
|
+
code:
|
|
37
|
+
```typescript
|
|
38
|
+
orderingApi.addItemToOrder("Pizza", ["Large"], ["mushrooms"]);
|
|
39
|
+
orderingApi.respondToUser("Ok, I added a Large Pizza with mushrooms");
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
user: Add a hamburger with bacon
|
|
43
|
+
|
|
44
|
+
code:
|
|
45
|
+
```typescript
|
|
46
|
+
const itemName = "Hamburger";
|
|
47
|
+
const item = Menu.find((item) => item.name === itemName);
|
|
48
|
+
if (!item) {
|
|
49
|
+
throw new Error(`Item with name "${itemName}" not found`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
orderingApi.addItemToOrder(itemName, undefined, [...item.toppings, "bacon"]);
|
|
53
|
+
orderingApi.respondToUser("Ok, I added a Hamburger with no cheese or onions. What else would you like?");
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
log: Added Hamburger with id 2
|
|
57
|
+
|
|
58
|
+
user: Add jalapenos to that
|
|
59
|
+
|
|
60
|
+
code:
|
|
61
|
+
```typescript
|
|
62
|
+
const existingItem = orderingApi.getItemInOrder("2");
|
|
63
|
+
|
|
64
|
+
if(existingItem) {
|
|
65
|
+
orderingApi.modifyItemInOrder("2", existingItem.customizations.map(item => item.name), [...existingItem.toppings, "jalapenos"]);
|
|
66
|
+
orderingApi.respondToUser("Ok, I added jalapenos to your Hamburger");
|
|
67
|
+
} else {
|
|
68
|
+
orderingApi.respondToUser("Hmm, I can't find that item.");
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
user: Add a hamburger with no lettuce
|
|
73
|
+
|
|
74
|
+
code:
|
|
75
|
+
```typescript
|
|
76
|
+
const itemName = "Hamburger";
|
|
77
|
+
const item = Menu.find((item) => item.name === itemName);
|
|
78
|
+
if (!item) {
|
|
79
|
+
throw new Error(`Item with name "${itemName}" not found`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
orderingApi.addItemToOrder(itemName, undefined, [...item.toppings.filter(topping => topping != "lettuce")]);
|
|
83
|
+
orderingApi.respondToUser("Ok, I added a Hamburger with no cheese or onions. What else would you like?");
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
log: Added Hamburger with id 2
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
user: I want an elephant.
|
|
90
|
+
|
|
91
|
+
code:
|
|
92
|
+
```typescript
|
|
93
|
+
orderingApi.respondToUser("I'm sorry, but that isn't on our menu.");
|
|
94
|
+
```
|