OpenAI #MODELs: List

OpenAI #MODELs: List

translate OpenAI #MODELs: リスト

Lists the various models available in the API including Fine-Tuned Models (FtMODELs). The number of the currently available models and TSV of basic information about each one can be obtained; created time, owner, root MODEL, MODEL ID.

Auto Step icon
Configs for this Auto Step
AuthzConfU1
U1: Select HTTP_Authz Setting (Secret API Key as “Fixed Value”) *
SelectConfB1
B1: Select NUMBER of MODELs (update)
SelectConfB3
B3: Select STRING that stores List TSV for MODELs (update)
StrConfU2
U2: Set OpenAI Organization ID (“org-xxxx”)#{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 numPocketModels     = configs.getObject( "SelectConfB1" );      // NotRequired
const strPocketModelsTsv  = configs.getObject( "SelectConfB3" );      // NotRequired



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



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

//// OpenAI API > Documentation > API REFERENCE > Models > List models
//// https://platform.openai.com/docs/api-reference/models/list

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

/// try request1
const response1     = request1.get( 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
{
  "data": [
    {...},
    {
      "id": "gpt-3.5-turbo",
      "object": "model",
      "created": 1677610602,
      "owned_by": "openai",
      "permission": [
        {
          "id": "modelperm-ILldYg889l2lED1b99xWEfey",
          "object": "model_permission",
          "created": 1689885359,
          "allow_create_engine": false,
          "allow_sampling": true,
          "allow_logprobs": true,
          "allow_search_indices": false,
          "allow_view": true,
          "allow_fine_tuning": false,
          "organization": "*",
          "group": null,
          "is_blocking": false
        }
      ],
      "root": "gpt-3.5-turbo",
      "parent": null
    },
    {
      "id": "curie:ft-questetra-2023-07-26-10-23-43",
      "object": "model",
      "created": 1690367023,
      "owned_by": "questetra",
      "permission": [
        {
          "id": "snapperm-JrqscbqEqor5uPKpW2b7g9uE",
          "object": "model_permission",
          "created": 1690367023,
          "allow_create_engine": true,
          "allow_sampling": true,
          "allow_logprobs": true,
          "allow_search_indices": false,
          "allow_view": true,
          "allow_fine_tuning": true,
          "organization": "org-xxxxxyyyyyzzzzzXXXXXYYYY",
          "group": null,
          "is_blocking": false
        }
      ],
      "root": "curie:2020-05-03",
      "parent": "curie:2020-05-03"
    },
    {
      "id": "curie:ft-questetra-2023-07-26-12-16-05",
      "object": "model",
      "created": 1690373765,
      "owned_by": "questetra",
      "permission": [
        {
          "id": "snapperm-ZntlMpN2Xu1HfmTx5T5Uftla",
          "object": "model_permission",
          "created": 1690373765,
          "allow_create_engine": true,
          "allow_sampling": true,
          "allow_logprobs": true,
          "allow_search_indices": false,
          "allow_view": true,
          "allow_fine_tuning": true,
          "organization": "org-xxxxxyyyyyzzzzzXXXXXYYYY",
          "group": null,
          "is_blocking": false
        }
      ],
      "root": "curie:2020-05-03",
      "parent": "curie:2020-05-03"
    }
  ]
}
*/

/// parse response1
const response1Obj = JSON.parse( response1Body );
let numModels = response1Obj?.data?.length ?? 0;
let arrModelsData = [];
for ( let i = 0; i < numModels; i++ ) { // Model ID, owned_by,
  const dateTmpCreated = new Date ( response1Obj.data[i].created * 1000 );
  arrModelsData.push ( 
    dateTmpCreated.toISOString() + '\t' +
    response1Obj.data[i].owned_by + '\t' +
    response1Obj.data[i].root + '\t' +
    response1Obj.data[i].id
  );
}




////// == Data Updating / ワークフローデータへの代入 ==
if( numPocketModels !== null ){
  engine.setData( numPocketModels, new java.math.BigDecimal( numModels ) );
}
if( strPocketModelsTsv !== null ){
  engine.setData( strPocketModelsTsv, arrModelsData.join('\n') );
}



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



/*
Notes:
- This "Automated Step" will list the MODELs available in the API.
    - Including Fine-Tuned MODELs (FtMODELs).
- 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"


Notes-ja:
- この[自動工程]は、API で利用可能な MODEL をリストします。
    - ファインチューニング済みの MODEL (FtMODEL) も含まれます。
- この[自動工程]をワークフロー図に配置すれば、案件が到達する度にリクエストが自動送信されます。
    - OpenAI API サーバに対してリクエストが自動送出されます。(REST API通信)
    - OpenAI API サーバからのレスポンスが自動保存解析されます。

APPENDIX-ja
- この[アドオン自動工程]を含むワークフローアプリを運用するには[HTTP 認証設定]が必要です。
    - あらかじめ "Secret API Key" を取得しておいてください。
    - "Secret API Key" を通信トークンとしてセットします。[トークン直接指定]
*/

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 list the MODELs available in the API.
    • Including Fine-Tuned MODELs (FtMODELs).
  • 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

Lists the various models available in the API including Fine-Tuned Models (FtMODELs). The number of the currently available models and TSV of basic information about each one can be obtained; created time, owner, root MODEL, MODEL ID.

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”

See Also

Leave a Reply

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

%d bloggers like this: