aimyapi 0.2.0 → 1.0.2
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 +72 -310
- package/dist/index.cjs +336 -101
- package/dist/index.d.cts +32 -11
- package/dist/index.d.mts +32 -11
- package/dist/index.d.ts +32 -11
- package/dist/index.js +336 -101
- package/dist/index.mjs +336 -102
- package/example/example1.ts +11 -8
- package/example/example2.ts +31 -20
- package/example/example3.ts +25 -18
- package/example/ordering_api.md +54 -109
- package/example/ordering_api.ts +3 -2
- package/example/ordering_api_impl.ts +2 -1
- package/example/sales_api.md +3 -16
- package/example/sales_api.ts +2 -2
- package/example/sales_api_impl.ts +1 -1
- package/package.json +12 -10
- package/prompts/create-task-prompt.md +19 -21
- package/src/index.ts +329 -126
- package/src/sandbox.ts +119 -26
- package/tsconfig.json +1 -0
package/README.md
CHANGED
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
# AI My API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AIMyAPI is a typescript code sandbox for your LLM using [QuickJS](https://github.com/justjake/quickjs-emscripten). It allows you to expose a global API object and allows your agent to write functions against it without giving it access to the internet or your filesystem except through the methods you define.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Requires an OpenAI compatible API
|
|
6
|
+
|
|
7
|
+
AIMyAPI will handle async operations and timers in your API object.
|
|
8
|
+
|
|
9
|
+
## About version 1.0 rewrite and motivation
|
|
10
|
+
|
|
11
|
+
AIMyAPI was originally written at a time (circa ChatGPT 3.5 / GPT-4) before tool calling existed, before Claude code and codex and just before OpenAI released their code interpreter. LLM models have also gotten drastically better since. Some of the problems it originally aimed to solve are better solved today with simple tool calling. However, there is still a need to safely run small programs in a sandboxed way, reliable way. Tools are good if you have a set interface but there may be times that an agent needs to do some sorting or filtering, or an algorithm or analysis, or some repeatable workflow which isn't implemented by the available tool functions. Writing code allows the agent to do things it might not otherwise be able to do with tools alone.
|
|
12
|
+
|
|
13
|
+
Having the ability to write code allows the tools API surface to be smaller; it could simply be a set of CRUD operations.
|
|
14
|
+
|
|
15
|
+
The other advantage of writing code is privacy and security. When an agent executes code in a sandbox, it doesn't see any of the results*, API keys or other things you may want to keep hidden. When an agent uses tools, it sees all the parameters and results of the tool calls. Code can be audited for security and correctness before running it. Finally, code can encompass a series of operations, whereas tool calls need to be approved one at a time or just trusted often without knowing what will come next.
|
|
16
|
+
|
|
17
|
+
*You'll have the option to hide logs and errors from the agent - logging can allow the agent to fix it's own coding mistakes and test the code, but it also allows information to leave the sandbox which you may want to limit depending on the sensitivity the data your api is handling. Another approach would be to implement a mocked version of your API that the agent can use to write code and debug against while keeping your real data hidden and safe from potentially destructive operations.
|
|
18
|
+
|
|
19
|
+
Version 1.0 updates AIMyAPI code generation to use the tool calling process for writing code. This allows the agent to check the code and run some tests or API calls before committing to a final version. This should result in better code since the previous model relied on the agent always being able to one-shot the code, which depended on it having a complete view of the problem before writing the code which wasn't always realistic. We could also update this process a bit to add "Plan" / "Build" / "Test" phases instead of just one code generation prompt.
|
|
6
20
|
|
|
7
|
-
Uses the OpenAI API and requires an API key.
|
|
8
21
|
|
|
9
22
|
## Quickstart
|
|
10
23
|
|
|
11
24
|
Install the package
|
|
12
25
|
|
|
13
|
-
```
|
|
26
|
+
```bash
|
|
14
27
|
npm i aimyapi --save
|
|
15
28
|
```
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
|
|
30
|
+
**Setup:** create a .env file in the root of your project and add your OpenAI api key:
|
|
31
|
+
```bash
|
|
32
|
+
OPENAI_API_KEY=XXXX
|
|
33
|
+
OPENAI_API_BASE_URL=XXXX // If using your own server, otherwise omit to use the default
|
|
34
|
+
OPENAI_API_MODEL=XXXX // defaults to "gpt-5-mini"
|
|
19
35
|
```
|
|
20
36
|
|
|
37
|
+
|
|
21
38
|
Simply define your strongly-typed typescript API:
|
|
22
39
|
|
|
23
40
|
`sales_api.ts`
|
|
24
|
-
```
|
|
41
|
+
```typescript
|
|
25
42
|
// Sales data for each month, per business unit
|
|
26
43
|
export interface SalesData {
|
|
27
44
|
sales: number;
|
|
@@ -38,15 +55,15 @@ export interface APIInterface {
|
|
|
38
55
|
// Prints the specified text to the user.
|
|
39
56
|
};
|
|
40
57
|
|
|
41
|
-
// Global object you will use for accessing the APIInterface
|
|
58
|
+
// Global object you will use for accessing the APIInterface. Any other globals can go here too if you declare them in the `apiGlobals` parameter.
|
|
42
59
|
declare global {
|
|
43
|
-
|
|
60
|
+
const api: APIInterface;
|
|
44
61
|
}
|
|
45
62
|
|
|
46
63
|
```
|
|
47
64
|
|
|
48
65
|
Implement it (`sales_api_impl.ts`):
|
|
49
|
-
```
|
|
66
|
+
```typescript
|
|
50
67
|
export class API implements APIInterface {
|
|
51
68
|
|
|
52
69
|
getSalesData() {
|
|
@@ -67,7 +84,7 @@ api.print("I'm great, thanks for asking!");
|
|
|
67
84
|
|
|
68
85
|
Instantiate your api and AIMyAPI. AIMyAPI will wrap your API so that it can be called from within the QuickJS sandbox.
|
|
69
86
|
|
|
70
|
-
```
|
|
87
|
+
```typescript
|
|
71
88
|
import { AIMyAPI } from "aimyapi"
|
|
72
89
|
|
|
73
90
|
const api = new API();
|
|
@@ -83,68 +100,31 @@ const aimyapi = await AIMyAPI.createWithAPI({
|
|
|
83
100
|
And now you can make requests against the API in natural language.
|
|
84
101
|
Any code generated by the LLM will be run within the sandbox. The LLM will ONLY have access to functions provided within your API and cannot use javascript to make http requests etc.
|
|
85
102
|
|
|
86
|
-
```
|
|
103
|
+
```typescript
|
|
87
104
|
await aimyapi.processRequest("Which business unit had the highest sales in 2020?");
|
|
88
105
|
```
|
|
89
106
|
|
|
90
107
|
This would produce the following code generated by the LLM prompt, which is run in the sandbox and makes calls on your API object:
|
|
91
108
|
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
maxSales = salesData[i].sales;
|
|
102
|
-
businessUnitWithMaxSales = salesData[i].businessUnit;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
api.print(\`The business unit with the highest sales in 2020 was ${businessUnitWithMaxSales}.\`);
|
|
106
|
-
} catch(e) {
|
|
107
|
-
console.error(e);
|
|
109
|
+
```typescript
|
|
110
|
+
|
|
111
|
+
let salesData = api.getSalesData();
|
|
112
|
+
let maxSales = 0;
|
|
113
|
+
let businessUnitWithMaxSales = "";
|
|
114
|
+
for (let i = 0; i < salesData.length; i++) {
|
|
115
|
+
if (salesData[i].year === 2020 && salesData[i].sales > maxSales) {
|
|
116
|
+
maxSales = salesData[i].sales;
|
|
117
|
+
businessUnitWithMaxSales = salesData[i].businessUnit;
|
|
108
118
|
}
|
|
109
|
-
}
|
|
119
|
+
}
|
|
120
|
+
api.print(\`The business unit with the highest sales in 2020 was ${businessUnitWithMaxSales}.\`);
|
|
121
|
+
|
|
110
122
|
```
|
|
111
123
|
|
|
112
124
|
This example does not take advantage of the chat history and treats every request as a fresh chat. See `example2` for a more complex example that uses the chat history.
|
|
113
125
|
|
|
114
126
|
APIs should be kept simple and understandable. If you have a complicated API you may want to write a simpler facade for it.
|
|
115
127
|
|
|
116
|
-
## Advantages and disadvantages of generating code
|
|
117
|
-
|
|
118
|
-
Currently there is a lot of hype around "agents" - while agents are extremely cool they have a couple drawbacks vs. the code generation approach that AIMyAPI uses to do some of the same things.
|
|
119
|
-
|
|
120
|
-
**Advantages of AIMyAPI over the Agent (haystack) approach:**
|
|
121
|
-
|
|
122
|
-
- Open AI's LLMs today are already really good at writing code, but not necessarily trained on the 'haystack' approach.
|
|
123
|
-
- Data from your API can be kept private as long as you don't add it to the chat history or the prompt. The LLM is writing the operations to manipulate the data but doesn't need to see the data itself to do that.
|
|
124
|
-
- Writing code means that AIMyAPI can do math and algorithms out of the box - something LLMs by themselves struggle at. For instance, asking it to do a simple calculation will result in it writing code to do the calculation. Agents can do this using 'tools', but that means you need to do the work to implement and explain these tools wheras they come built-in in a programming language.
|
|
125
|
-
- Agents typically only do one thing at a time and require several OpenAI API calls to do a single loop. AIMyAPI can write an entire program that does several things in one shot.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
**Disadvantages:**
|
|
129
|
-
|
|
130
|
-
- This is not an iterative approach: AIMyAPI must have a full understanding of the problem and the API in order write code against it. Haystack may be better for problems with unknowns.
|
|
131
|
-
- The LLM can misunderstand your intentions, the api or write incorrect code or reference things that don't exist in the sandbox.
|
|
132
|
-
- It is not currently set up to be able to troubleshoot or fix it's own code (this may be possible though)
|
|
133
|
-
- Limits on the context for OpenAI's LLMs mean you can't have a super big API or lots of docs/examples (maybe GPT4's larger context will make this a non-issue - I don't have access yet).
|
|
134
|
-
- Due to it's training, gpt3.5-turbo tends to want to reply with commentary sometimes, not just code. But examples mostly fix this issue. The `davinci-003` model with the completion api can be prompted to just reply with code, but it's 10x more expensive.
|
|
135
|
-
|
|
136
|
-
## Installation
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
npm install
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**Important:**
|
|
143
|
-
create a .env file in the root of your project
|
|
144
|
-
add your open ai key:
|
|
145
|
-
```
|
|
146
|
-
OPENAI_API_KEY=XXXXXXXX
|
|
147
|
-
```
|
|
148
128
|
|
|
149
129
|
## API Reference for AIMyAPI
|
|
150
130
|
|
|
@@ -152,7 +132,23 @@ OPENAI_API_KEY=XXXXXXXX
|
|
|
152
132
|
|
|
153
133
|
Primary function you will use to create a module for working your API API. For a simple example with no chat history, see example1. For an example with chat history see example2.
|
|
154
134
|
|
|
155
|
-
####
|
|
135
|
+
#### Options:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
export interface AIMyAPIOptions {
|
|
139
|
+
apiObject: object;
|
|
140
|
+
apiExports: object;
|
|
141
|
+
apiWhitelist?: string[];
|
|
142
|
+
apiGlobals?: object;
|
|
143
|
+
apiDefFilePath: string;
|
|
144
|
+
apiGlobalName?: string;
|
|
145
|
+
apiDocsPath?: string;
|
|
146
|
+
debug?: boolean;
|
|
147
|
+
model?: string;
|
|
148
|
+
additionalModelOptions?: object;
|
|
149
|
+
hideLogsFromAgent?: boolean;
|
|
150
|
+
};
|
|
151
|
+
```
|
|
156
152
|
|
|
157
153
|
- `apiObject`: An object representing the API to be used.
|
|
158
154
|
- `apiExports`: An object representing the exported functions and variables from the API.
|
|
@@ -168,253 +164,22 @@ The module created by the `createWithAPI` function:
|
|
|
168
164
|
|
|
169
165
|
#### Methods
|
|
170
166
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
### Example 1 - sales database
|
|
181
|
-
A simple api example where the LLM allows you to ask questions and compute things about a dataset
|
|
182
|
-
```
|
|
183
|
-
npm run example1
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
```
|
|
187
|
-
import { AIMyAPI } from "../lib";
|
|
188
|
-
import { API } from "./sales_api_impl";
|
|
189
|
-
import * as APIExports from "./sales_api";
|
|
190
|
-
import path from "path";
|
|
191
|
-
|
|
192
|
-
// Simpler example using no support for chat history;
|
|
193
|
-
|
|
194
|
-
(async () => {
|
|
195
|
-
const api = new API();
|
|
196
|
-
|
|
197
|
-
const aimyapi = await AIMyAPI.createWithAPI({
|
|
198
|
-
apiObject: api,
|
|
199
|
-
apiGlobalName: "api", // Should match whatever you declared as your global in your api.
|
|
200
|
-
apiExports: APIExports,
|
|
201
|
-
apiDefFilePath: path.join(__dirname, "./sales_api.ts"),
|
|
202
|
-
apiDocsPath: path.join(__dirname, "./sales_api.md"),
|
|
203
|
-
debug: false,
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
console.log("Print 'hello' three times.")
|
|
207
|
-
await aimyapi.processRequest("Print 'hello' three times.");
|
|
208
|
-
|
|
209
|
-
console.log("What was our best month in 2020")
|
|
210
|
-
await aimyapi.processRequest("What was our best month in 2020");
|
|
211
|
-
|
|
212
|
-
console.log("Which business unit had the highest sales in 2020?")
|
|
213
|
-
await aimyapi.processRequest("Which business unit had the highest sales in 2020?");
|
|
214
|
-
|
|
215
|
-
console.log("Compute the total sales for each month in 2020 then email the top 3 to test@email.com")
|
|
216
|
-
await aimyapi.processRequest("Compute the total sales for each month in 2020 then email the top 3 to test@email.com");
|
|
217
|
-
})();
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
Output:
|
|
221
|
-
```
|
|
222
|
-
Print 'hello' three times.
|
|
223
|
-
Generate Task: 4.086s
|
|
224
|
-
hello
|
|
225
|
-
hello
|
|
226
|
-
hello
|
|
227
|
-
Run Code: 379.328ms
|
|
228
|
-
What was our best month in 2020
|
|
229
|
-
Generate Task: 11.345s
|
|
230
|
-
Our best month in 2020 was month 8 with 4400 sales.
|
|
231
|
-
Run Code: 119.145ms
|
|
232
|
-
Which business unit had the highest sales in 2020?
|
|
233
|
-
Generate Task: 11.477s
|
|
234
|
-
The business unit with the highest sales in 2020 was Hardware
|
|
235
|
-
Run Code: 124.522ms
|
|
236
|
-
Compute the total sales for each month in 2020 then email the top 3 to test@email.com
|
|
237
|
-
Generate Task: 15.648s
|
|
238
|
-
Sending email to "test@email.com" with subject "Top 3 Sales Months in 2020" and body
|
|
239
|
-
"Top 3 sales months in 2020:
|
|
240
|
-
Month 8: $4400
|
|
241
|
-
Month 7: $4300
|
|
242
|
-
Month 6: $4000"
|
|
243
|
-
Run Code: 1.200s
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Example 2 - Food ordering bot
|
|
247
|
-
|
|
248
|
-
A more complex food ordering example which incorporates chat history
|
|
249
|
-
|
|
250
|
-
```
|
|
251
|
-
npm run example2
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
Code:
|
|
255
|
-
```
|
|
256
|
-
import { AIMyAPI } from "../lib";
|
|
257
|
-
import { OrderingAPI } from "./ordering_api_impl";
|
|
258
|
-
import * as APIExports from "./ordering_api";
|
|
259
|
-
import path from "path";
|
|
260
|
-
|
|
261
|
-
// More complex fast food ordering example that uses chat history.
|
|
262
|
-
// Fast food ordering example.
|
|
263
|
-
(async () => {
|
|
264
|
-
const api = new OrderingAPI();
|
|
265
|
-
|
|
266
|
-
const aimyapi = await AIMyAPI.createWithAPI({
|
|
267
|
-
apiObject: api,
|
|
268
|
-
apiGlobalName: "orderingApi", // Should match whatever you declared as your global in your ordering api.
|
|
269
|
-
apiExports: APIExports,
|
|
270
|
-
apiDefFilePath: path.join(__dirname, "./ordering_api.ts"),
|
|
271
|
-
apiDocsPath: path.join(__dirname, "./ordering_api.md"),
|
|
272
|
-
debug: false,
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
async function runQuery(query:string) {
|
|
276
|
-
console.log(`Query: ${query}`)
|
|
277
|
-
|
|
278
|
-
// generate the code for this query
|
|
279
|
-
const codeResult = await aimyapi.generateCode(query, api._getHistory());
|
|
280
|
-
|
|
281
|
-
api._addMessageToHistory({
|
|
282
|
-
content: query,
|
|
283
|
-
role: "user",
|
|
284
|
-
name: "user",
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
api._addMessageToHistory({
|
|
288
|
-
content: '```\n' + codeResult.loggableCode + '\n```',
|
|
289
|
-
role: "assistant",
|
|
290
|
-
name: "assistant",
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
// run the code in the sandbox
|
|
294
|
-
await aimyapi.runCode(codeResult.code);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
await runQuery("How's the burger here?");
|
|
298
|
-
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.");
|
|
299
|
-
await runQuery("I changed my mind, instead of anchovies, can I get a large gluten free pizza with pineapple instead.");
|
|
300
|
-
await runQuery("email me the total at myemail@test.com and complete the order");
|
|
301
|
-
|
|
302
|
-
})();
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
Output:
|
|
306
|
-
```
|
|
307
|
-
Query: How's the burger here?
|
|
308
|
-
Our Hamburger is delicious! It comes with cheese, lettuce, tomato, and onion by default, but you can customize it with any of our toppings.
|
|
309
|
-
Query: I'd like a plain hamburger (no cheese) and a large fries, a pizza with anchovies and a cola. I'd also like a cheese burger with bacon and avocado.
|
|
310
|
-
added #0 Hamburger... $8.99
|
|
311
|
-
lettuce
|
|
312
|
-
tomato
|
|
313
|
-
onion
|
|
314
|
-
|
|
315
|
-
Ok, I added a plain hamburger. What else would you like?
|
|
316
|
-
added #1 Fries... $2.99
|
|
317
|
-
Large... $1.99
|
|
318
|
-
|
|
319
|
-
Ok, I added large fries. What else would you like?
|
|
320
|
-
added #2 Pizza... $10.99
|
|
321
|
-
anchovies
|
|
322
|
-
|
|
323
|
-
Ok, I added a pizza with anchovies. What else would you like?
|
|
324
|
-
added #3 Fountain Drink... $1.99
|
|
325
|
-
Large... $0.99
|
|
326
|
-
|
|
327
|
-
Ok, I added a cola. What else would you like?
|
|
328
|
-
added #4 Hamburger... $8.99
|
|
329
|
-
cheese
|
|
330
|
-
lettuce
|
|
331
|
-
tomato
|
|
332
|
-
onion
|
|
333
|
-
cheese
|
|
334
|
-
bacon
|
|
335
|
-
avocado
|
|
336
|
-
|
|
337
|
-
Ok, I added a cheese burger with bacon and avocado. Is there anything else I can help you with?
|
|
338
|
-
Query: I changed my mind, instead of anchovies, can I get a large gluten free pizza with pineapple instead.
|
|
339
|
-
Removed item 2
|
|
340
|
-
added #5 Pizza... $10.99
|
|
341
|
-
pineapple
|
|
342
|
-
Gluten Free Crust... $2.99
|
|
343
|
-
|
|
344
|
-
Ok, I added a large gluten free pizza with pineapple. Is there anything else I can help you with?
|
|
345
|
-
Query: email me the total at myemail@test.com and complete the order
|
|
346
|
-
Sending email to "myemail@test.com" with subject "Order Total" and body
|
|
347
|
-
"Your order total is $39.92."
|
|
348
|
-
----
|
|
349
|
-
|
|
350
|
-
Displaying order:
|
|
351
|
-
#0 Hamburger... $8.99
|
|
352
|
-
lettuce
|
|
353
|
-
tomato
|
|
354
|
-
onion
|
|
355
|
-
|
|
356
|
-
#1 Fries... $2.99
|
|
357
|
-
Large... $1.99
|
|
358
|
-
|
|
359
|
-
#3 Fountain Drink... $1.99
|
|
360
|
-
Large... $0.99
|
|
361
|
-
|
|
362
|
-
#4 Hamburger... $8.99
|
|
363
|
-
cheese
|
|
364
|
-
lettuce
|
|
365
|
-
tomato
|
|
366
|
-
onion
|
|
367
|
-
cheese
|
|
368
|
-
bacon
|
|
369
|
-
avocado
|
|
370
|
-
|
|
371
|
-
#5 Pizza... $10.99
|
|
372
|
-
pineapple
|
|
373
|
-
Gluten Free Crust... $2.99
|
|
374
|
-
|
|
375
|
-
-- Total: $39.92
|
|
376
|
-
Order completed!
|
|
377
|
-
Your order has been completed. Thank you for choosing our restaurant!
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
# Example 3 - interactive food ordering
|
|
381
|
-
|
|
382
|
-
Interactive ordering example (same api as example2). You can type your own orders on the command line.
|
|
383
|
-
|
|
384
|
-
```
|
|
385
|
-
npm run example3
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
## Providing examples
|
|
389
|
-
|
|
390
|
-
Providing examples is super important.
|
|
391
|
-
We recommend that you instruct the LLM to return a self executing async function enclosed in \`\`\` with no other commentary. See the `example/ordering_api.md` for reference.
|
|
392
|
-
It's recommended that you provide at least one example and no other commentary from the assistant, otherwise the LLM's responses will vary pretty widely and probably be unusable.
|
|
393
|
-
GPT3.5-turbo also has tendency to respond in words even after being instructed to respond only with code. Examples help alleviate this problem.
|
|
394
|
-
|
|
395
|
-
**Sample example**:
|
|
396
|
-
|
|
397
|
-
```
|
|
398
|
-
Examples of how you should respond:
|
|
399
|
-
|
|
400
|
-
user: How are you today?
|
|
401
|
-
|
|
402
|
-
assistant:
|
|
403
|
-
\`\`\`
|
|
404
|
-
api.print("I'm great, thanks for asking!");
|
|
405
|
-
\`\`\`
|
|
406
|
-
|
|
167
|
+
```typescript
|
|
168
|
+
export interface AIMyAPIInstance {
|
|
169
|
+
options:AIMyAPIOptions;
|
|
170
|
+
generateCode: (queryText:string, userChatHistory:ChatCompletionMessageParam[]) => Promise<GenerateCodeResult | null>;
|
|
171
|
+
runCode: (code:string) => Promise<CodeRunResult>;
|
|
172
|
+
checkCode: (code:string) => Promise<CodeRunResult>;
|
|
173
|
+
// run a single request with no history
|
|
174
|
+
processRequest: (userQuery:string, context?: object) => Promise<GenerateCodeResult | null>;
|
|
175
|
+
}
|
|
407
176
|
```
|
|
408
177
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
If you plan to use history, it is vital that you include the generated code in the history. Otherwise, the LLM will start to think that it doesn't need to generate code. Logging is also necessary for keeping track of Id's from past requests so that future requests can leverage that information.
|
|
414
|
-
|
|
415
|
-
See example2 for more an example on how to do this.
|
|
178
|
+
- `generateCode()`: A function that generates code to be run in the sandbox for the given query text and user chat history.
|
|
179
|
+
- `runCode()`: A function that runs the generated code in the sandbox.
|
|
180
|
+
- `checkCode()`: Typecheck / compile the code
|
|
181
|
+
- `processRequest()`: A single function that generates and runs code assuming no chat history.
|
|
416
182
|
|
|
417
|
-
TODO: Add more details explaining how this is done.
|
|
418
183
|
|
|
419
184
|
## Safety notes:
|
|
420
185
|
|
|
@@ -428,9 +193,6 @@ TODO: Add more details explaining how this is done.
|
|
|
428
193
|
- A way to audit and rollback anything the LLM does would be wise. The LLM can misunderstand requests due to false assumptions or incomplete information (or trickery). If you allow it to modify your data it could mess things up.
|
|
429
194
|
- By using this library you acknowledge that you take full responsibility for anything that happens as a result of it's use. We cannot gaurantee what will happen based on your instructions to the LLM or how the LLM interprets them etc.
|
|
430
195
|
|
|
431
|
-
## Thoughts:
|
|
432
196
|
|
|
433
|
-
Could fine tuning on our API and examples allow us to make the prompt smaller? We can only fine tune on the base models though, so we can't use the cheaper gpt3.5-turbo model.
|
|
434
|
-
Could a smaller / more efficient LLM focused on coding tasks work for this usecase?
|
|
435
197
|
|
|
436
198
|
|