aimyapi 0.1.0 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +47 -12
  2. package/lib/index.ts +2 -2
  3. 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
- sendEmail(to: string, subject: string, body: string): Promise<void> {
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,24 +111,55 @@ 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
- - It is not currently set up to be able to troubleshoot or fix it's own code (this may be possible)
112
- - Limits on the context for OpenAI's LLMs mean you can't have a super big API (maybe GPT4 will make this a non-issue).
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
- ## installation
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
  ```
123
130
  OPENAI_API_KEY=XXXXXXXX
124
131
  ```
125
132
 
133
+ ## API Reference for AIMyAPI
134
+
135
+ ### createWithAPI(options: AIMyAPIOptions): Promise<CreateWithAPIExports>
136
+
137
+ 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.
138
+
139
+ #### options
140
+
141
+ - `apiObject`: An object representing the API to be used.
142
+ - `apiExports`: An object representing the exported functions and variables from the API.
143
+ - `apiGlobals` (optional): An object representing global variables for the API.
144
+ - `apiDefFilePath`: A string representing the full path to the API definition file.
145
+ - `apiGlobalName` (optional): A string representing the name of the global variable for the API.
146
+ - `apiDocsPath` (optional): A string representing the path to the documentation for the API.
147
+ - `debug` (optional): A boolean indicating whether to output debugging information.
148
+
149
+ ### The AIMyAPI module (type: CreateWithAPIExports)
150
+
151
+ The module created by the `createWithAPI` function:
152
+
153
+ #### Methods
154
+
155
+ - `generateCode(queryText: string, userChatHistory: ChatCompletionRequestMessage[]): Promise<string>`: A function that generates code for the given query text and user chat history.
156
+ - `runCode(task: string): Promise<void>`: A function that runs the generated code.
157
+ - `processRequest(userQuery: string, context?: object): Promise<string>`: A function that processes a user request.
158
+
126
159
  ## Examples
127
160
 
161
+ Download or clone the repo. From the root folder run the following.
162
+
128
163
  A simple api example where the LLM allows you to ask questions and compute things about a dataset
129
164
  ```
130
165
  npm run example1
package/lib/index.ts CHANGED
@@ -230,7 +230,7 @@ export interface AIMyAPIExports {
230
230
  createWithAPI: (options:AIMyAPIOptions) => Promise<CreateWithAPIExports>;
231
231
 
232
232
  createBasePrompt: (apiFilePath:string, documentationPath: string) => string;
233
- generateTask: (queryText:string, userChatHistory:any[], createTaskPrompt:string, apiPath:string) => Promise<string>;
233
+ generateCode: (queryText:string, userChatHistory:ChatCompletionRequestMessage[], createTaskPrompt:string, apiPath:string, debug:boolean) => Promise<string>;
234
234
  createSandbox: (QuickJS:QuickJSWASMModule, globals: any) => Promise<any>;
235
235
  }
236
236
 
@@ -240,7 +240,7 @@ const aimyapi:AIMyAPIExports = {
240
240
 
241
241
  // functions for customized usage
242
242
  createBasePrompt,
243
- generateTask: generateCode,
243
+ generateCode,
244
244
  createSandbox,
245
245
  }
246
246
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aimyapi",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "AI My API! Use LLMs to create small programs that safely* run and make calls against your API.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",