I believe in sharing. Learning how to use OpenAI's latest API for ChatGTP was very useful for me, so I hope it will also be useful for others here as well.
So without further ado, here is a straightfoward function which demonstrates how to use OpenAI's recently released GPT-3.5-Turbo API. The same model is used on the ChatGPT web interface, so it is just like using ChatGTP, but now through code - how cool is that?.
This code can just be written into a Jupyter Notebook as on the screenshot - and you are all set. Just run it, ask a question, hit enter - and magic !
I found the example on this very helpful video
https://lnkd.in/dP2hdNtT
However I have adapted the code slightly, so that I declare my API key directly in the function. Just put in your own API key from OpenAI here (it is free)
And keep in mind this new API is 1/10th the price per token of the already reasonably priced Da Vinci model. You get $5 free credit to begin with. At this token price it will last you a while. Nice move from OpenAI!