الذكاء الصناعي يعرف باسكال
#5
استخدم ChatGPT من دلفي

كود :
https://www.tmssoftware.com/site/blog.asp?post=1045&fbclid=IwAR2s0h20LBWhCDvc_D56nxx7uGbagG_Wwo3Pt6Qm20B2BRmaWZJyVquqGfU


[صورة: delphichatgtp1.png]

[صورة: delphichatgtp2.png]


كود :
uses    System.JSON, VCL.TMSFNCCloudBase;    function AskChatGPT(AQuestion: string): string;  var    LCb: TTMSFNCCloudBase;    LPostdata: string;    LJsonValue: TJsonValue;    LJsonArray: TJsonArray;    LJSonString: TJsonString;  begin    Result := '';      LPostData := '{' +      '"model": "text-davinci-003",'+      '"prompt": "' + AQuestion + '",'+      '"max_tokens": 2048,'+      '"temperature": 0'+      '}';      // create instance of TMS FNC Cloud Base class    LCb := TTMSFNCCloudBase.Create;      try      // Use JSON for the REST API calls and set API KEY via Authorization header      LCb.Request.AddHeader('Authorization','Bearer ' + CHATGPT_APIKEY);      LCb.Request.AddHeader('Content-Type','application/json');        // Select HTTPS POST method, set POST data and specify endpoint URL      LCb.Request.Method := rmPOST;      LCb.Request.PostData := LPostData;      LCb.Request.Host := 'https://api.openai.com';      LCb.Request.Path := 'v1/completions';        // Execute the HTTPS POST request synchronously (last param Async = false)      LCb.ExecuteRequest(nil,nil,false);        // Process returned JSON when request was successful      if Lcb.RequestResult.Success then      begin        LJsonValue := TJSonObject.ParseJSONValue(Lcb.RequestResult.ResultString);        LJsonValue := LJsonValue.GetValue<TJSonValue>('choices');        if LJsonValue is TJSonArray then        begin          LJSonArray := LJsonValue as TJSonArray;          LJSonString := LJSonArray.Items[0].GetValue<TJSONString>('text');          Result := LJSonString.Value;        end        else      end      else        raise Exception.Create('HTTP response code: ' + LCb.RequestResult.ResponseCode.ToString);    finally      LCb.Free;    end;  end; 
قل: اللهم فاطِرَ السماوات والأرض عالم الغيبِ والشهادة، ربَّ كُلِّ شَيءٍ ومَلِيكَه، أَشْهد أن لا إله إلا أنت، أعوذ بك من شرِّ نفسي وشرِّ الشيطان وشِرْكِهِ وأن أقترف على نفسي سوءًا أو أجرُّه إلى مسلم
[-] كل من 5 users say قال شكرا ل Delphi4Us على المشاركة المفيدة
  • Delphi2020, أبو معاذ, ELARAPY, wadoud, rm31
الرد


الردود في هذا الموضوع
الذكاء الصناعي يعرف باسكال - بواسطة Delphi4Us - 24-12-2022, 06:14 PM
RE: الذكاء الصناعي يعرف باسكال - بواسطة Delphi4Us - 03-01-2023, 02:31 PM
RE: الذكاء الصناعي يعرف باسكال - بواسطة NiTRO - 04-04-2023, 03:48 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم