aimyapi 0.1.13 → 0.1.14

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.
@@ -1,18 +1,18 @@
1
1
  require('dotenv').config()
2
2
  import fs from 'fs';
3
- import { ChatCompletionRequestMessage, Configuration, OpenAIApi } from "openai";
3
+ import { OpenAI } from "openai";
4
4
  import path from 'path';
5
5
 
6
6
  import createSandbox from "./sandbox";
7
7
  import { rejectOpenPromises } from './sandbox-wrappers';
8
8
 
9
+ import { ChatCompletionMessageParam } from 'openai/resources/index.mjs';
9
10
  import { QuickJSWASMModule, getQuickJS } from "quickjs-emscripten";
10
11
 
11
- const configuration = new Configuration({
12
- apiKey: process.env.OPENAI_API_KEY,
12
+ const openai = new OpenAI({
13
+ apiKey: process.env.OPENAI_API_KEY // This is also the default, can be omitted
13
14
  });
14
15
 
15
- const openai = new OpenAIApi(configuration);
16
16
 
17
17
  // function formatObject(obj: any): string {
18
18
  // return Object.keys(obj).reduce((acc, key) => {
@@ -38,13 +38,13 @@ export interface GenerateCodeResult {
38
38
  }
39
39
 
40
40
  // FIXME: add an options parameter and allow specifying the token limit
41
- export const generateCode = async function(queryText:string, userChatHistory:ChatCompletionRequestMessage[], createTaskPrompt:string, apiPath:string, debug:boolean = false, model="gpt-4o"): Promise<GenerateCodeResult> {
41
+ export const generateCode = async function(queryText:string, userChatHistory:ChatCompletionMessageParam[], createTaskPrompt:string, apiPath:string, debug:boolean = false, model="gpt-4o"): Promise<GenerateCodeResult> {
42
42
  if(!queryText)
43
43
  return { code: '', loggableCode: '' };
44
44
 
45
45
  let generatedCode = '';
46
46
  const prompt = createTaskPrompt.replace("{{QUERY_TEXT}}", queryText);
47
- const messages:ChatCompletionRequestMessage[] = [
47
+ const messages:ChatCompletionMessageParam[] = [
48
48
  {
49
49
  role: "system",
50
50
  content: prompt,
@@ -57,18 +57,18 @@ export const generateCode = async function(queryText:string, userChatHistory:Cha
57
57
  }
58
58
  ];
59
59
  try {
60
- const results = await openai.createChatCompletion({
60
+ const results = await openai.chat.completions.create({
61
61
  model,
62
62
  messages: messages,
63
- temperature: 0.1,
63
+ temperature: 0.0,
64
64
  max_tokens: 700,
65
65
  }
66
66
  );
67
67
 
68
68
  if(debug)
69
- console.log(results.data.usage);
69
+ console.log(results.usage);
70
70
 
71
- const response = results.data.choices[0].message.content;
71
+ const response = results.choices[0].message.content;
72
72
 
73
73
  if(debug)
74
74
  console.log(response);
@@ -110,7 +110,7 @@ export interface AIMyAPIOptions {
110
110
  export interface AIMyAPIInstance {
111
111
  // see xample 2
112
112
  options:AIMyAPIOptions;
113
- generateCode: (queryText:string, userChatHistory:ChatCompletionRequestMessage[]) => Promise<GenerateCodeResult>;
113
+ generateCode: (queryText:string, userChatHistory:ChatCompletionMessageParam[]) => Promise<GenerateCodeResult>;
114
114
  runCode: (task:string) => Promise<void>;
115
115
  // run a single request with no history
116
116
  processRequest: (userQuery:string, context?: object) => Promise<GenerateCodeResult>;
@@ -138,7 +138,7 @@ async function createWithAPI(options:AIMyAPIOptions): Promise<AIMyAPIInstance> {
138
138
 
139
139
  return {
140
140
  options,
141
- generateCode: async function(queryText:string, userChatHistory:ChatCompletionRequestMessage[], currentContext:any = undefined) {
141
+ generateCode: async function(queryText:string, userChatHistory:ChatCompletionMessageParam[], currentContext:any = undefined) {
142
142
  if(!queryText)
143
143
  return { code: '', loggableCode: '' };
144
144
 
@@ -228,11 +228,11 @@ export interface AIMyAPIModuleExports {
228
228
  createWithAPI: (options:AIMyAPIOptions) => Promise<AIMyAPIInstance>;
229
229
 
230
230
  createBasePrompt: (apiFilePath:string, documentationPath: string) => string;
231
- generateCode: (queryText:string, userChatHistory:ChatCompletionRequestMessage[], createTaskPrompt:string, apiPath:string, debug:boolean) => Promise<GenerateCodeResult>;
231
+ generateCode: (queryText:string, userChatHistory:ChatCompletionMessageParam[], createTaskPrompt:string, apiPath:string, debug:boolean) => Promise<GenerateCodeResult>;
232
232
  createSandbox: (QuickJS:QuickJSWASMModule, globals: any) => Promise<any>;
233
233
  }
234
234
 
235
- const aimyapi:AIMyAPIModuleExports = {
235
+ export const aimyapi:AIMyAPIModuleExports = {
236
236
  // Standard way of using the library
237
237
  createWithAPI,
238
238
 
@@ -240,6 +240,4 @@ const aimyapi:AIMyAPIModuleExports = {
240
240
  createBasePrompt,
241
241
  generateCode,
242
242
  createSandbox,
243
- }
244
-
245
- export default aimyapi;
243
+ }
package/tsconfig.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "module": "nodenext" /* Some imports are really imports: https://www.typescriptlang.org/docs/handbook/esm-node.html */,
5
5
  "moduleResolution": "nodenext" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
6
6
  "lib": ["ES2021", "dom"] /* Specify library files to be included in the compilation. */,
7
- "outDir": "dist" /* Redirect output structure to the directory. */,
7
+ "outDir": "./dist" /* Redirect output structure to the directory. */,
8
8
  "declaration": true
9
9
  },
10
- "include": ["**/lib/*.ts"],
10
+ "include": ["**/src/*.ts"],
11
11
  "exclude": ["**/node_modules, **/dist"]
12
12
  }
File without changes
File without changes
File without changes