Implement uploading of files for model fine-tuning to OpenAI API - #155
Merged
Conversation
* build(deps-dev): bump @babel/preset-env from 7.22.5 to 7.22.9 Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.22.5 to 7.22.9. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.22.9/packages/babel-preset-env) --- updated-dependencies: - dependency-name: "@babel/preset-env" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps-dev): bump prettier from 2.8.8 to 3.0.0 Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](prettier/prettier@2.8.8...3.0.0) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps-dev): bump tslib from 2.5.3 to 2.6.1 Bumps [tslib](https://github.com/Microsoft/tslib) from 2.5.3 to 2.6.1. - [Release notes](https://github.com/Microsoft/tslib/releases) - [Commits](microsoft/tslib@v2.5.3...v2.6.1) --- updated-dependencies: - dependency-name: tslib dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps-dev): bump jest and @types/jest Bumps [jest](https://github.com/facebook/jest/tree/HEAD/packages/jest) and [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest). These dependencies needed to be updated together. Updates `jest` from 29.5.0 to 29.6.1 - [Release notes](https://github.com/facebook/jest/releases) - [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/jest/commits/v29.6.1/packages/jest) Updates `@types/jest` from 29.5.2 to 29.5.3 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) --- updated-dependencies: - dependency-name: jest dependency-type: direct:development update-type: version-update:semver-minor - dependency-name: "@types/jest" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * feature/files multiple * refactor: Update uploadFile middleware to uploadFiles for handling multiple files. * refactor: Rename src/http/Responses.ts file to src/lib/Responses.ts. Updated path to dependency. * feat: add rxjs dependency to package.json (feature/files-multiple) * feat(configs): add validFiles regex pattern (feature/files-multiple) * feat(types): add optional properties to Express.Request - Add optional property 'proxy' of type SoakpProxy to Express.Request interface - Add optional property 'files' of type Express.Multer.File[] to Express.Request interface - Remove 'convert' property from Express.Request interface - Add property 'openaiFileId' of type string to Express.Request interface - Add property 'titles' of type string[] to Express.Request interface feat(uploadFiles): update file upload middleware to accept multiple files feat(SoakpProxy): Add concatTxt2Jsonlines method Add the `concatTxt2Jsonlines` method to the `SoakpProxy` class. This method concatenates an array of files into a single JSONL file suitable for OpenAI model fine-tuning. The concatenated file is saved with a generated name in the `jsonl` directory. - Added support for uploading multiple files in the OpenaiFilesApi class. - Updated the `sendFiles` method to handle multiple file uploads. - Added validation for file titles and file types. - Implemented file concatenation and conversion to JSONL format. - Updated the `sendFile` method to handle file uploads. - Added error handling and response messages. feat(lib): Add Timer and LineParser classes - Add Timer class with a static method `wait` that returns a promise that resolves after a specified delay. - Add LineParser class with a parser and stringifier instance from the jsonlines library. - Add cleanup method to LineParser that removes leading whitespace from a given line. This commit adds the Timer and LineParser classes to the `lib` directory. The Timer class provides a convenient way to introduce delays in asynchronous operations. The LineParser class utilizes the jsonlines library to parse and stringify JSON lines. Additionally, the LineParser class includes a cleanup method that removes leading whitespace from a given line. feat(openai): update uploadFile parameter in OpenaiFilesApi.ts Update the `uploadFile` method parameter in `OpenaiFilesApi.ts` to accept a `jsonlDataReadStream` instead of `concatenatedFile` in the `fine-tune` mode. * feat(tests): Refactor server test to use Timer class Refactor the server test in `src/__tests__/server.ts` to use the `Timer` class instead of the `wait` function. This change improves code readability and maintainability. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [babel-jest](https://github.com/facebook/jest/tree/HEAD/packages/babel-jest) from 29.5.0 to 29.6.2. - [Release notes](https://github.com/facebook/jest/releases) - [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/jest/commits/v29.6.2/packages/babel-jest) --- updated-dependencies: - dependency-name: babel-jest dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 29.1.0 to 29.1.1. - [Release notes](https://github.com/kulshekhar/ts-jest/releases) - [Changelog](https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md) - [Commits](kulshekhar/ts-jest@v29.1.0...v29.1.1) --- updated-dependencies: - dependency-name: ts-jest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Antony Repin <lehcode@gmail.com>
Bumps [jest](https://github.com/facebook/jest/tree/HEAD/packages/jest) from 29.6.1 to 29.6.2. - [Release notes](https://github.com/facebook/jest/releases) - [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/jest/commits/v29.6.2/packages/jest) --- updated-dependencies: - dependency-name: jest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 4.2.1 to 5.0.0. - [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases) - [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/master/CHANGELOG.md) - [Commits](prettier/eslint-plugin-prettier@v4.2.1...v5.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-prettier dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Antony Repin <lehcode@gmail.com>
Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 8.8.0 to 8.9.0. - [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md) - [Commits](prettier/eslint-config-prettier@v8.8.0...v8.9.0) --- updated-dependencies: - dependency-name: eslint-config-prettier dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Antony Repin <lehcode@gmail.com>
Bumps [flask](https://github.com/pallets/flask) from 2.0.1 to 2.2.5. - [Release notes](https://github.com/pallets/flask/releases) - [Changelog](https://github.com/pallets/flask/blob/main/CHANGES.rst) - [Commits](pallets/flask@2.0.1...2.2.5) --- updated-dependencies: - dependency-name: flask dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Antony Repin <lehcode@gmail.com>
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.5. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](jonschlinkert/word-wrap@1.2.3...1.2.5) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](npm/node-semver@v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [eslint](https://github.com/eslint/eslint) from 8.43.0 to 8.46.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](eslint/eslint@v8.43.0...v8.46.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.3.1 to 20.4.5. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Antony Repin <lehcode@gmail.com>
Bumps [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) from 7.22.5 to 7.22.9. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.22.9/packages/babel-core) --- updated-dependencies: - dependency-name: "@babel/core" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) from 9.0.0 to 9.0.1. - [Changelog](https://github.com/auth0/node-jsonwebtoken/blob/master/CHANGELOG.md) - [Commits](auth0/node-jsonwebtoken@v9.0.0...v9.0.1) --- updated-dependencies: - dependency-name: jsonwebtoken dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* fix: Update Node.js version in .env.dist and .env.test files - Updated USE_NODE_VERSION value from 16.20.0 to 18.16.0 in .env.dist and .env.test files. * feat: Add lodash and ts-morph dependencies - Added lodash (^4.14.2) and ts-morph (^19.0.0) as dependencies in package.json. - Updated devDependencies for @types/lodash (^4.14.196). Issue Number: hotfix/cancel-fine-tune (from branch name) * feat(config): update USE_PYTHON_VERSION to "3.9" in .env.dist and .env.test files (hotfix/cancel-fine-tune) * feat(openai): Add OpenaiFinetunesApi class for fine-tuning jobs (hotfix/cancel-fine-tune) The `OpenaiFinetunesApi` class provides a set of methods to handle fine-tuning related jobs. It allows creating, listing, retrieving details, listing events, and canceling fine-tuning jobs. Each method corresponds to an API endpoint and communicates with the OpenAI API via a proxy instance. This class requires instantiation with a `SoakpServer` context for access to application services and utilities. Changes: - Added `CreateFineTuneRequest` import from 'openai' - Added `Project` import from 'ts-morph' - Added class description and method descriptions - Modified `createJob` method to expect `training_file` and `model` parameters in the request body - Updated `createJob` method to use the `CreateFineTuneRequest` interface and pass the request to the proxy - Updated error handling * chore(tsconfig): Update target and allowJs options in tsconfig.json (hotfix/cancel-fine-tune)
Bumps [lodash](https://github.com/lodash/lodash) from 4.14.2 to 4.17.21. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](lodash/lodash@4.14.2...4.17.21) --- updated-dependencies: - dependency-name: lodash dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: Add express-rate-limit package Add the express-rate-limit package to the dependencies in package.json. Issue: hotfix/rate-limiting * feat(server): add rate limiting middleware (hotfix/rate-limiting) Add rate limiting middleware to the server to limit the number of requests from clients. The middleware is implemented using the 'express-rate-limit' package. The rate limit is set to 5 requests per minute. Changes made in src/SoakpServer.ts: - Import the 'rateLimit' middleware from 'express-rate-limit'. - Add a 'rateLimit' property to the SoakpServer class. - Initialize the 'rateLimit' property with a window of 1 minute and a maximum of 5 requests. - Add the 'rateLimit' middleware to the express app. Issue: hotfix/rate-limiting
* feat: Add fine-tunes API endpoints * feat(SoakpProxy): Add concatTxt2Jsonlines method This commit adds the `concatTxt2Jsonlines` method to the `SoakpProxy` class. This method is used to concatenate an array of text files into a single JSONL file suitable for OpenAI model fine-tuning. The method takes in the `txtFiles` array of text files and the `completions` array of completion strings. It also accepts an optional `concatBaseName` parameter to specify the base name of the concatenated JSONL file. If not provided, a default name will be generated. Issue: feature/finetunes * feat: Update Node.js version in .env.dist and .env.test files Update the Node.js version in the .env.dist and .env.test files from 16.20.0 to 18.17.0. Issue: feature/finetunes
5 tasks
…oad-file-for-fine-tuning) - Updated the file upload method in the OpenaiFinetunesApi class. - Replaced the uploadFineTuneFile() method with uploadFile(). - This change ensures consistency with the naming convention. - Also updated the error handling in the catch block. - Changed the type of the rateLimit variable to 'any' for now. Issue: sweep/upload-file-for-fine-tuning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the functionality to upload files for model fine-tuning to the OpenAI API. It includes changes to the
SoakpProxyandOpenaiFinetunesApiclasses.Summary of Changes
uploadFineTuneFilein theSoakpProxyclass to handle file upload for fine-tuning. This method uses the OpenAI API'screateFilemethod.POST /openai/fine-tunes/uploadin theOpenaiFinetunesApiclass to handle the HTTP request for file upload. This endpoint calls theuploadFineTuneFilemethod in theSoakpProxyclass.Related Issue
This PR addresses Issue #153.
Testing
Documentation
Checklist
Fixes #153.
To checkout this PR branch, run the following command in your terminal:
To get Sweep to edit this pull request, leave a comment below or in the code. Leaving a comment in the code will only modify the file but commenting below can change the entire PR.