aimyapi 0.1.10 → 0.1.11

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/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare function createBasePrompt(apiFilePath: string, documentationPath:
4
4
  export interface GenerateCodeResult {
5
5
  code: string;
6
6
  loggableCode: string;
7
+ rawResponse?: string;
7
8
  }
8
9
  export declare const generateCode: (queryText: string, userChatHistory: ChatCompletionRequestMessage[], createTaskPrompt: string, apiPath: string, debug?: boolean) => Promise<GenerateCodeResult>;
9
10
  export interface AIMyAPIOptions {
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ exports.createBasePrompt = createBasePrompt;
32
32
  // FIXME: add an options parameter and allow specifying the token limit
33
33
  const generateCode = async function (queryText, userChatHistory, createTaskPrompt, apiPath, debug = false) {
34
34
  if (!queryText)
35
- return;
35
+ return { code: '', loggableCode: '' };
36
36
  let generatedCode = '';
37
37
  const prompt = createTaskPrompt.replace("{{QUERY_TEXT}}", queryText);
38
38
  const messages = [
@@ -43,7 +43,7 @@ const generateCode = async function (queryText, userChatHistory, createTaskPromp
43
43
  ...userChatHistory,
44
44
  {
45
45
  role: "user",
46
- content: `${queryText}`,
46
+ content: `${queryText}.\nRespond only with code enclosed in \`\`\`.`,
47
47
  name: "user"
48
48
  }
49
49
  ];
@@ -64,16 +64,15 @@ const generateCode = async function (queryText, userChatHistory, createTaskPromp
64
64
  const codeEnd = response.lastIndexOf('```');
65
65
  // error, no code detected inside the response
66
66
  if (codeStart === -1 || codeEnd === -1 || codeStart === codeEnd) {
67
- return { code: '', loggableCode: '' };
67
+ return { code: '', loggableCode: '', rawResponse: response };
68
68
  }
69
69
  generatedCode = response.substring(codeStart + 3, codeEnd).replace('typescript', '');
70
- const codeHeader = `// Query: ${queryText}\nimport * as ApiDefs from '${apiPath}'\n(async() {\n\ttry {`;
70
+ const codeHeader = `import * as ApiDefs from '${apiPath}'\n(async() {\n\ttry {`;
71
71
  const codeFooter = `\n\t} catch(err) {\n\t\tconsole.error(err);\n\t}\n})();`;
72
72
  return { code: codeHeader + generatedCode + codeFooter, loggableCode: generatedCode };
73
73
  }
74
74
  catch (err) {
75
75
  console.error(err);
76
- console.log("Prompt", messages);
77
76
  return { code: '', loggableCode: '' };
78
77
  }
79
78
  };
package/lib/index.ts CHANGED
@@ -34,12 +34,13 @@ export function createBasePrompt(apiFilePath:string, documentationPath: string):
34
34
  export interface GenerateCodeResult {
35
35
  code: string;
36
36
  loggableCode: string;
37
+ rawResponse?: string;
37
38
  }
38
39
 
39
40
  // FIXME: add an options parameter and allow specifying the token limit
40
41
  export const generateCode = async function(queryText:string, userChatHistory:ChatCompletionRequestMessage[], createTaskPrompt:string, apiPath:string, debug:boolean = false): Promise<GenerateCodeResult> {
41
42
  if(!queryText)
42
- return;
43
+ return { code: '', loggableCode: '' };
43
44
 
44
45
  let generatedCode = '';
45
46
  const prompt = createTaskPrompt.replace("{{QUERY_TEXT}}", queryText);
@@ -51,7 +52,7 @@ export const generateCode = async function(queryText:string, userChatHistory:Cha
51
52
  ...userChatHistory,
52
53
  {
53
54
  role: "user",
54
- content: `${queryText}`,
55
+ content: `${queryText}.\nRespond only with code enclosed in \`\`\`.`,
55
56
  name: "user"
56
57
  }
57
58
  ];
@@ -78,17 +79,16 @@ export const generateCode = async function(queryText:string, userChatHistory:Cha
78
79
 
79
80
  // error, no code detected inside the response
80
81
  if(codeStart === -1 || codeEnd === -1 || codeStart === codeEnd) {
81
- return { code: '', loggableCode: '' };
82
+ return { code: '', loggableCode: '', rawResponse: response };
82
83
  }
83
84
 
84
85
  generatedCode = response.substring(codeStart + 3, codeEnd).replace('typescript', '');
85
86
 
86
- const codeHeader = `// Query: ${queryText}\nimport * as ApiDefs from '${apiPath}'\n(async() {\n\ttry {`;
87
+ const codeHeader = `import * as ApiDefs from '${apiPath}'\n(async() {\n\ttry {`;
87
88
  const codeFooter = `\n\t} catch(err) {\n\t\tconsole.error(err);\n\t}\n})();`;
88
89
  return { code: codeHeader + generatedCode + codeFooter, loggableCode: generatedCode };
89
90
  } catch(err) {
90
91
  console.error(err);
91
- console.log("Prompt", messages);
92
92
  return { code: '', loggableCode: '' };
93
93
  }
94
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aimyapi",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "AI My API! Use LLMs to create small programs that safely* run and make calls against your API. Similar to ChatGPT's Code Interpreter.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",