Jump to content

Chat GPT example


Jfish
 Share

Recommended Posts

CHAT GPT is taking over ... so I asked it to help me code a call to itself from AutoIt. It did pretty well - but ultimately I had to turn to the docs to realize that it was calling its own deprecated endpoint that I needed to update (AI has limits I guess).  Anywho, if anyone wants to play around with it here is a working example:

#include <WinHttp.au3>
#include <Json.au3>

; Set up WinHttp object
$oHttp = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHttp.Open("POST", "https://api.openai.com/v1/completions", false)
$oHttp.SetRequestHeader("Content-Type", "application/json")
$oHttp.SetRequestHeader("Authorization", "Bearer <YOUR API KEY HERE>"); you will need to get an API key and place it here

; Set up request data params can be seen here https://platform.openai.com/docs/api-reference/completions/create 
; tokens dictate length
$sData = '{"model": "text-davinci-003", "prompt": "what day is it?", "max_tokens": 10}' ; change the prompt to whatever you want

; Send request and get response
$oHttp.Send($sData)

; Check if request was successful
If $oHttp.Status <> 200 Then
    MsgBox(0, "Error", "WinHttp request failed with status code: " & $oHttp.Status)
    Exit
EndIf

$sResponse = $oHttp.ResponseText

; Parse response and display
$aJson = _Json_Parse($sResponse)
$sText = $aJson.choices[0].text
MsgBox(0, "Response", $sText)

 

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

[this was a reply to a message that was subsequently deleted - won't let me delete the reply for some reason] Yes. it can code and it can also debug code. It isn't always 100% accurate but over time it has the potential to radically change so many things - including software development.

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...