OpenAI #FtJob: Create

OpenAI #FtJob: Create

translate OpenAI #FtJob: 生成

Creates a job (FtJob) that fine-tunes a specified MODEL. Stores the job ID. The job will take minutes or hours. The “Fine-Tuned MODEL” (FtMODEL) will be available after the job is completed. Note that the training file (dataset) must be uploaded in advance.

Auto Step icon
Configs for this Auto Step
AuthzConfU1
U1: Select HTTP_Authz Setting (Secret API Key as “Fixed Value”) *
StrConfA1
A1: Set ID of Training File ID *#{EL}
SelectConfB1
B1: Select STRING that stores Job ID (update) *
StrConfU2
U2: Set OpenAI Organization ID (“org-xxxx”)#{EL}
StrConfA2
A2: Set ID of Validation File ID#{EL}
StrConfA3
A3: Set Base MODEL NAME/ID#{EL}
StrConfA4
A4: Set SUFFIX for FtMODEL Name#{EL}
Script (click to open)
// GraalJS standard mode Script Script (engine type: 3)
// cf. 'engine type: 2': "GraalJS Nashorn compatible mode" (renamed from "GraalJS" at 20230526)


//////// START "main()" /////////////////////////////////////////////////////////////////

main();
function main(){ 

////// == Config Retrieving / 工程コンフィグの参照 ==
const strAuthzSetting     = configs.get( "AuthzConfU1" );             /// REQUIRED
  engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
const strOrgId            = configs.get( "StrConfU2" );               // NotRequired
  engine.log( " AutomatedTask Config: OpenAI-Organization: " + strOrgId );

const strFileIdTraining   = configs.get( "StrConfA1" );               /// REQUIRED
const strFileIdValidation = configs.get( "StrConfA2" );               // NotRequired
const strBaseModel        = configs.get( "StrConfA3" );               // NotRequired
const strSuffix           = configs.get( "StrConfA4" );               // NotRequired

const strPocketJobId      = configs.getObject( "SelectConfB1" );      /// REQUIRED



////// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)



////// == Calculating / 演算 ==

//// OpenAI API > Documentation > API REFERENCE > Fine-tunes > Create fine-tune
//// https://platform.openai.com/docs/api-reference/fine-tunes/create

/// prepare json
let strJson = {};
    strJson.training_file = strFileIdTraining;
    if ( strFileIdValidation !== "" ){
      strJson.validation_file = strFileIdValidation;
    }
    if ( strBaseModel !== "" ){
      strJson.model = strBaseModel;
    }
    if ( strSuffix !== "" ){
      strJson.suffix = strSuffix;
    }

/// prepare request1
let request1Uri = "https://api.openai.com/v1/fine-tunes";
let request1 = httpClient.begin(); // HttpRequestWrapper
    request1 = request1.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
    if ( strOrgId !== "" ){
      request1 = request1.header( "OpenAI-Organization", strOrgId );
    }
    request1 = request1.body( JSON.stringify( strJson ), "application/json" );

/// try request1
const response1     = request1.post( request1Uri ); // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest1 Start: " + request1Uri );
const response1Code = response1.getStatusCode() + ""; // JavaNum to string
const response1Body = response1.getResponseAsString();
engine.log( " AutomatedTask ApiResponse1 Status: " + response1Code );
if( response1Code !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
/* engine.log( response1Body ); // debug
{
  "object": "fine-tune",
  "id": "ft-lN1WPLOp8rtoalbMG5Nctc0T",
  "hyperparams": {
    "n_epochs": 4,
    "batch_size": null,
    "prompt_loss_weight": 0.01,
    "learning_rate_multiplier": null
  },
  "organization_id": "org-xxxxxyyyyyzzzzzXXXXXYYYY",
  "model": "curie",
  "training_files": [
    {
      "object": "file",
      "id": "file-rM8tP15b9pZ2tJSLZEfUl7fG",
      "purpose": "fine-tune",
      "filename": "training-data-questetra-bpm-suite-assistant.jsonl",
      "bytes": 6823,
      "created_at": 1690249576,
      "status": "processed",
      "status_details": null
    }
  ],
  "validation_files": [],
  "result_files": [],
  "created_at": 1690354635,
  "updated_at": 1690354635,
  "status": "pending",
  "fine_tuned_model": null,
  "events": [
    {
      "object": "fine-tune-event",
      "level": "info",
      "message": "Created fine-tune: ft-lN1WPLOp8rtoalbMG5Nctc0T",
      "created_at": 1690354635
    }
  ]
}
*/

/// parse response1
const response1Obj = JSON.parse( response1Body );



////// == Data Updating / ワークフローデータへの代入 ==
if( strPocketJobId !== null ){
  engine.setData( strPocketJobId, response1Obj.id );
}


} //////// END "main()" /////////////////////////////////////////////////////////////////


/*
Notes:
- This "Automated Step" will start to generate a Fine-Tuned MODEL on the OpenAI server.
    - It is possible to specify the base MODEL.
    - The confirmation step is placed downstream. (OpenAI #FtJob: Retrieve)
- If you place this "Automated Step" in the Workflow diagram, the request will be automatically sent every time the process token arrives.
    - A request is automatically sent to the OpenAI API server. (REST API)
    - The response from the OpenAI API server is automatically parsed.

APPENDIX
- To activate a Workflow App that includes this Automated Step, "HTTP Authz Setting" is required
    - Obtain a "Secret API Key" in advance.
    - Set the key as the communication token in "Token Fixed Value"
- This automated step does not support the following parameters.
     - `n_epochs`
     - `batch_size`
     - `learning_rate_multiplier`
     - `prompt_loss_weight`
     - `compute_classification_metrics`
     - `classification_n_classes`
     - `classification_positive_class`
     -`classification_betas`
- Check the OpenAI document for the MODEL that can be specified as the Base MODEL for fine tuning.
    - https://platform.openai.com/docs/guides/fine-tuning/what-models-can-be-fine-tuned
    - Asof 202307: Fine-tuning is currently only available for the following base models: `davinci`, `curie`, `babbage`, and `ada`. We are working on safely enabling fine-tuning for GPT-4 and GPT-3.5 Turbo and expect this feature to be available later this year.
- When setting SUFFIX, set it within 40 characters.
     - eg: "custom-model-name"
     - MODEL name: "ada:ft-your-org:custom-model-name-2022-02-15-04-21-04"


Notes-ja:
- この[自動工程]は、OpenAI サーバ上の Fine-Tuned MODEL 生成を開始させます。
    - ベースとなる MODEL を指定できます。
    - ファインチューニング(微調整)の成果は、下流に進捗確認工程を配置し確認します。(OpenAI #FtJob: 進捗確認)
- この[自動工程]をワークフロー図に配置すれば、案件が到達する度にリクエストが自動送信されます。
    - OpenAI API サーバに対してリクエストが自動送出されます。(REST API通信)
    - OpenAI API サーバからのレスポンスが自動保存解析されます。

APPENDIX-ja
- この[アドオン自動工程]を含むワークフローアプリを運用するには[HTTP 認証設定]が必要です。
    - あらかじめ "Secret API Key" を取得しておいてください。
    - "Secret API Key" を通信トークンとしてセットします。[トークン直接指定]
- この自動工程は、以下のパラメータに対応していません。
    - `n_epochs`
    - `batch_size`
    - `learning_rate_multiplier`
    - `prompt_loss_weight`
    - `compute_classification_metrics`
    - `classification_n_classes`
    - `classification_positive_class`
    - `classification_betas`
- ファインチューニングの Base MODEL として指定可能な MODEL については OpenAI ドキュメントを参照ください。
    - https://platform.openai.com/docs/guides/fine-tuning/what-models-can-be-fine-tuned
    - Asof 202307: Fine-tuning is currently only available for the following base models: `davinci`, `curie`, `babbage`, and `ada`. We are working on safely enabling fine-tuning for GPT-4 and GPT-3.5 Turbo and expect this feature to be available later this year.
- SUFFIX を設定する場合は40文字以内で設定します。
    - eg: "custom-model-name"
    - MODEL name: "ada:ft-your-org:custom-model-name-2022-02-15-04-21-04"
*/

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

  • This Automated Step will start to generate a Fine-Tuned MODEL on the OpenAI server.
    • It is possible to specify the base MODEL.
    • The confirmation step is placed downstream. (OpenAI #FtJob: Retrieve)
  • If you place this Automated Step in the Workflow diagram, the request will be automatically sent every time the process token arrives.
    • A request is automatically sent to the OpenAI API server. (REST API)
    • The response from the OpenAI API server is automatically parsed.

Capture

Creates a job (FtJob) that fine-tunes a specified MODEL. Stores the job ID. The job will take minutes or hours. The "Fine-Tuned MODEL" (FtMODEL) will be available after the job is completed. Note that the training file (dataset) must be uploaded in advance.

Appendix

  • To activate a Workflow App that includes this Automated Step, “HTTP Authz Setting” is required
    • Obtain a “Secret API Key” in advance.
    • Set the key as the communication token in “Token Fixed Value”
  • This automated step does not support the following parameters.
    • n_epochs
    • batch_size
    • learning_rate_multiplier
    • prompt_loss_weight
    • compute_classification_metrics
    • classification_n_classes
    • classification_positive_class
      classification_betas
  • Check the OpenAI document for the MODEL that can be specified as the Base MODEL for fine tuning.
  • When setting SUFFIX, set it within 40 characters.
    • eg: “custom-model-name”
    • MODEL name: “ada:ft-your-org:custom-model-name-2022-02-15-04-21-04”

See Also

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: