aimyapi 0.1.2 → 0.1.4
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 +196 -4
- package/dist/{lib/index.d.ts → index.d.ts} +1 -1
- package/dist/{lib/index.js → index.js} +18 -16
- package/dist/{lib/sandbox.js → sandbox.js} +1 -1
- package/example/example1.ts +0 -2
- package/example/example2.ts +5 -7
- package/example/ordering_api.md +23 -11
- package/example/ordering_api.ts +8 -12
- package/example/ordering_api_impl.ts +30 -21
- package/lib/index.ts +18 -21
- package/lib/sandbox.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.json +2 -2
- package/dist/example/example1.d.ts +0 -1
- package/dist/example/example1.js +0 -52
- package/dist/example/example2.d.ts +0 -1
- package/dist/example/example2.js +0 -66
- package/dist/example/example3.d.ts +0 -1
- package/dist/example/example3.js +0 -79
- package/dist/example/ordering_api.d.ts +0 -36
- package/dist/example/ordering_api.js +0 -125
- package/dist/example/ordering_api_impl.d.ts +0 -23
- package/dist/example/ordering_api_impl.js +0 -128
- package/dist/example/sales_api.d.ts +0 -16
- package/dist/example/sales_api.js +0 -5
- package/dist/example/sales_api_impl.d.ts +0 -7
- package/dist/example/sales_api_impl.js +0 -59
- /package/dist/{lib/sandbox-wrappers.d.ts → sandbox-wrappers.d.ts} +0 -0
- /package/dist/{lib/sandbox-wrappers.js → sandbox-wrappers.js} +0 -0
- /package/dist/{lib/sandbox.d.ts → sandbox.d.ts} +0 -0
- /package/dist/{lib/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/{lib/utils.js → utils.js} +0 -0
package/lib/index.ts
CHANGED
|
@@ -27,22 +27,31 @@ export function createBasePrompt(apiFilePath:string, documentationPath: string):
|
|
|
27
27
|
const documentationText: string = documentationPath ? fs.readFileSync(documentationPath, 'utf8') : '';
|
|
28
28
|
|
|
29
29
|
//console.time("Loading templates");
|
|
30
|
-
|
|
31
|
-
const createTaskPrompt: string = fs.readFileSync( path.join(__dirname, '../prompts/create-task-prompt.md'), 'utf8').replace("{{DOCUMENTATION}}", documentationText).replace("{{API}}", apiText);
|
|
32
|
-
|
|
30
|
+
const createTaskPrompt: string = fs.readFileSync( path.join(__dirname, '../prompts/create-task-prompt.md'), 'utf8').replace("{{DOCUMENTATION}}", documentationText).replace("{{API}}", apiText);
|
|
33
31
|
//console.timeEnd("Loading templates")
|
|
34
32
|
|
|
35
33
|
return createTaskPrompt;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
//
|
|
36
|
+
// FIXME: add an options parameter and allow specifying the token limit
|
|
39
37
|
export const generateCode = async function(queryText:string, userChatHistory:ChatCompletionRequestMessage[], createTaskPrompt:string, apiPath:string, debug:boolean = false): Promise<string> {
|
|
40
38
|
if(!queryText)
|
|
41
39
|
return;
|
|
42
40
|
|
|
43
41
|
let generatedCode = '';
|
|
44
42
|
const prompt = createTaskPrompt.replace("{{QUERY_TEXT}}", queryText);
|
|
45
|
-
|
|
43
|
+
const messages:ChatCompletionRequestMessage[] = [
|
|
44
|
+
{
|
|
45
|
+
role: "system",
|
|
46
|
+
content: prompt,
|
|
47
|
+
},
|
|
48
|
+
...userChatHistory,
|
|
49
|
+
{
|
|
50
|
+
role: "user",
|
|
51
|
+
content: `${queryText}`,
|
|
52
|
+
name: "user"
|
|
53
|
+
}
|
|
54
|
+
];
|
|
46
55
|
// TODO: I should switch this back to gpt3.5 turbo since it's cheaper
|
|
47
56
|
try {
|
|
48
57
|
// const task = await openai.createCompletion(
|
|
@@ -56,24 +65,12 @@ export const generateCode = async function(queryText:string, userChatHistory:Cha
|
|
|
56
65
|
|
|
57
66
|
const results = await openai.createChatCompletion({
|
|
58
67
|
model: "gpt-3.5-turbo",
|
|
59
|
-
messages:
|
|
60
|
-
{
|
|
61
|
-
role: "system",
|
|
62
|
-
content: prompt,
|
|
63
|
-
},
|
|
64
|
-
...userChatHistory,
|
|
65
|
-
{
|
|
66
|
-
role: "user",
|
|
67
|
-
content: `${queryText}`,
|
|
68
|
-
name: "user"
|
|
69
|
-
}
|
|
70
|
-
],
|
|
68
|
+
messages: messages,
|
|
71
69
|
temperature: 0.1,
|
|
72
|
-
max_tokens:
|
|
70
|
+
max_tokens: 700,
|
|
73
71
|
}
|
|
74
72
|
);
|
|
75
73
|
|
|
76
|
-
|
|
77
74
|
if(debug)
|
|
78
75
|
console.log(results.data.usage);
|
|
79
76
|
|
|
@@ -91,13 +88,13 @@ export const generateCode = async function(queryText:string, userChatHistory:Cha
|
|
|
91
88
|
|
|
92
89
|
generatedCode = response.substring(codeStart + 3, codeEnd).replace('typescript', '');
|
|
93
90
|
|
|
94
|
-
generatedCode =
|
|
91
|
+
generatedCode = generatedCode.replace("./api.ts", apiPath);
|
|
95
92
|
return generatedCode;
|
|
96
93
|
} catch(err) {
|
|
97
94
|
console.error(err);
|
|
95
|
+
console.log("Prompt", messages);
|
|
98
96
|
return '';
|
|
99
97
|
}
|
|
100
|
-
|
|
101
98
|
};
|
|
102
99
|
|
|
103
100
|
let QuickJS:QuickJSWASMModule = null;
|
package/lib/sandbox.ts
CHANGED
|
@@ -139,7 +139,7 @@ export default async function createSandbox(QuickJS, requireLookup:any = {}, glo
|
|
|
139
139
|
const compiled = tsCompile(task);
|
|
140
140
|
|
|
141
141
|
if (!compiled || compiled.length === 0) {
|
|
142
|
-
console.
|
|
142
|
+
console.error("Could not compile", task);
|
|
143
143
|
return false;
|
|
144
144
|
}
|
|
145
145
|
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/example/example1.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const lib_1 = __importDefault(require("../lib"));
|
|
30
|
-
const sales_api_impl_1 = require("./sales_api_impl");
|
|
31
|
-
const APIExports = __importStar(require("./sales_api"));
|
|
32
|
-
const path_1 = __importDefault(require("path"));
|
|
33
|
-
// Simpler example using no support for chat history;
|
|
34
|
-
(async () => {
|
|
35
|
-
const api = new sales_api_impl_1.API();
|
|
36
|
-
const aimyapi = await lib_1.default.createWithAPI({
|
|
37
|
-
apiObject: api,
|
|
38
|
-
apiGlobalName: "api",
|
|
39
|
-
apiExports: APIExports,
|
|
40
|
-
apiDefFilePath: path_1.default.join(__dirname, "./sales_api.ts"),
|
|
41
|
-
apiDocsPath: path_1.default.join(__dirname, "./sales_api.md"),
|
|
42
|
-
debug: false,
|
|
43
|
-
});
|
|
44
|
-
console.log("Print 'hello' three times.");
|
|
45
|
-
await aimyapi.processRequest("Print 'hello' three times.");
|
|
46
|
-
console.log("What was our best month in 2020");
|
|
47
|
-
await aimyapi.processRequest("What was our best month in 2020");
|
|
48
|
-
console.log("Which business unit had the highest sales in 2020?");
|
|
49
|
-
await aimyapi.processRequest("Which business unit had the highest sales in 2020?");
|
|
50
|
-
console.log("Compute the total sales for each month in 2020 then email the top 3 to test@email.com");
|
|
51
|
-
await aimyapi.processRequest("Compute the total sales for each month in 2020 then email the top 3 to test@email.com");
|
|
52
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/example/example2.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const lib_1 = __importDefault(require("../lib"));
|
|
30
|
-
const ordering_api_impl_1 = require("./ordering_api_impl");
|
|
31
|
-
const APIExports = __importStar(require("./ordering_api"));
|
|
32
|
-
const path_1 = __importDefault(require("path"));
|
|
33
|
-
// More complex fast food ordering example that uses chat history.
|
|
34
|
-
// Fast food ordering example.
|
|
35
|
-
(async () => {
|
|
36
|
-
const api = new ordering_api_impl_1.OrderingAPI();
|
|
37
|
-
const aimyapi = await lib_1.default.createWithAPI({
|
|
38
|
-
apiObject: api,
|
|
39
|
-
apiGlobalName: "orderingApi",
|
|
40
|
-
apiExports: APIExports,
|
|
41
|
-
apiDefFilePath: path_1.default.join(__dirname, "./ordering_api.ts"),
|
|
42
|
-
apiDocsPath: path_1.default.join(__dirname, "./ordering_api.md"),
|
|
43
|
-
debug: false,
|
|
44
|
-
});
|
|
45
|
-
async function runQuery(query) {
|
|
46
|
-
console.log(`Query: ${query}`);
|
|
47
|
-
// generate the code for this query
|
|
48
|
-
const code = await aimyapi.generateCode(query, api._getHistory());
|
|
49
|
-
api._addMessageToHistory({
|
|
50
|
-
content: query,
|
|
51
|
-
role: "user",
|
|
52
|
-
name: "user",
|
|
53
|
-
});
|
|
54
|
-
api._addMessageToHistory({
|
|
55
|
-
content: '```\n' + code + '\n```',
|
|
56
|
-
role: "assistant",
|
|
57
|
-
name: "assistant",
|
|
58
|
-
});
|
|
59
|
-
// run the code in the sandbox
|
|
60
|
-
await aimyapi.runCode(code);
|
|
61
|
-
}
|
|
62
|
-
await runQuery("How's the burger here?");
|
|
63
|
-
await runQuery("I'd like a plain hamburger and a large fries, a pizza with anchovies and a cola. I'd also like a cheese burger with bacon and avocado.");
|
|
64
|
-
await runQuery("I changed my mind, instead of anchovies, can I get a large gluten free pizza with pineapple instead.");
|
|
65
|
-
await runQuery("email me the total at myemail@test.com and complete the order");
|
|
66
|
-
})();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/example/example3.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const lib_1 = __importDefault(require("../lib"));
|
|
30
|
-
const ordering_api_impl_1 = require("./ordering_api_impl");
|
|
31
|
-
const APIExports = __importStar(require("./ordering_api"));
|
|
32
|
-
const path_1 = __importDefault(require("path"));
|
|
33
|
-
const readline_1 = __importDefault(require("readline"));
|
|
34
|
-
function getInput(query) {
|
|
35
|
-
const rl = readline_1.default.createInterface({
|
|
36
|
-
input: process.stdin,
|
|
37
|
-
output: process.stdout,
|
|
38
|
-
});
|
|
39
|
-
return new Promise(resolve => rl.question(query, ans => {
|
|
40
|
-
rl.close();
|
|
41
|
-
resolve(ans);
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
// More complex fast food ordering example that uses chat history.
|
|
45
|
-
// Fast food ordering example.
|
|
46
|
-
// Interactive version
|
|
47
|
-
(async () => {
|
|
48
|
-
const api = new ordering_api_impl_1.OrderingAPI();
|
|
49
|
-
const aimyapi = await lib_1.default.createWithAPI({
|
|
50
|
-
apiObject: api,
|
|
51
|
-
apiGlobalName: "orderingApi",
|
|
52
|
-
apiExports: APIExports,
|
|
53
|
-
apiDefFilePath: path_1.default.join(__dirname, "./ordering_api.ts"),
|
|
54
|
-
apiDocsPath: path_1.default.join(__dirname, "./ordering_api.md"),
|
|
55
|
-
debug: false,
|
|
56
|
-
});
|
|
57
|
-
async function runQuery(query) {
|
|
58
|
-
console.log(`Query: ${query}`);
|
|
59
|
-
// generate the code for this query
|
|
60
|
-
const code = await aimyapi.generateCode(query, api._getHistory());
|
|
61
|
-
api._addMessageToHistory({
|
|
62
|
-
content: query,
|
|
63
|
-
role: "user",
|
|
64
|
-
name: "user",
|
|
65
|
-
});
|
|
66
|
-
api._addMessageToHistory({
|
|
67
|
-
content: '```\n' + code + '\n```',
|
|
68
|
-
role: "assistant",
|
|
69
|
-
name: "assistant",
|
|
70
|
-
});
|
|
71
|
-
// run the code in the sandbox
|
|
72
|
-
await aimyapi.runCode(code);
|
|
73
|
-
}
|
|
74
|
-
console.log("Welcome to the restaurant. You can ask to hear the menu or order something. What would you like to do?");
|
|
75
|
-
while (!api._isCompleted) {
|
|
76
|
-
const query = await getInput("Your query: ");
|
|
77
|
-
await runQuery(query);
|
|
78
|
-
}
|
|
79
|
-
})();
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export declare const API_VERSION = "1.0.1";
|
|
2
|
-
export interface Customization {
|
|
3
|
-
name: string;
|
|
4
|
-
priceAdjustment: number;
|
|
5
|
-
}
|
|
6
|
-
export interface MenuItemBase {
|
|
7
|
-
orderId?: string;
|
|
8
|
-
name: string;
|
|
9
|
-
price: number;
|
|
10
|
-
description: string;
|
|
11
|
-
category: string;
|
|
12
|
-
tags: string[];
|
|
13
|
-
customizations: Customization[];
|
|
14
|
-
readonly allowedCustomizations: Customization[];
|
|
15
|
-
toppings: string[];
|
|
16
|
-
readonly allowedToppings: string[];
|
|
17
|
-
}
|
|
18
|
-
export declare const Menu: MenuItemBase[];
|
|
19
|
-
export interface OrderingAPIInterface {
|
|
20
|
-
sendEmail(to: string, subject: string, body: string): Promise<void>;
|
|
21
|
-
getCurrentOrder(): MenuItemBase[];
|
|
22
|
-
getItemInOrder(itemOrderId: string): MenuItemBase | undefined;
|
|
23
|
-
getCustomizationByName(itemName: string, name: string): Customization | undefined;
|
|
24
|
-
addItemToOrder(itemName: string, customizationNames: string[], toppings: string[]): void;
|
|
25
|
-
removeItemFromOrder(itemOrderId: string): void;
|
|
26
|
-
modifyItemInOrder(itemOrderId: string, customizationNames: string[], toppings: string[]): void;
|
|
27
|
-
getOrderTotal(): number;
|
|
28
|
-
completeOrder(): void;
|
|
29
|
-
respondToUser(text: string): void;
|
|
30
|
-
delay(milliseconds: number): Promise<void>;
|
|
31
|
-
displayItem(item: MenuItemBase): void;
|
|
32
|
-
displayOrder(): void;
|
|
33
|
-
}
|
|
34
|
-
declare global {
|
|
35
|
-
var orderingApi: OrderingAPIInterface;
|
|
36
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Menu = exports.API_VERSION = void 0;
|
|
4
|
-
exports.API_VERSION = "1.0.1";
|
|
5
|
-
exports.Menu = [
|
|
6
|
-
{
|
|
7
|
-
"name": "Pizza",
|
|
8
|
-
"price": 10.99,
|
|
9
|
-
"description": "A classic pizza with your choice of toppings.",
|
|
10
|
-
"category": "Pizza",
|
|
11
|
-
"tags": [
|
|
12
|
-
"cheese",
|
|
13
|
-
"pizza"
|
|
14
|
-
],
|
|
15
|
-
"customizations": [],
|
|
16
|
-
"allowedCustomizations": [
|
|
17
|
-
{
|
|
18
|
-
"name": "Extra Cheese",
|
|
19
|
-
"priceAdjustment": 1.99
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"name": "Extra Sauce",
|
|
23
|
-
"priceAdjustment": 0.99
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"name": "Gluten Free Crust",
|
|
27
|
-
"priceAdjustment": 2.99
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"name": "Large",
|
|
31
|
-
"priceAdjustment": 3.99
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
"toppings": [],
|
|
35
|
-
"allowedToppings": [
|
|
36
|
-
"pepperoni",
|
|
37
|
-
"sausage",
|
|
38
|
-
"mushrooms",
|
|
39
|
-
"onions",
|
|
40
|
-
"green peppers",
|
|
41
|
-
"black olives",
|
|
42
|
-
"green olives",
|
|
43
|
-
"anchovies",
|
|
44
|
-
"pineapple",
|
|
45
|
-
"ham",
|
|
46
|
-
"bacon",
|
|
47
|
-
"chicken",
|
|
48
|
-
]
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"name": "Hamburger",
|
|
52
|
-
"price": 8.99,
|
|
53
|
-
"description": "A classic american hamburger with your choice of toppings. Cheese, lettuce, tomato, and onion are included by default. Other toppings available on request.",
|
|
54
|
-
"category": "Burgers",
|
|
55
|
-
"tags": [
|
|
56
|
-
"hamburger",
|
|
57
|
-
"burger"
|
|
58
|
-
],
|
|
59
|
-
"customizations": [],
|
|
60
|
-
"allowedCustomizations": [
|
|
61
|
-
{
|
|
62
|
-
"name": "Special sauce",
|
|
63
|
-
"priceAdjustment": 1.99
|
|
64
|
-
}
|
|
65
|
-
],
|
|
66
|
-
"toppings": [],
|
|
67
|
-
"allowedToppings": [
|
|
68
|
-
"cheese",
|
|
69
|
-
"lettuce",
|
|
70
|
-
"tomato",
|
|
71
|
-
"onion",
|
|
72
|
-
"pickles",
|
|
73
|
-
"bacon",
|
|
74
|
-
"mushrooms",
|
|
75
|
-
"avocado",
|
|
76
|
-
"jalapenos",
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"name": "Fries",
|
|
81
|
-
"price": 2.99,
|
|
82
|
-
"description": "A classic side of fries.",
|
|
83
|
-
"category": "Sides",
|
|
84
|
-
"tags": [
|
|
85
|
-
"fries",
|
|
86
|
-
"french fries"
|
|
87
|
-
],
|
|
88
|
-
"customizations": [],
|
|
89
|
-
"allowedCustomizations": [
|
|
90
|
-
{
|
|
91
|
-
"name": "Large",
|
|
92
|
-
"priceAdjustment": 1.99
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
"toppings": [],
|
|
96
|
-
"allowedToppings": [
|
|
97
|
-
"old bay",
|
|
98
|
-
]
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
"name": "Fountain Drink",
|
|
102
|
-
"price": 1.99,
|
|
103
|
-
"description": "A classic fountain drink. Choose from Cola, Diet Cola, Dr. Dazzle, or Mountain Rush.",
|
|
104
|
-
"category": "Drinks",
|
|
105
|
-
"tags": [
|
|
106
|
-
"drink",
|
|
107
|
-
"soda",
|
|
108
|
-
"fountain drink"
|
|
109
|
-
],
|
|
110
|
-
"customizations": [],
|
|
111
|
-
"allowedCustomizations": [
|
|
112
|
-
{
|
|
113
|
-
"name": "Large",
|
|
114
|
-
"priceAdjustment": 0.99
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"name": "Extra Ice",
|
|
118
|
-
"priceAdjustment": 0.99
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
"toppings": [],
|
|
122
|
-
"allowedToppings": []
|
|
123
|
-
}
|
|
124
|
-
];
|
|
125
|
-
;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { ChatCompletionRequestMessage } from "openai";
|
|
2
|
-
import { Customization, MenuItemBase, OrderingAPIInterface } from "./ordering_api";
|
|
3
|
-
export declare class OrderingAPI implements OrderingAPIInterface {
|
|
4
|
-
private _order;
|
|
5
|
-
private _lastOrderIdNumber;
|
|
6
|
-
_isCompleted: boolean;
|
|
7
|
-
private _history;
|
|
8
|
-
sendEmail(to: string, subject: string, body: string): Promise<void>;
|
|
9
|
-
respondToUser(text: string): void;
|
|
10
|
-
delay(milliseconds: number): Promise<void>;
|
|
11
|
-
getCurrentOrder(): MenuItemBase[];
|
|
12
|
-
getCustomizationByName(itemName: string, name: string): Customization | undefined;
|
|
13
|
-
addItemToOrder(itemName: string, customizationNames: string[], toppings: string[]): void;
|
|
14
|
-
getItemInOrder(itemOrderId: string): MenuItemBase;
|
|
15
|
-
removeItemFromOrder(itemOrderId: string): void;
|
|
16
|
-
modifyItemInOrder(itemOrderId: string, customizationNames: string[], toppings: string[]): void;
|
|
17
|
-
getOrderTotal(): number;
|
|
18
|
-
completeOrder(): void;
|
|
19
|
-
displayItem(item: MenuItemBase): void;
|
|
20
|
-
displayOrder(): void;
|
|
21
|
-
_addMessageToHistory(message: ChatCompletionRequestMessage): void;
|
|
22
|
-
_getHistory(): ChatCompletionRequestMessage[];
|
|
23
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrderingAPI = void 0;
|
|
4
|
-
const utils_1 = require("../lib/utils");
|
|
5
|
-
const ordering_api_1 = require("./ordering_api");
|
|
6
|
-
// TODO: make functions to print out an item, and print out the current order with the price totals.
|
|
7
|
-
class OrderingAPI {
|
|
8
|
-
constructor() {
|
|
9
|
-
this._order = [];
|
|
10
|
-
this._lastOrderIdNumber = 0;
|
|
11
|
-
this._isCompleted = false;
|
|
12
|
-
this._history = [];
|
|
13
|
-
}
|
|
14
|
-
// Mock implementation, doesn't actually send an email
|
|
15
|
-
sendEmail(to, subject, body) {
|
|
16
|
-
console.log(`Sending email to "${to}" with subject "${subject}" and body\n"${body}"`);
|
|
17
|
-
return (0, utils_1.delay)(1000);
|
|
18
|
-
}
|
|
19
|
-
respondToUser(text) {
|
|
20
|
-
console.log(text);
|
|
21
|
-
this._history.push({
|
|
22
|
-
role: "assistant",
|
|
23
|
-
content: "Response output: " + text,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
delay(milliseconds) {
|
|
27
|
-
return (0, utils_1.delay)(milliseconds);
|
|
28
|
-
}
|
|
29
|
-
getCurrentOrder() {
|
|
30
|
-
return this._order;
|
|
31
|
-
}
|
|
32
|
-
// addItemToOrder(item: MenuItemBase) {
|
|
33
|
-
// item.orderId = "" + (this._lastOrderIdNumber++);
|
|
34
|
-
// this._order.push(item);
|
|
35
|
-
// }
|
|
36
|
-
getCustomizationByName(itemName, name) {
|
|
37
|
-
const item = ordering_api_1.Menu.find((item) => item.name === itemName);
|
|
38
|
-
if (!item) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
return item.allowedCustomizations.find((customization) => customization.name === name);
|
|
42
|
-
}
|
|
43
|
-
addItemToOrder(itemName, customizationNames, toppings) {
|
|
44
|
-
const item = ordering_api_1.Menu.find((item) => item.name === itemName);
|
|
45
|
-
if (!item) {
|
|
46
|
-
throw new Error(`Item with name "${itemName}" not found`);
|
|
47
|
-
}
|
|
48
|
-
const customizations = customizationNames
|
|
49
|
-
.map((customizationName) => {
|
|
50
|
-
return this.getCustomizationByName(itemName, customizationName);
|
|
51
|
-
})
|
|
52
|
-
.filter((customization) => customization !== undefined);
|
|
53
|
-
const newItem = {
|
|
54
|
-
...item,
|
|
55
|
-
customizations,
|
|
56
|
-
toppings: toppings,
|
|
57
|
-
orderId: "" + this._lastOrderIdNumber++,
|
|
58
|
-
};
|
|
59
|
-
this._order.push(newItem);
|
|
60
|
-
this.respondToUser(`Added ${itemName} with id ${newItem.orderId}`);
|
|
61
|
-
this.displayItem(newItem);
|
|
62
|
-
}
|
|
63
|
-
getItemInOrder(itemOrderId) {
|
|
64
|
-
const item = this._order.find((item) => item.orderId === itemOrderId);
|
|
65
|
-
if (!item) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
return item;
|
|
69
|
-
}
|
|
70
|
-
removeItemFromOrder(itemOrderId) {
|
|
71
|
-
this._order = this._order.filter((item) => item.orderId !== itemOrderId);
|
|
72
|
-
this.respondToUser(`Removed item ${itemOrderId}`);
|
|
73
|
-
}
|
|
74
|
-
modifyItemInOrder(itemOrderId, customizationNames, toppings) {
|
|
75
|
-
const existingIndex = this._order.findIndex((item) => item.orderId === itemOrderId);
|
|
76
|
-
if (existingIndex !== -1) {
|
|
77
|
-
const customizations = customizationNames
|
|
78
|
-
.map((customizationName) => {
|
|
79
|
-
return this.getCustomizationByName(this._order[existingIndex].name, customizationName);
|
|
80
|
-
})
|
|
81
|
-
.filter((customization) => customization !== undefined);
|
|
82
|
-
this._order[existingIndex].customizations = customizations;
|
|
83
|
-
this._order[existingIndex].toppings = toppings;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
throw new Error(`Item with id #"${itemOrderId}" not found in order`);
|
|
87
|
-
}
|
|
88
|
-
this.respondToUser(`Modified item ${itemOrderId}`);
|
|
89
|
-
}
|
|
90
|
-
getOrderTotal() {
|
|
91
|
-
const total = this._order.reduce((total, item) => {
|
|
92
|
-
const customizationTotal = item.customizations.reduce((total, customization) => {
|
|
93
|
-
return total + customization?.priceAdjustment || 0;
|
|
94
|
-
}, 0);
|
|
95
|
-
return total + item.price + customizationTotal;
|
|
96
|
-
}, 0);
|
|
97
|
-
return total;
|
|
98
|
-
}
|
|
99
|
-
completeOrder() {
|
|
100
|
-
this.displayOrder();
|
|
101
|
-
this.respondToUser("Order completed!");
|
|
102
|
-
this._lastOrderIdNumber = 0;
|
|
103
|
-
// clear history
|
|
104
|
-
this._history = [];
|
|
105
|
-
this._isCompleted = true;
|
|
106
|
-
}
|
|
107
|
-
displayItem(item) {
|
|
108
|
-
this.respondToUser(`\t#${item.orderId || ""} ${item.name}...\t\t$${item.price.toFixed(2)}`);
|
|
109
|
-
item.toppings.forEach((topping) => {
|
|
110
|
-
this.respondToUser(`\t\t${topping}`);
|
|
111
|
-
});
|
|
112
|
-
item.customizations.forEach((customization) => {
|
|
113
|
-
this.respondToUser(`\t\t${customization.name}...\t$${customization.priceAdjustment.toFixed(2)}`);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
displayOrder() {
|
|
117
|
-
this.respondToUser("----\n\nDisplaying order:\n\n");
|
|
118
|
-
this._order.forEach((item) => this.displayItem(item));
|
|
119
|
-
this.respondToUser(`--\tTotal:\t\t$${this.getOrderTotal()}`);
|
|
120
|
-
}
|
|
121
|
-
_addMessageToHistory(message) {
|
|
122
|
-
this._history.push(message);
|
|
123
|
-
}
|
|
124
|
-
_getHistory() {
|
|
125
|
-
return this._history;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.OrderingAPI = OrderingAPI;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare const API_VERSION = "1.0.1";
|
|
2
|
-
export interface SalesData {
|
|
3
|
-
sales: number;
|
|
4
|
-
month: number;
|
|
5
|
-
year: number;
|
|
6
|
-
businessUnit: "Advertising" | "Hardware" | "Software";
|
|
7
|
-
}
|
|
8
|
-
export interface APIInterface {
|
|
9
|
-
sendEmail(to: string, subject: string, body: string): Promise<void>;
|
|
10
|
-
getSalesData(): SalesData[];
|
|
11
|
-
print(text: string): void;
|
|
12
|
-
delay(milliseconds: number): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
declare global {
|
|
15
|
-
var api: APIInterface;
|
|
16
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { APIInterface, SalesData } from "./sales_api";
|
|
2
|
-
export declare class API implements APIInterface {
|
|
3
|
-
sendEmail(to: string, subject: string, body: string): Promise<void>;
|
|
4
|
-
getSalesData(): SalesData[];
|
|
5
|
-
print(text: string): void;
|
|
6
|
-
delay(milliseconds: number): Promise<void>;
|
|
7
|
-
}
|