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
(Visual FoxPro) 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
LOCAL loHttp LOCAL lnSuccess LOCAL loSbResponseBody LOCAL loJResp LOCAL lnRespStatusCode LOCAL lcId LOCAL lnCreated LOCAL lcOwned_by LOCAL lcRoot LOCAL lcParent LOCAL j LOCAL lnCount_j LOCAL lnAllow_create_engine LOCAL lnAllow_sampling LOCAL lnAllow_logprobs LOCAL lnAllow_search_indices LOCAL lnAllow_view LOCAL lnAllow_fine_tuning LOCAL lcOrganization LOCAL lcGroup LOCAL lnIs_blocking LOCAL lcV_object LOCAL i LOCAL lnCount_i * This example assumes the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.Http') * 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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" * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbResponseBody = CreateObject('Chilkat.StringBuilder') lnSuccess = loHttp.QuickGetSb("https://api.openai.com/v1/models",loSbResponseBody) IF (lnSuccess = 0) THEN ? loHttp.LastErrorText RELEASE loHttp RELEASE loSbResponseBody CANCEL ENDIF * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJResp = CreateObject('Chilkat.JsonObject') loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = 0 ? "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 CANCEL 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") lnAllow_create_engine = loJResp.BoolOf("data[i].permission[j].allow_create_engine") lnAllow_sampling = loJResp.BoolOf("data[i].permission[j].allow_sampling") lnAllow_logprobs = loJResp.BoolOf("data[i].permission[j].allow_logprobs") lnAllow_search_indices = loJResp.BoolOf("data[i].permission[j].allow_search_indices") lnAllow_view = loJResp.BoolOf("data[i].permission[j].allow_view") lnAllow_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") lnIs_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.