Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Lianja) OpenAI (ChatGTP) List ModelsSee more OpenAI ChatGPT ExamplesShow how to list available OpenAI models and shows how to parse the JSON model information. For more information, see https://platform.openai.com/docs/api-reference/models/list
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loHttp = createobject("CkHttp") // Implements the following CURL command: // curl https://api.openai.com/v1/models \ // -H "Authorization: Bearer $OPENAI_API_KEY" // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code // Adds the "Authorization: Bearer $OPENAI_API_KEY" header. // This is NOT a real key. Change the "sk-vi...." to your own key. loHttp.AuthToken = "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" loSbResponseBody = createobject("CkStringBuilder") llSuccess = loHttp.QuickGetSb("https://api.openai.com/v1/models",loSbResponseBody) if (llSuccess = .F.) then ? loHttp.LastErrorText release loHttp release loSbResponseBody return endif loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loHttp.LastStatus ? "Response Status Code = " + str(lnRespStatusCode) if (lnRespStatusCode >= 400) then ? "Response Header:" ? loHttp.LastHeader ? "Failed." release loHttp release loSbResponseBody release loJResp return endif // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "object": "list", // "data": [ // { // "id": "babbage", // "object": "model", // "created": 1649358449, // "owned_by": "openai", // "permission": [ // { // "id": "modelperm-49FUp5v084tBB49tC4z8LPH5", // "object": "model_permission", // "created": 1669085501, // "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": "babbage", // "parent": null // }, // { // "id": "davinci", // "object": "model", // "created": 1649359874, // "owned_by": "openai", // "permission": [ // { // "id": "modelperm-U6ZwlyAd0LyMk4rcMdz33Yc3", // "object": "model_permission", // "created": 1669066355, // "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": "davinci", // "parent": null // }, // ... // ... // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON lcV_object = loJResp.StringOf("object") i = 0 lnCount_i = loJResp.SizeOfArray("data") do while i < lnCount_i loJResp.I = i lcId = loJResp.StringOf("data[i].id") lcV_object = loJResp.StringOf("data[i].object") lnCreated = loJResp.IntOf("data[i].created") lcOwned_by = loJResp.StringOf("data[i].owned_by") lcRoot = loJResp.StringOf("data[i].root") lcParent = loJResp.StringOf("data[i].parent") j = 0 lnCount_j = loJResp.SizeOfArray("data[i].permission") do while j < lnCount_j loJResp.J = j lcId = loJResp.StringOf("data[i].permission[j].id") lcV_object = loJResp.StringOf("data[i].permission[j].object") lnCreated = loJResp.IntOf("data[i].permission[j].created") llAllow_create_engine = loJResp.BoolOf("data[i].permission[j].allow_create_engine") llAllow_sampling = loJResp.BoolOf("data[i].permission[j].allow_sampling") llAllow_logprobs = loJResp.BoolOf("data[i].permission[j].allow_logprobs") llAllow_search_indices = loJResp.BoolOf("data[i].permission[j].allow_search_indices") llAllow_view = loJResp.BoolOf("data[i].permission[j].allow_view") llAllow_fine_tuning = loJResp.BoolOf("data[i].permission[j].allow_fine_tuning") lcOrganization = loJResp.StringOf("data[i].permission[j].organization") lcGroup = loJResp.StringOf("data[i].permission[j].group") llIs_blocking = loJResp.BoolOf("data[i].permission[j].is_blocking") j = j + 1 enddo i = i + 1 enddo release loHttp release loSbResponseBody release loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.