Is it possible somehow, through webget or something else, to interact with the API from ChatGPT (GPT-3), I need this in order to make a conversation with a virtual friend on the server, and not only for this, I can do this ?, there are just a few examples for python, and there is authorization through the site, but I still could not do anything, I decided to ask here.
Yes; You can use OpenAI's API endpoint using the
WebGet
command to interact with your server as a virtual friend. What you would need is to have basic understanding of making web requests and understanding the basics of JSON structures.
Per their documentation, this is where you want to reference first:
Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.
platform.openai.com
You can obtain an API key here, if you haven't already:
https://beta.openai.com/account/api-keys
Your
URL
endpoint is
https://api.openai.com/v1/completions
You can define your
<[headers]>
for the
Webget
command simply like this:
YAML:
- definemap headers:
Authorization: <secret[ai]>
Content-Type: application/json
User-Agent: your_name
For more information on SecretTags such as the example used above
<secret[ai]>
, you can reference this part of the meta for setting yours up:
Tag search for 'secret'
meta.denizenscript.com
It's very important you never reveal your OpenAI API Token, or to have it written blatantly in your script to be saved in ram. Using a SecretTag allows you to properly secure your token.
Your
<[data]>
is going to be where your prompt goes, here's a simple example:
YAML:
- definemap data:
model: text-davinci-003
prompt: Tell me a joke!
temperature: 0
max_tokens: 300
This example uses the
text-davinci-003
model. You can learn more about the other models available
Here.
Your
Webget
command will look something like this:
~webget <> data:<[data]> headers:<[headers]> save:response
in which, you use your save argument to get the
<entry[response].result>
result, which you can parse using a tag like
the yaml parsing tags.
You can use
<entry[response].failed>
to determine if the response failed, or not.
You can use
<util.parse_yaml[<entry[response].result>].get[choices].first.get[text]>
to return the response that resulted from the web request.
I've actually created a Denizen script that implements this into Discord using
dDiscordBot if you'd like a working example.
You should also find better help and support on our
Discord - my username is
@Hydra Melody#0001
if you have questions specifically about my script, but we can help you better there.
Hope this helps.
Edit: fixed my formatting, added a tiny bit more info