aimyapi 0.1.0 → 0.1.1
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 +21 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,9 +4,16 @@ Build AI assistants that use your API's and respond to natural language queries
|
|
|
4
4
|
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 -
|
|
5
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.
|
|
6
6
|
|
|
7
|
-
Uses the OpenAI API and requires an API key.
|
|
7
|
+
Uses the OpenAI API and requires an API key.
|
|
8
8
|
|
|
9
9
|
## Quickstart
|
|
10
|
+
|
|
11
|
+
Install the package
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm i aimyapi --save
|
|
15
|
+
```
|
|
16
|
+
|
|
10
17
|
Simply define your strongly-typed typescript API:
|
|
11
18
|
|
|
12
19
|
`sales_api.ts`
|
|
@@ -20,16 +27,11 @@ export interface SalesData {
|
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
export interface APIInterface {
|
|
23
|
-
sendEmail(to: string, subject: string, body: string): Promise<void>;
|
|
24
|
-
|
|
25
30
|
getSalesData(): SalesData[];
|
|
26
31
|
// Returns an array of sales data.
|
|
27
32
|
|
|
28
33
|
print(text: string): void;
|
|
29
34
|
// Prints the specified text to the user.
|
|
30
|
-
|
|
31
|
-
delay(milliseconds: number): Promise<void>;
|
|
32
|
-
// waits for the specified number of milliseconds before resolving the promise.
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
// Global object you will use for accessing the APIInterface
|
|
@@ -43,13 +45,15 @@ Implement it:
|
|
|
43
45
|
```
|
|
44
46
|
export class API implements APIInterface {
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
getSalesData() {
|
|
47
49
|
...
|
|
48
50
|
```
|
|
49
51
|
|
|
50
52
|
Instantiate your api and AIMyAPI. AIMyAPI will wrap your API so that it can be called from within the QuickJS sandbox.
|
|
51
53
|
|
|
52
54
|
```
|
|
55
|
+
import AIMyAPI from "aimyapi"
|
|
56
|
+
|
|
53
57
|
const api = new API();
|
|
54
58
|
|
|
55
59
|
const aimyapi = await AIMyAPI.createWithAPI({
|
|
@@ -91,7 +95,7 @@ import * as ApiDefs from './api.ts'
|
|
|
91
95
|
|
|
92
96
|
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.
|
|
93
97
|
|
|
94
|
-
APIs should be kept simple and understandable. If you have a complicated API you may want to write a facade for it.
|
|
98
|
+
APIs should be kept simple and understandable. If you have a complicated API you may want to write a simpler facade for it.
|
|
95
99
|
|
|
96
100
|
## Advantages and disadvantages of generating code
|
|
97
101
|
|
|
@@ -107,16 +111,19 @@ Currently there is a lot of hype around "agents" - while agents are extremely co
|
|
|
107
111
|
|
|
108
112
|
**Disadvantages:**
|
|
109
113
|
|
|
110
|
-
- This is not an iterative approach: AIMyAPI must have a full understanding of the problem and the API in order write code against it.
|
|
111
|
-
-
|
|
112
|
-
-
|
|
114
|
+
- 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.
|
|
115
|
+
- The LLM can misunderstand your intentions, the api or write incorrect code or reference things that don't exist in the sandbox.
|
|
116
|
+
- It is not currently set up to be able to troubleshoot or fix it's own code (this may be possible though)
|
|
117
|
+
- 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).
|
|
118
|
+
- 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.
|
|
113
119
|
|
|
114
|
-
##
|
|
120
|
+
## Installation
|
|
115
121
|
|
|
116
122
|
```
|
|
117
123
|
npm install
|
|
118
124
|
```
|
|
119
125
|
|
|
126
|
+
**Important:**
|
|
120
127
|
create a .env file in the root of your project
|
|
121
128
|
add your open ai key:
|
|
122
129
|
```
|
|
@@ -125,6 +132,8 @@ OPENAI_API_KEY=XXXXXXXX
|
|
|
125
132
|
|
|
126
133
|
## Examples
|
|
127
134
|
|
|
135
|
+
Download or clone the repo. From the root folder run the following.
|
|
136
|
+
|
|
128
137
|
A simple api example where the LLM allows you to ask questions and compute things about a dataset
|
|
129
138
|
```
|
|
130
139
|
npm run example1
|