Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 12/31/22 in Posts

  1. esegece

    ChatGPT Example

    Hello, The API is very simple, you can use Indy to send the POST request and then parse the JSON response. Find below an example: function AskChatGPT(const aAPI, aQuestion: string): string; var oHTTP: TIdHTTP; oSSL: TIdSSLIOHandlerSocketOpenSSL; oStream: TStringStream; vPostData: string; oJSON: TJSONValue; oArray: TJSonArray; begin oHTTP := TIdHTTP.Create(nil); oSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); Try oSSL.SSLOptions.Method := sslvTLSv1_2; oHTTP.IOHandler := oSSL; oHTTP.Request.CustomHeaders.Add('Authorization: Bearer ' + aAPI); oHTTP.Request.ContentType := 'application/json'; vPostData := Format('{"model": "text-davinci-003","prompt": "%s","max_tokens": 2048,"temperature": 0}', [aQuestion]); // send request oStream := TStringStream.Create(vPostData); Try result := oHTTP.Post('https://api.openai.com/v1/completions', oStream); // parse response oJSON := TJSonObject.ParseJSONValue(result).GetValue<TJSONValue> ('choices'); result := TJSonArray(oJSON).Items[0].GetValue<TJSONString>('text').Value; Finally oStream.Free; End; Finally oSSL.Free; oHTTP.Free; End; end; The function has 2 arguments, the API key (can be obtained from https://beta.openai.com/account/api-keys) and the message you want to sent to ChatGPT. The function just sends the API Key as a Bearer Token and POST the JSON message to the server. The server returns a JSON object that must be parsed to obtain the response text. I've attached the complete project with the required openSSL libraries. Kind Regards, Sergio chatgpt_esegece.zip
  2. In a 5 year old answer to a stackoverflow question @David Heffernan responded that "class properties cannot be accessed via RTTI". Is this still the case with recent versions of Delphi?
  3. python4delphi/Demos at master · pyscripter/python4delphi (github.com) python4delphi/Tutorials at master · pyscripter/python4delphi (github.com)
  4. Attila Kovacs

    AE BDSLauncher

    I think you can remove POSTED_DDE_ACK
  5. I found my problem. I thought the barcodeHandler was only called when a barcode was found in the image. Things are working fine now. Thanks again for the help.
  6. AFAIK, yes, it is still the case.
  7. programmerdelphi2k

    Adding phone numbers in addressbook

    It's right! because if you "Free it" your reference on "phones list" would be "null"... provocating a "AV"!
×