OpenAI #FtJob: 生成
MODEL をファインチューニングするジョブ(FtJob)を開始させ、ジョブのIDを取得します。生成ジョブの完了には数分から数時間かかります。”チューニングされた MODEL”(FtMODL)は、ジョブ完了後に利用可能となります。なお、トレーニングファイル(データセット)は事前にアップロードしておく必要があります。
Configs for this Auto Step
- AuthzConfU1
- U1: HTTP認証設定を選択してください(Secret API Key @トークン直接指定) *
- StrConfA1
- A1: トレーニング(学習)ファイルのIDをセットしてください *#{EL}
- SelectConfB1
- B1: Job ID が格納される文字列型データ項目を選択してください(更新) *
- StrConfU2
- U2: OpenAI Organization ID をセットしてください(”org-xxxx”)#{EL}
- StrConfA2
- A2: 検証ファイルのIDをセットしてください#{EL}
- StrConfA3
- A3: ベースとなる MODEL NAME/ID をセットしてください *#{EL}
- StrConfA4
- A4: Fine-Tuned MODEL 名に追加したい SUFFIX をセットしてください#{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" ); /// REQUIRED (20230822)
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-tuning job
//// https://platform.openai.com/docs/api-reference/fine-tuning/create
/// prepare json
let strJson = {};
strJson.training_file = strFileIdTraining;
if ( strFileIdValidation !== "" ){
strJson.validation_file = strFileIdValidation;
}
strJson.model = strBaseModel; // eg. "gpt-3.5-turbo" (asof 20230822)
if ( strSuffix !== "" ){
strJson.suffix = strSuffix;
}
/// prepare request1
let request1Uri = "https://api.openai.com/v1/fine_tuning/jobs"; // updated 20230822
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_tuning.job",
"id":"ftjob-EcRIIXZMnZzbEqyrFvJ2vYLZ",
"model":"gpt-3.5-turbo-0613",
"created_at":1692772480,
"finished_at":null,
"fine_tuned_model":null,
"organization_id":"org-xxxxxyyyyyzzzzzXXXXXYYYY",
"result_files":[],
"status":"created",
"validation_file":null,
"training_file":"file-UaXSB3M90mpinC3pH3ZGiTiJ",
"hyperparameters":{"n_epochs":5},
"trained_tokens":null
}
*/
/// 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.
- Asof 202308: Fine-tuning is currently available for the following models:
- gpt-3.5-turbo-0613 (recommended)
- babbage-002
- davinci-002
- 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"
- The format of the training data has also changed. (2023-08-22)
- https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset
- 20230822~: `{"messages": [{"role": "system", "content": "●"}, {"role": "user", "content": "●"}, {"role": "assistant", "content": "●"}]}`
- ~20230822: `{"prompt": "<prompt text>", "completion": "<ideal generated text>"}`
- error to: `"message": "File file-xxxxxyyyyyzzzzzXXXXXYYYY format is not compatible with model gpt-3.5-turbo-0613"`
- At least 10 examples are required. For clear improvements on 50 to 100 training examples typically.
- error to: `"message": "file-xxxxxyyyyyzzzzzXXXXXYYYY has 4 example(s), but must have at least 10 examples"`
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.
- Asof 202308: Fine-tuning is currently available for the following models:
- gpt-3.5-turbo-0613 (recommended)
- babbage-002
- davinci-002
- SUFFIX を設定する場合は40文字以内で設定します。
- eg: "custom-model-name"
- MODEL name: "ada:ft-your-org:custom-model-name-2022-02-15-04-21-04"
- トレーニングデータのフォーマットも変更されています。 (2023-08-22)
- https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset
- 20230822~: `{"messages": [{"role": "system", "content": "●"}, {"role": "user", "content": "●"}, {"role": "assistant", "content": "●"}]}`
- ~20230822: `{"prompt": "<prompt text>", "completion": "<ideal generated text>"}`
- error to: `"message": "File file-xxxxxyyyyyzzzzzXXXXXYYYY format is not compatible with model gpt-3.5-turbo-0613"`
- 少なくとも10個のトレーニングデータが必要です。通常、50~100個のデータで明確な改善が期待されます。
- error to: `"message": "file-xxxxxyyyyyzzzzzXXXXXYYYY has 4 example(s), but must have at least 10 examples"`
*/
Download
- openai-ftjob-create-202308.xml
- 2023-08-23 (C) Questetra, Inc. (MIT License)
(アドオン自動工程のインストールは Professional editionでのみ可能です)
Notes
- この[自動工程]は、OpenAI サーバ上の Fine-Tuned MODEL 生成を開始させます。
- ベースとなる MODEL を指定できます。
- ファインチューニング(微調整)の成果は、下流に進捗確認工程を配置し確認します。(OpenAI #FtJob: 進捗確認)
- この[自動工程]をワークフロー図に配置すれば、案件が到達する度にリクエストが自動送信されます。
- OpenAI API サーバに対してリクエストが自動送出されます。(REST API通信)
- OpenAI API サーバからのレスポンスが自動保存解析されます。
Capture


Appendix
- この[アドオン自動工程]を含むワークフローアプリを運用するには[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
, andada
. 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. - Asof 202308: Fine-tuning is currently available for the following models:
- gpt-3.5-turbo-0613 (recommended)
- babbage-002
- davinci-002
- SUFFIX を設定する場合は40文字以内で設定します。
- eg: “custom-model-name”
- MODEL name: “ada:ft-your-org:custom-model-name-2022-02-15-04-21-04”
- トレーニングデータのフォーマットも変更されています。 (2023-08-22)
- https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset
- 20230822~:
{"messages": [{"role": "system", "content": "●"}, {"role": "user", "content": "●"}, {"role": "assistant", "content": "●"}]}
- ~20230822:
{"prompt": "<prompt text>", "completion": "<ideal generated text>"}
- error to:
"message": "File file-xxxxxyyyyyzzzzzXXXXXYYYY format is not compatible with model gpt-3.5-turbo-0613"
- 少なくとも10個のトレーニングデータが必要です。通常、50~100個のデータで明確な改善が期待されます。
- error to:
"message": "file-xxxxxyyyyyzzzzzXXXXXYYYY has 4 example(s), but must have at least 10 examples"
- error to: