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
(AutoIt) 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. $oHttp = ObjCreate("Chilkat.Http") Local $bSuccess ; 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. $oHttp.AuthToken = "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" $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $bSuccess = $oHttp.QuickGetSb("https://api.openai.com/v1/models",$oSbResponseBody) If ($bSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf $oJResp = ObjCreate("Chilkat.JsonObject") $oJResp.LoadSb($oSbResponseBody) $oJResp.EmitCompact = False ConsoleWrite("Response Body:" & @CRLF) ConsoleWrite($oJResp.Emit() & @CRLF) Local $iRespStatusCode = $oHttp.LastStatus ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF) If ($iRespStatusCode >= 400) Then ConsoleWrite("Response Header:" & @CRLF) ConsoleWrite($oHttp.LastHeader & @CRLF) ConsoleWrite("Failed." & @CRLF) Exit 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 Local $sId Local $iCreated Local $sOwned_by Local $sRoot Local $sParent Local $iJ Local $iCount_j Local $bAllow_create_engine Local $bAllow_sampling Local $bAllow_logprobs Local $bAllow_search_indices Local $bAllow_view Local $bAllow_fine_tuning Local $sOrganization Local $sGroup Local $bIs_blocking Local $sV_object = $oJResp.StringOf("object") Local $i = 0 Local $iCount_i = $oJResp.SizeOfArray("data") While $i < $iCount_i $oJResp.I = $i $sId = $oJResp.StringOf("data[i].id") $sV_object = $oJResp.StringOf("data[i].object") $iCreated = $oJResp.IntOf("data[i].created") $sOwned_by = $oJResp.StringOf("data[i].owned_by") $sRoot = $oJResp.StringOf("data[i].root") $sParent = $oJResp.StringOf("data[i].parent") $iJ = 0 $iCount_j = $oJResp.SizeOfArray("data[i].permission") While $iJ < $iCount_j $oJResp.J = $iJ $sId = $oJResp.StringOf("data[i].permission[j].id") $sV_object = $oJResp.StringOf("data[i].permission[j].object") $iCreated = $oJResp.IntOf("data[i].permission[j].created") $bAllow_create_engine = $oJResp.BoolOf("data[i].permission[j].allow_create_engine") $bAllow_sampling = $oJResp.BoolOf("data[i].permission[j].allow_sampling") $bAllow_logprobs = $oJResp.BoolOf("data[i].permission[j].allow_logprobs") $bAllow_search_indices = $oJResp.BoolOf("data[i].permission[j].allow_search_indices") $bAllow_view = $oJResp.BoolOf("data[i].permission[j].allow_view") $bAllow_fine_tuning = $oJResp.BoolOf("data[i].permission[j].allow_fine_tuning") $sOrganization = $oJResp.StringOf("data[i].permission[j].organization") $sGroup = $oJResp.StringOf("data[i].permission[j].group") $bIs_blocking = $oJResp.BoolOf("data[i].permission[j].is_blocking") $iJ = $iJ + 1 Wend $i = $i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.