[Custom API] ChatGPT - chat with your friend Nightbot!

Hiya!
Saw a post here about asking for a ChatGPT command and thought that was a fun and good idea!
I’ve put something quickly together, not very well tested, but aye, throw some questions at it and let me know if it breaks.

Everytime you call this api it’s considered a new conversation. You will receive a hastag and a code and the end of every message. This is a reference to your personal conversation.
Use this hashtag and code as first part of a new message to continue the conversation.

See example below:

Automatic installation:
Visit xgpt.gerhard.dev/dashboard and sign in with Nightbot to install this command with just a click.

When you sign in to our dashboard you will be able to customize settings for your personal AI chatbot. Give the bot more and detailed instructions for just your stream. Provide attional information about you or your stream, so the bot can answer more specific questions. Want the bot to speak in a certain language, a certain way, include emojis, be more funny? Endless opportunities and alot of fun!

You’ll also be able to use your own OpenAI API key to avoid monthly limits, which we highly recommend!

Manual installation:

$(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring))

Example command you can add:

!commands add !ai -cd=5 $(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring))

Questions? Just let me know, enjoy!


The code for this command is available on Github, want to improve or suggest anything, feel free to submit it there: GitHub - xgerhard/XGPT: Use Nightbot as AI chatbot powered by ChatGPT


This service is free to use, however the OpenAI API does cost money based on the amount of requests made. While it’s fun to see more people using this command, this does increase the monthly bill. If you like this command and want to support this project, consider helping with these monthly costs or buy me a beer with a one-time contribution: Sponsor @xgerhard on GitHub Sponsors · GitHub

11 Likes

I have it installed and working. Neat little code thanks for the effort. Now I can discover all the secrets of the Universe.

Thanks for trying it out! If you find something important, I hope you let me know :wink:

Will do I haven’t unleashed on my followers yet but they will give it a good run through

1 Like

Out of interest what is the # at the end of an answer?

The hashtag and numbers lets you continue the conversation with the chatgpt bot. Otherwise each time you talk to it would be a unique interaction. But if you use the hashtag amd numbers it picks up the convesation where you left off.

Gehard posted example images of that use.

2 Likes

great custom api! I’ve integrated this into my chat as well. Is there anyway to bake in a character limit? or at least force nightbot to not send multiple long messages in the chat? Maybe over a certain length it can go to a whisper? Just a suggestion. I think it’s awesome though!

1 Like

Hiya, thanks for trying it out! Replying to whisper is not an option. As explained in the first post, if you want shorter responses you can specify it in your message, for example: “explain pi in 100 characters”.

how can i add it on my twitch channel everyone seems to know how to do it but i don’t can you guys help me?

Hey everyone, and more specifically @drmadness112!

EDIT: the API has been updated, and the following message is no longer up-to-date, you don’t need to add the extra string to “fix” the command, so feel free to disregard this message, leaving it up for posterity/context.

If you want to make ChatGPT (attempt to) shorten its answers without having to write it in every time, so it doesn’t cut the message with ellipsis, you can edit the command as such:

!editcom !xgpt $(urlfetch https://xgpt.gerhard.dev/api/command?q=$(querystring)%20answer%20in%20150%20characters%20or%20less)

It adds the following string to your request for every command call: “answer in 150 characters or less.”
I limited to 150 characters because I noticed that it seems to cuts the message at around 165 characters.
:warning: It works fairly well, but there are still mishaps sometimes.

Hey @1denik!

xgerhard already gave an example on how to do it in their introduction post:

Simply copy/paste the !commands add ... in your chat (it’ll only work if you already added Nightbot to your chat).

If you rather add the command through the dashboard, give the command a name, for example !xgpt, and copy/paste that bit in the Message field:

1 Like

I have really been hammering on this and outside of a few cannot reach external server errors it has been a blast. I am wondering if it is possible to make a call to xgpt from another script. I was hoping to have it recognize an input from the sending action…

[This Code I Have]
$(user), You drew $(eval responses=[The Fool!,The Magician!,The High Priestess!,The Empress!,The Emperor!,The Hierophant!,The Lovers!,The Chariot!,Justice!,Strength!,The Hermit!,Wheel of Fortune!,The Hanged Man!,Death!,Temperance!,The Devil!,The Tower!,The Star!,The Moon!,The Sun!,Judgement!,The World!];responses[Math.floor(Math.random()*responses.length)])

User:!tarot
Nightbot $(user) you chose ‘INSERT-CARD-NAME-HERE’
[Alias Call Here]
This is where I am confused how to pass of the results of command a to another command called from the !alias

[This is the code I am looking to Create]
Ex: !xgpt What is the meaning of INSERT-CARD-NAME-HERE in Tarot?
(Getting the input from !tarot results)

Nightbot: xgtp: INSERT-CARD-NAME-HERE in Tarot means Blah Blah Blah

What I am imagining is creating an in between command at the End of the Tarot command and then handing that off to xgtp? I am just lost at where to start.

Thanks for any help - JTS

Hey @Jeffrey_TheSeer!

An alias overrides the output of the first command, so what you’re trying to do is not possible.
And using an AI to pull the meaning of the cards could be a bit excessive, what makes me say that is that you already made a similar topic that has a better/simpler/easier solution in my opinion.

1 Like

Thank you for this Emily! Could I adjust that 150 value to 350, or whatever my own character limit is? And I’d do what you did and dial it back just before that limit as well.

Thanks

Yeah you can adjust to your preference. Character limit is 400, minus the username and conversation ID, so 350 should work.

EDIT: the API has been updated, and the following message is no longer up-to-date, you don’t need to add the extra string to “fix” the command, so feel free to disregard this message, leaving it up for posterity/context.

From my experience, the output is cut short with ellipsis at 165 characters, regardless of the platform limit, I’m really not sure why.
But if you want to increase it to 350, I highlighted the number you’d need to edit:

1 Like

Thanks for testing this! I now send an extra message with every request: “answer in X characters or less”.
So this extra part should not be needed anymore, but everyone can choose their own character limits ofcourse.

I put an X, since I dont have the exact number yet, I’m playing around with this number and a max_tokens value I can send to the ChatGPT API, which is their sort of way of counting words/characters. Trying to find the sweet spot between not reaching timeout limits for Nightbot, and also not sending cut off responses.
So please try it out, and let me know your findings. If responses are cut off frequently or commands are timing out I can adjust these numbers.

2 Likes

First of all congratulations on the api and thank you very much.

Since a few hours nightbot always responds “ChatGPT took to long to respond. Please try again in a bit. ResidentSleeper”

Hiya, saw you posted this messages a couple hours ago, I updated the api (see message above) after that which should hopefully fix most of these timeout messages.

It’s been working perfectly for a few hours. It does not show the error of “Error Connecting To Remote Server” or “ChatGPT took to long to respond. Please try again in a bit. ResidentSleeper”
Thank you!

1 Like