okai 0.0.2 → 0.0.5
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.js +236 -11150
 - package/dist/info.js +59 -0
 - package/dist/okai.js +4 -0
 - package/dist/openai.js +97 -0
 - package/dist/types.js +1 -0
 - package/dist/utils.js +32 -0
 - package/package.json +3 -3
 - package/dist/index.d.ts +0 -3
 
    
        package/dist/info.js
    ADDED
    
    | 
         @@ -0,0 +1,59 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import fs from "fs";
         
     | 
| 
      
 2 
     | 
    
         
            +
            import path from "path";
         
     | 
| 
      
 3 
     | 
    
         
            +
            export function projectInfo(cwd) {
         
     | 
| 
      
 4 
     | 
    
         
            +
                const config = fs.existsSync(path.join(cwd, "okai.json"))
         
     | 
| 
      
 5 
     | 
    
         
            +
                    ? JSON.parse(fs.readFileSync(path.join(cwd, "okai.json")).toString())
         
     | 
| 
      
 6 
     | 
    
         
            +
                    : null;
         
     | 
| 
      
 7 
     | 
    
         
            +
                const parentDir = path.dirname(cwd);
         
     | 
| 
      
 8 
     | 
    
         
            +
                let slnDir = '';
         
     | 
| 
      
 9 
     | 
    
         
            +
                let sln = fs.readdirSync(cwd).find(f => f.endsWith(".sln"));
         
     | 
| 
      
 10 
     | 
    
         
            +
                if (sln) {
         
     | 
| 
      
 11 
     | 
    
         
            +
                    slnDir = cwd;
         
     | 
| 
      
 12 
     | 
    
         
            +
                }
         
     | 
| 
      
 13 
     | 
    
         
            +
                else {
         
     | 
| 
      
 14 
     | 
    
         
            +
                    sln = fs.readdirSync(parentDir).find(f => f.endsWith(".sln"));
         
     | 
| 
      
 15 
     | 
    
         
            +
                    if (sln) {
         
     | 
| 
      
 16 
     | 
    
         
            +
                        slnDir = parentDir;
         
     | 
| 
      
 17 
     | 
    
         
            +
                    }
         
     | 
| 
      
 18 
     | 
    
         
            +
                }
         
     | 
| 
      
 19 
     | 
    
         
            +
                if (!sln) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                    if (config)
         
     | 
| 
      
 21 
     | 
    
         
            +
                        return config;
         
     | 
| 
      
 22 
     | 
    
         
            +
                    throw new Error("No .sln file found");
         
     | 
| 
      
 23 
     | 
    
         
            +
                }
         
     | 
| 
      
 24 
     | 
    
         
            +
                const projectName = sln.substring(0, sln.length - 4);
         
     | 
| 
      
 25 
     | 
    
         
            +
                function getDir(slnDir, match) {
         
     | 
| 
      
 26 
     | 
    
         
            +
                    if (fs.readdirSync(slnDir).find(match))
         
     | 
| 
      
 27 
     | 
    
         
            +
                        return slnDir;
         
     | 
| 
      
 28 
     | 
    
         
            +
                    const dirs = fs.readdirSync(slnDir).filter(f => fs.statSync(path.join(slnDir, f)).isDirectory());
         
     | 
| 
      
 29 
     | 
    
         
            +
                    for (let dir of dirs) {
         
     | 
| 
      
 30 
     | 
    
         
            +
                        const hasFile = fs.readdirSync(path.join(slnDir, dir)).find(match);
         
     | 
| 
      
 31 
     | 
    
         
            +
                        if (hasFile)
         
     | 
| 
      
 32 
     | 
    
         
            +
                            return path.join(slnDir, dir);
         
     | 
| 
      
 33 
     | 
    
         
            +
                    }
         
     | 
| 
      
 34 
     | 
    
         
            +
                    return null;
         
     | 
| 
      
 35 
     | 
    
         
            +
                }
         
     | 
| 
      
 36 
     | 
    
         
            +
                const hostDir = getDir(slnDir, f => f === `${projectName}.csproj`);
         
     | 
| 
      
 37 
     | 
    
         
            +
                const serviceModelDirName = fs.readdirSync(slnDir).find(f => f.endsWith("ServiceModel"));
         
     | 
| 
      
 38 
     | 
    
         
            +
                const serviceModelDir = serviceModelDirName
         
     | 
| 
      
 39 
     | 
    
         
            +
                    ? path.join(slnDir, serviceModelDirName)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    : null;
         
     | 
| 
      
 41 
     | 
    
         
            +
                const serviceInterfaceDirName = fs.readdirSync(slnDir).find(f => f.endsWith("ServiceInterface"));
         
     | 
| 
      
 42 
     | 
    
         
            +
                const serviceInterfaceDir = serviceInterfaceDirName
         
     | 
| 
      
 43 
     | 
    
         
            +
                    ? path.join(slnDir, serviceInterfaceDirName)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    : null;
         
     | 
| 
      
 45 
     | 
    
         
            +
                const migrationsDir = hostDir && fs.readdirSync(hostDir).find(f => f === "Migrations")
         
     | 
| 
      
 46 
     | 
    
         
            +
                    ? path.join(hostDir, "Migrations")
         
     | 
| 
      
 47 
     | 
    
         
            +
                    : null;
         
     | 
| 
      
 48 
     | 
    
         
            +
                const info = {
         
     | 
| 
      
 49 
     | 
    
         
            +
                    projectName,
         
     | 
| 
      
 50 
     | 
    
         
            +
                    slnDir,
         
     | 
| 
      
 51 
     | 
    
         
            +
                    hostDir,
         
     | 
| 
      
 52 
     | 
    
         
            +
                    migrationsDir,
         
     | 
| 
      
 53 
     | 
    
         
            +
                    serviceModelDir,
         
     | 
| 
      
 54 
     | 
    
         
            +
                    serviceInterfaceDir,
         
     | 
| 
      
 55 
     | 
    
         
            +
                };
         
     | 
| 
      
 56 
     | 
    
         
            +
                return config
         
     | 
| 
      
 57 
     | 
    
         
            +
                    ? Object.assign({}, info, config)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    : info;
         
     | 
| 
      
 59 
     | 
    
         
            +
            }
         
     | 
    
        package/dist/okai.js
    ADDED
    
    
    
        package/dist/openai.js
    ADDED
    
    | 
         @@ -0,0 +1,97 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            /* Options:
         
     | 
| 
      
 2 
     | 
    
         
            +
            Date: 2024-11-29 17:33:02
         
     | 
| 
      
 3 
     | 
    
         
            +
            Version: 8.53
         
     | 
| 
      
 4 
     | 
    
         
            +
            Tip: To override a DTO option, remove "//" prefix before updating
         
     | 
| 
      
 5 
     | 
    
         
            +
            BaseUrl: https://openai.servicestack.net
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            //GlobalNamespace:
         
     | 
| 
      
 8 
     | 
    
         
            +
            //MakePropertiesOptional: False
         
     | 
| 
      
 9 
     | 
    
         
            +
            //AddServiceStackTypes: True
         
     | 
| 
      
 10 
     | 
    
         
            +
            //AddResponseStatus: False
         
     | 
| 
      
 11 
     | 
    
         
            +
            //AddImplicitVersion:
         
     | 
| 
      
 12 
     | 
    
         
            +
            //AddDescriptionAsComments: True
         
     | 
| 
      
 13 
     | 
    
         
            +
            IncludeTypes: OpenAiChatCompletion.*
         
     | 
| 
      
 14 
     | 
    
         
            +
            //ExcludeTypes:
         
     | 
| 
      
 15 
     | 
    
         
            +
            //DefaultImports:
         
     | 
| 
      
 16 
     | 
    
         
            +
            */
         
     | 
| 
      
 17 
     | 
    
         
            +
            /** @description The tool calls generated by the model, such as function calls. */
         
     | 
| 
      
 18 
     | 
    
         
            +
            // @Api(Description="The tool calls generated by the model, such as function calls.")
         
     | 
| 
      
 19 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 20 
     | 
    
         
            +
            export class ToolCall {
         
     | 
| 
      
 21 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 22 
     | 
    
         
            +
            }
         
     | 
| 
      
 23 
     | 
    
         
            +
            /** @description A list of messages comprising the conversation so far. */
         
     | 
| 
      
 24 
     | 
    
         
            +
            // @Api(Description="A list of messages comprising the conversation so far.")
         
     | 
| 
      
 25 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 26 
     | 
    
         
            +
            export class OpenAiMessage {
         
     | 
| 
      
 27 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 28 
     | 
    
         
            +
            }
         
     | 
| 
      
 29 
     | 
    
         
            +
            export var ResponseFormat;
         
     | 
| 
      
 30 
     | 
    
         
            +
            (function (ResponseFormat) {
         
     | 
| 
      
 31 
     | 
    
         
            +
                ResponseFormat["Text"] = "text";
         
     | 
| 
      
 32 
     | 
    
         
            +
                ResponseFormat["JsonObject"] = "json_object";
         
     | 
| 
      
 33 
     | 
    
         
            +
            })(ResponseFormat || (ResponseFormat = {}));
         
     | 
| 
      
 34 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 35 
     | 
    
         
            +
            export class OpenAiResponseFormat {
         
     | 
| 
      
 36 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 37 
     | 
    
         
            +
            }
         
     | 
| 
      
 38 
     | 
    
         
            +
            export var OpenAiToolType;
         
     | 
| 
      
 39 
     | 
    
         
            +
            (function (OpenAiToolType) {
         
     | 
| 
      
 40 
     | 
    
         
            +
                OpenAiToolType["Function"] = "function";
         
     | 
| 
      
 41 
     | 
    
         
            +
            })(OpenAiToolType || (OpenAiToolType = {}));
         
     | 
| 
      
 42 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 43 
     | 
    
         
            +
            export class OpenAiTools {
         
     | 
| 
      
 44 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 45 
     | 
    
         
            +
            }
         
     | 
| 
      
 46 
     | 
    
         
            +
            /** @description Given a list of messages comprising a conversation, the model will return a response. */
         
     | 
| 
      
 47 
     | 
    
         
            +
            // @Api(Description="Given a list of messages comprising a conversation, the model will return a response.")
         
     | 
| 
      
 48 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 49 
     | 
    
         
            +
            export class OpenAiChat {
         
     | 
| 
      
 50 
     | 
    
         
            +
                constructor(init) {
         
     | 
| 
      
 51 
     | 
    
         
            +
                    /** @description A list of messages comprising the conversation so far. */
         
     | 
| 
      
 52 
     | 
    
         
            +
                    // @DataMember(Name="messages")
         
     | 
| 
      
 53 
     | 
    
         
            +
                    // @ApiMember(Description="A list of messages comprising the conversation so far.")
         
     | 
| 
      
 54 
     | 
    
         
            +
                    this.messages = [];
         
     | 
| 
      
 55 
     | 
    
         
            +
                    Object.assign(this, init);
         
     | 
| 
      
 56 
     | 
    
         
            +
                }
         
     | 
| 
      
 57 
     | 
    
         
            +
            }
         
     | 
| 
      
 58 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 59 
     | 
    
         
            +
            export class ResponseError {
         
     | 
| 
      
 60 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 61 
     | 
    
         
            +
            }
         
     | 
| 
      
 62 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 63 
     | 
    
         
            +
            export class ResponseStatus {
         
     | 
| 
      
 64 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 65 
     | 
    
         
            +
            }
         
     | 
| 
      
 66 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 67 
     | 
    
         
            +
            export class ChoiceMessage {
         
     | 
| 
      
 68 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 69 
     | 
    
         
            +
            }
         
     | 
| 
      
 70 
     | 
    
         
            +
            export class Choice {
         
     | 
| 
      
 71 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 72 
     | 
    
         
            +
            }
         
     | 
| 
      
 73 
     | 
    
         
            +
            /** @description Usage statistics for the completion request. */
         
     | 
| 
      
 74 
     | 
    
         
            +
            // @Api(Description="Usage statistics for the completion request.")
         
     | 
| 
      
 75 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 76 
     | 
    
         
            +
            export class OpenAiUsage {
         
     | 
| 
      
 77 
     | 
    
         
            +
                constructor(init) { Object.assign(this, init); }
         
     | 
| 
      
 78 
     | 
    
         
            +
            }
         
     | 
| 
      
 79 
     | 
    
         
            +
            // @DataContract
         
     | 
| 
      
 80 
     | 
    
         
            +
            export class OpenAiChatResponse {
         
     | 
| 
      
 81 
     | 
    
         
            +
                constructor(init) {
         
     | 
| 
      
 82 
     | 
    
         
            +
                    /** @description A list of chat completion choices. Can be more than one if n is greater than 1. */
         
     | 
| 
      
 83 
     | 
    
         
            +
                    // @DataMember(Name="choices")
         
     | 
| 
      
 84 
     | 
    
         
            +
                    // @ApiMember(Description="A list of chat completion choices. Can be more than one if n is greater than 1.")
         
     | 
| 
      
 85 
     | 
    
         
            +
                    this.choices = [];
         
     | 
| 
      
 86 
     | 
    
         
            +
                    Object.assign(this, init);
         
     | 
| 
      
 87 
     | 
    
         
            +
                }
         
     | 
| 
      
 88 
     | 
    
         
            +
            }
         
     | 
| 
      
 89 
     | 
    
         
            +
            /** @description Given a list of messages comprising a conversation, the model will return a response. */
         
     | 
| 
      
 90 
     | 
    
         
            +
            // @Route("/v1/chat/completions", "POST")
         
     | 
| 
      
 91 
     | 
    
         
            +
            // @Api(Description="Given a list of messages comprising a conversation, the model will return a response.")
         
     | 
| 
      
 92 
     | 
    
         
            +
            export class OpenAiChatCompletion extends OpenAiChat {
         
     | 
| 
      
 93 
     | 
    
         
            +
                constructor(init) { super(init); Object.assign(this, init); }
         
     | 
| 
      
 94 
     | 
    
         
            +
                getTypeName() { return 'OpenAiChatCompletion'; }
         
     | 
| 
      
 95 
     | 
    
         
            +
                getMethod() { return 'POST'; }
         
     | 
| 
      
 96 
     | 
    
         
            +
                createResponse() { return new OpenAiChatResponse(); }
         
     | 
| 
      
 97 
     | 
    
         
            +
            }
         
     | 
    
        package/dist/types.js
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            export {};
         
     | 
    
        package/dist/utils.js
    ADDED
    
    | 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            export function replaceMyApp(input, projectName) {
         
     | 
| 
      
 2 
     | 
    
         
            +
                const condensed = projectName.replace(/_/g, '');
         
     | 
| 
      
 3 
     | 
    
         
            +
                const kebabCase = camelToKebabCase(condensed);
         
     | 
| 
      
 4 
     | 
    
         
            +
                const splitCase = splitPascalCase(condensed);
         
     | 
| 
      
 5 
     | 
    
         
            +
                return input
         
     | 
| 
      
 6 
     | 
    
         
            +
                    .replace(/My_App/g, projectName)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    .replace(/MyApp/g, projectName)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    .replace(/My App/g, splitCase)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    .replace(/my-app/g, kebabCase)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    .replace(/myapp/g, condensed.toLowerCase())
         
     | 
| 
      
 11 
     | 
    
         
            +
                    .replace(/my_app/g, projectName.toLowerCase());
         
     | 
| 
      
 12 
     | 
    
         
            +
            }
         
     | 
| 
      
 13 
     | 
    
         
            +
            export function splitPascalCase(str) {
         
     | 
| 
      
 14 
     | 
    
         
            +
                if (!str || str.length <= 1)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    return str;
         
     | 
| 
      
 16 
     | 
    
         
            +
                // Replace capital letters with space + letter, trim any leading space
         
     | 
| 
      
 17 
     | 
    
         
            +
                return str
         
     | 
| 
      
 18 
     | 
    
         
            +
                    .replace(/([A-Z])/g, ' $1')
         
     | 
| 
      
 19 
     | 
    
         
            +
                    .trim();
         
     | 
| 
      
 20 
     | 
    
         
            +
            }
         
     | 
| 
      
 21 
     | 
    
         
            +
            export function camelToKebabCase(str) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                if (!str || str.length <= 1)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    return str.toLowerCase();
         
     | 
| 
      
 24 
     | 
    
         
            +
                // Insert hyphen before capitals and numbers, convert to lowercase
         
     | 
| 
      
 25 
     | 
    
         
            +
                return str
         
     | 
| 
      
 26 
     | 
    
         
            +
                    .replace(/([A-Z0-9])/g, '-$1')
         
     | 
| 
      
 27 
     | 
    
         
            +
                    .toLowerCase()
         
     | 
| 
      
 28 
     | 
    
         
            +
                    // Remove leading hyphen if exists
         
     | 
| 
      
 29 
     | 
    
         
            +
                    .replace(/^-/, '')
         
     | 
| 
      
 30 
     | 
    
         
            +
                    // Replace multiple hyphens with single hyphen
         
     | 
| 
      
 31 
     | 
    
         
            +
                    .replace(/-+/g, '-');
         
     | 
| 
      
 32 
     | 
    
         
            +
            }
         
     | 
    
        package/package.json
    CHANGED
    
    | 
         @@ -1,8 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "name": "okai",
         
     | 
| 
       3 
3 
     | 
    
         
             
              "type": "module",
         
     | 
| 
       4 
     | 
    
         
            -
              "version": "0.0. 
     | 
| 
       5 
     | 
    
         
            -
              "bin": "./dist/ 
     | 
| 
      
 4 
     | 
    
         
            +
              "version": "0.0.5",
         
     | 
| 
      
 5 
     | 
    
         
            +
              "bin": "./dist/okai.js",
         
     | 
| 
       6 
6 
     | 
    
         
             
              "main": "./dist/index.js",
         
     | 
| 
       7 
7 
     | 
    
         
             
              "module": "./dist/index.js",
         
     | 
| 
       8 
8 
     | 
    
         
             
              "types": "./dist/index.d.ts",
         
     | 
| 
         @@ -12,7 +12,7 @@ 
     | 
|
| 
       12 
12 
     | 
    
         
             
                "import": "./dist/index.js"
         
     | 
| 
       13 
13 
     | 
    
         
             
              },
         
     | 
| 
       14 
14 
     | 
    
         
             
              "scripts": {
         
     | 
| 
       15 
     | 
    
         
            -
                "build": "bun run  
     | 
| 
      
 15 
     | 
    
         
            +
                "build": "bun run clean && tsc",
         
     | 
| 
       16 
16 
     | 
    
         
             
                "clean": "shx rm -rf ./dist",
         
     | 
| 
       17 
17 
     | 
    
         
             
                "test": "bun test --",
         
     | 
| 
       18 
18 
     | 
    
         
             
                "prepublishOnly": "bun run build",
         
     | 
    
        package/dist/index.d.ts
    DELETED