Jump to content

Search the Community

Showing results for tags 'ipworks'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 1 result

  1. CoeurdeLeon

    ChatGPT Example

    Does anyone have a working example where a connection is made with chatgpt, a question is asked and a response successfully returned. I have tried with both indy and ipworks components. I get a variety of errors. Here are 2 IPworks functions: Unit ads.ChatGpt; Interface Function ChatWithGPT(Const question, Api_Key: String): String; Function ChatWithGPT2(Const question, Api_Key: String): String; Implementation Uses ipwcore, ipwhttp, ipwrest, ipwtypes, System.SysUtils; Function ChatWithGPT(Const question, Api_Key: String): String; Var http : TIpwHttp; response: String; Begin http := TIpwHttp.Create(Nil); Try http.AddCookie('Authorization', 'Bearer ' + Api_Key); http.Get('https://api.openai.com/v1/chatgpt/chat?question=' + question); response := http.TransferredData; Result := response; Finally http.Free; End; End; Function ChatWithGPT2(Const question, Api_Key: String): String; Var rest : TipwREST; response: String; Begin rest := TipwREST.Create(Nil); Try rest.ContentType := 'application/json'; rest.OtherHeaders := 'Authorization: Bearer ' + Api_Key; rest.PostData := '{\"model\": \"text-davinci-003\", \"prompt\": \"" + question + "\", \"temperature\": 0, \"max_tokens\": 64}'; rest.Post('https://api.openai.com/v1/completions'); rest.XPath := '/json/choices/[1]/text'; response := rest.XText.Replace('\"', ''); Result := response; Finally FreeAndNil(rest); End; End; End. Richard Maley
×