How to use the OpenAI Assistants API (Discord Bot Tutorial)

  Рет қаралды 7,356

Volo

Volo

Күн бұрын

Recently, OpenAI announced a new set of APIs and capabilities at the 2023 OpenAI DevDay. These include Custom GPTs, the GPT Store, Assistants API, and much more! I will be covering all of these concepts over the coming months.
In this hands-on tutorial we dive into how to use OpenAI's new Assistants API to create a GPT-powered Discord bot! Basically, using ChatGPT in Discord! In this video, I walk you through every step of integrating the powerful new OpenAI API with Discord using NodeJS and explain how does the new OpenAI Assistants API work. I will also cover the core concepts of the Assistants API so you can get started using it today!
This tutorial is designed to be accessible yet informative, perfect for both beginners and seasoned developers who want to explore the new capabilities of OpenAI's Assistants API and Discord bot development.
📚 Resources:
- GitHub Repo: github.com/VoloBuilds/openai-...
- OpenAI API Documentation: platform.openai.com/docs/assi...
- Discord Developer Portal: / discord
🔥 Key Highlights:
**Introducing OpenAI's Assistants API**: Deep dive of the the capabilities and features of the new OpenAI Assistants API.
**Key concepts of the new Assistants API**: Concepts include Assistants, Threads, and Runs. The OpenAI Files API will be covered in a future video.
NodeJS and Discord.js: Use the Discord.js library with Node to easily build a discord bot.
**Creating Real-Time AI Responses in Discord**: Learn how to implement real-time, context-aware responses using OpenAI within a Discord server.
**Environment Setup and API Configuration**: A step-by-step guide to setting up your development environment and configuring API keys securely.
**Code Walkthrough**: Detailed explanation of the source code to understand every component of the bot.
🚀 What You'll Learn:
- How the OpenAI Assistants API works
- Utilizing the OpenAI Assistants API with Discord
- Implementing AI in chatbots
- NodeJS application development
- Maintaining conversation context in Discord
- OpenAI state management through Assistant Threads
💡 Perfect for Viewers Interested in:
- AI-powered chatbots
- Building Discord bots
- OpenAI API applications
- Learning about the latest AI tech
- JavaScript and NodeJS development
- Real-time messaging applications
Subscribe for more tutorials on AI and programming and to stay up to date on the latest AI updates and news!!
💬 Questions or Feedback? Drop your thoughts in the comments below, and I'll be sure to get back to you!
#openai #devday #ChatGPT #ai #aicommunity #gpt #Gpt4 #OpenAIStore #DallE3 #ChatGPT4Turbo #OpenAIAssistants #OpenAIAgents #CustomGPT #OpenAIAPI #OpenAIDevDay #DiscordBot #NodeJS #JavaScript #AIChatbot #Discordjs #RealTimeChatbot #NodeJSBotDevelopment #OpenAITutorial #AIIntegration #ChatbotTutorial #TechTutorial #Coding #SoftwareDevelopment #AssistantsAPI
Chapters:
00:00 - Intro
00:41 - Project Setup
04:57 - Assistants API Concepts
07:45 - Using the new APIs
10:31 - Thread Handling
12:03 - Finishing the bot

Пікірлер: 82
@dd2834
@dd2834 6 ай бұрын
Just discovered your channel and subscribed - Will be going through your example myself to connect an Agent to Discord.
@VoloBuilds
@VoloBuilds 6 ай бұрын
Thanks for watching! Best of luck with your implementation!
@Queeny.photography
@Queeny.photography Ай бұрын
Thanks a lot! Followed all your instructions to the T after failing and wasting time checking out other blogs and tutorials. You Rock! I have my own custom bot installed now. Wondering if you made a video on the sessions / user / thread database storage? I would love to be able to accomplish that now. Thanks again!
@VoloBuilds
@VoloBuilds Ай бұрын
That's awesome! Glad it was helpful! :) I haven't made that follow-up and probably won't at this point so it's a good opportunity to challenge your skills and expand on this code!
@bleak183
@bleak183 5 ай бұрын
I've been waiting for someone to make a video like this!! do you have a discord server?
@VoloBuilds
@VoloBuilds 5 ай бұрын
Glad you enjoyed it! I don't but that's a great idea, so I'll be making one in the coming weeks! :)
@onedaytimewin
@onedaytimewin 6 ай бұрын
fire tutorial, thank you
@VoloBuilds
@VoloBuilds 6 ай бұрын
Thank you!! 😄
@nosult3220
@nosult3220 6 ай бұрын
I made a discord bot with mistral 7B (using a drop in for the open ai code) yes this makes it so much easier with the threads
@VoloBuilds
@VoloBuilds 6 ай бұрын
Nice!! I'd love to see an open source version of these abstractions. They make a lot of sense to me. Perhaps LangChain will pivot towards this? Or perhaps someone will build something new? Good opportunity here
@Suushidesu
@Suushidesu 4 ай бұрын
wow this was such a good to follow tutorial, any plans for another one that shows how to incorporate a seperate database like an obsidian vault that the AI can use for thread pointers? im really excited to implement this into my server but im so scared to have everyone bond with it only to lose its context every reload/reboot
@VoloBuilds
@VoloBuilds 4 ай бұрын
Thank you so much! That is a good point - and I've heard other concerns too which relate to not being able to send multiple messages at the same time. I didn't have plans to make a second one yet, but will have to think about it :)
@Suushidesu
@Suushidesu 4 ай бұрын
@@VoloBuilds right! We've been experimenting on that other problem by including something like "# user:name" in every message a human sends in the server but that's not a long term solution anyway unless that's automated. Anyway I appreciate your response and am keeping my eye on your channel for updates on this and your other projects c:
@Suushidesu
@Suushidesu 4 ай бұрын
@@VoloBuilds some progress was made and since this tutorial started the whole endeavour i figured id give a little update: for longterm context we now have the bot write locally to a thread pointer file, which contains the id for the discord channel and links it to specific threads.! It works really well and its now reboot and crash proof 🙏 thanks again volo. I really appreciate what you tought us!
@VoloBuilds
@VoloBuilds 4 ай бұрын
Hey that's a really good idea@@Suushidesu! Yeah I think a local file is a perfectly good solution - especially if you don't have like thousands of users or something. If it got too high, you could start to use a distributed database, but I love that you chose a less complicated solution first! Glad to hear your project is going well!
@dylanbritz1333
@dylanbritz1333 6 ай бұрын
This video helped a lot thanks man! Can you make a tutorial on how to upload files and access them as well?
@VoloBuilds
@VoloBuilds 6 ай бұрын
Glad it was helpful!! Yes! This is one of the videos I plan to create in the near future :)
@dylanbritz1333
@dylanbritz1333 6 ай бұрын
@@VoloBuilds Awesome I can't wait! I have files uploaded to the Assistant ID I used for this bot, but for some reason every time I create a prompt to access the files, the bot can't access all of the files and it takes forever to respond. I did manage to create split messages in my code tho which is pretty cool, when the bot gets close to a 2000 characters it's splits the message in 2
@VoloBuilds
@VoloBuilds 6 ай бұрын
@@dylanbritz1333 Sounds like I'm in for some deep exploration working with the files then lol! Hey that's a brilliant idea with the message split! Would be happy to merge into my repo if you want to make a PR ;)
@dylanbritz1333
@dylanbritz1333 6 ай бұрын
@@VoloBuildsI'd be honored to! But by implementing that solution I encountered another problem, every time I give the bot a message it responds with 2 messages 🥲 I'm still pretty much a rookie when it comes to coding but ChatGPT has been a massive help 😂
@VoloBuilds
@VoloBuilds 6 ай бұрын
Haha yes ChatGPT can be such a great way to learn this stuff! If you do get it working, feel free to open that PR!
@satchserra89
@satchserra89 4 ай бұрын
Great tutorial!! My assistant works great on my server! idk ANYTHING about coding and was able to get it up and running! That being said, i am now stuck on something 😂Im running this out of vscode on my desktop and was wondering if theres a way to have it work without my pc being on.
@VoloBuilds
@VoloBuilds 3 ай бұрын
That's awesome!! Glad you were able to get it working! I would look into Replit as a potential platform for more or less easily deploying/hosting a bot like this!
@Queeny.photography
@Queeny.photography Ай бұрын
Is Replit better than Google Cloud? I am also a newbie and don't know much about this. I want to create a database for the sessions and threads as well. @@VoloBuilds
@jagatla_vyakti
@jagatla_vyakti 6 ай бұрын
Once GPT store is live please make a video on GPT store and how to create custom GPT, love from india
@VoloBuilds
@VoloBuilds 6 ай бұрын
Absolutely! OpenAI actually unlocked custom GPT creation for everyone yesterday so (even though the store doesn't exist yet) so I'll be building a custom GPT in one of my next couple of videos! Thanks for watching!
@chriswilke9197
@chriswilke9197 5 ай бұрын
Could do a similar video or plugin for Slack? This was a great tutorial. Thank you!
@VoloBuilds
@VoloBuilds 5 ай бұрын
Great suggestion - I got a few more videos planned out currently but will add this to the idea list! Thanks for watching!
@patherren3487
@patherren3487 2 ай бұрын
@@VoloBuilds I'm gonna second this comment. A slack integration would be extremely helpful within the business!
@draganpetrov9594
@draganpetrov9594 6 ай бұрын
Hi Volo, do you do custom work? Freelancing
@VoloBuilds
@VoloBuilds 6 ай бұрын
I do! Send me an email at volobuilds1 @ gmail and we can talk details
@Fellendorf85
@Fellendorf85 6 ай бұрын
🔥🔥🔥🔥🔥
@VoloBuilds
@VoloBuilds 6 ай бұрын
😄 Thank you and glad you enjoyed!
@Fellendorf85
@Fellendorf85 6 ай бұрын
@@VoloBuilds Thank you!!!
@stevens3966
@stevens3966 4 ай бұрын
Hi! thanks for the tutorial, I got the bot working! I didn't implement the changes after 17:20, but the bot seems to be working fine without it. am I missing something?
@VoloBuilds
@VoloBuilds 4 ай бұрын
I think the bot can work without those changes but depending on what you wrote, you might be missing the relevant context of the full thread. I linked the code in the description, so you could check it out there if you're still not sure!
@stevens3966
@stevens3966 4 ай бұрын
your github code worked straight away so i ended up using that anyway :) @@VoloBuilds
@GamesBrendanPlays
@GamesBrendanPlays 5 ай бұрын
Hey! So I was able to get a discord bot going real quick, but the bot shuts down if there are two requests sent before it answers the first one. Is there an easy way to fix this?
@VoloBuilds
@VoloBuilds 5 ай бұрын
Oh that's interesting - I wonder why that would happen.. If you don't mind, could you open an issue on GitHub with the details of what you're seeing? I could take a look then and see if I can reproduce it!
@kordou
@kordou 6 ай бұрын
Hi thank fo the tutorial but you can not folow this tutorial. at the poin that create the bot on discord, there is a missing step and you cannot get the url. Solution that i tried is to add aa Redirect URL in the AUTH 2 to a localhost url but then when you try to link the bot with the server the link does not exist so the not never goes into the server, any solution ?
@VoloBuilds
@VoloBuilds 6 ай бұрын
Not sure what you mean exactly. Will try to clarify the steps: 1. Go to discord.com/developers/applications/ 2. Create app (assuming you got this already done) 3. Check all 3 "Privileged Gateway Intents" boxes in the Bot tab 4. Go to Oauth2 > URL Generator 5. Check the "bot" box (perhaps this is most likely the step you missed?) 6. URL should appear at the bottom of the page. This URL is the URL you can use to invite the bot to your server 7. Go to that URL in the browser and add the bot to your server Where specifically in this flow are you encountering the issue?
@kordou
@kordou 6 ай бұрын
@@VoloBuilds thanks for the responce. I am doing exactly that but at least in my discord the lest step where getting the URL does not give a url and you cannot press the save button .
@VoloBuilds
@VoloBuilds 6 ай бұрын
@@kordouHmm that is strange indeed. Seems like a discord problem, maybe with your account? I don't have turbo or anything so I don't think it's that.. Maybe some weird ad block thing? If you want me to take a closer look, please open a github issue with a video attached of what you see when trying to create the discord URL!
@illya_ike
@illya_ike Ай бұрын
I'm not sure I get how Discord accesses your bot which, from what I understand, is running on your local machine. Could you please clarify this point?
@illya_ike
@illya_ike Ай бұрын
Got it - your bot keeps opened connection with the Discord server - this way it can handle requests.
@Fever_Dreams_
@Fever_Dreams_ 5 ай бұрын
This was working great for me, but I changed the OpenAI API key, and the program isn't seeing the new key. It tries to use the old one, which is rejected every time because it's been deleted. Any idea how to fix this?
@VoloBuilds
@VoloBuilds 5 ай бұрын
Hey there - where are you running the code? If you deployed it to a cloud service or something make sure the env change is present there as well. Either way, make sure to restart the application after making .env changes for them to take effect
@stevens3966
@stevens3966 4 ай бұрын
One more question, do you have a tutorial to upload files to my assistance API and train it that way?
@VoloBuilds
@VoloBuilds 4 ай бұрын
Yep, I do! kzbin.info/www/bejne/gKvbhopmj7lnqtE the intro is a bit quirky as I got carried away being creative 😅 but I go over the files API in there!
@stevens3966
@stevens3966 4 ай бұрын
@@VoloBuilds thanks for your help! i am trying to develop a billing system for my Assistant, but I can't figure out how to get a cost breakdown per Assistant, it just shows a cost breakdown per model. It does show the number of queries per assistant, but not the number of tokens. this seems rather deficient! how would you approach this problem Volo?
@VoloBuilds
@VoloBuilds 4 ай бұрын
@@stevens3966 I think this is a limitation of what OpenAI makes available unfortunately. The closest work around I can think of is to add your own logic to count tokens in your code - maybe using something like this: www.npmjs.com/package/@dqbd/tiktoken It's not perfect though because you then have to count input/output separately and do the math on the rate, and you have no visibility into how many tokens it used for retrieving data and such. Maybe it's in the API response json? Not trivial for sure! Let me know if you figure something good out
@stevens3966
@stevens3966 4 ай бұрын
will do@@VoloBuilds! thanks for the response. i am actually looking at mistral ai as a cheaper alternative. also changing to the cgpt 3.5 1160 model helps to save money.
@CanuteTang
@CanuteTang 2 ай бұрын
Hi Volo, I have create a discord bot, and used your openAI assistant code. Also I upload my knowledge base for it. But it seems have a large usage, just 2~3 questions, 1 $ used....Is that normal?
@VoloBuilds
@VoloBuilds 2 ай бұрын
That seems likely to be related to the knowledge base size. They have the cost for that published and it's kind of confusing. $1 for 2-3 questions seems high unless you have this thing pumping out a huge amount of output
@CanuteTang
@CanuteTang 2 ай бұрын
@@VoloBuilds thanks for your feedback! Very helpful! I did upload a huge knowledge base, even in ppt and picture formats, and I thought I should simplify them? Because every question means searching this huge knowledge base, right?
@VoloBuilds
@VoloBuilds 2 ай бұрын
@@CanuteTang Cleaning up the data before loading is definitely recommended! Both for accuracy and cost purposes. It'll make it easier for the model to find what it needs to use it. The entire knowledge base is not passed into each prompt and the specifics of OpenAI's retrieval approach are not public, but the simple way to think about it is -> more data = more cost, messier data = more cost
@101thornangel
@101thornangel 3 ай бұрын
Is there any way to limit the amount of token usage?
@VoloBuilds
@VoloBuilds 3 ай бұрын
You would need to implement this in your backend server logic - probably by adding a token counter and then tracking overall usage in your DB. OpenAI has been improving this side of things though so I wouldn't be surprised if they add a native feature to do this in their platform at some point!
@RichardGetzPhotography
@RichardGetzPhotography 5 ай бұрын
Very nice. Thank you for sharing. I send you an email from Getz AI. Look forward to speaking with you.
@VoloBuilds
@VoloBuilds 5 ай бұрын
Glad you enjoyed the video and thanks for reaching out!!
@arealicehole
@arealicehole 4 ай бұрын
how do i go from flowise to discord
@VoloBuilds
@VoloBuilds 4 ай бұрын
I actually have not used flowise myself, just seen tutorials on it from other creators. This tutorial is working with discord directly, so no need to involve flowise. Looks like this tutorial connects discord and Flowise though: kzbin.info/www/bejne/aJLHp3aHnJiHmcU&ab_channel=DerekCheung
@iffatarabrishti1623
@iffatarabrishti1623 3 ай бұрын
why i am not seeing any server while creating a bot in discord??
@VoloBuilds
@VoloBuilds 3 ай бұрын
If you're talking about a discord server, you need to create one first - those servers are basically communities you can create. If you're talking about the code shown in this tutorial, you would be running it on your local computer which is effectively acting as a server, but to make it work "in production" you'd need to deploy the code somewhere like Replit
@zaregotoch.8491
@zaregotoch.8491 10 күн бұрын
nodemon bot command does not work
@VoloBuilds
@VoloBuilds 7 күн бұрын
Sorry to hear that - what seems to be the issue? Since I can't troubleshoot directly, I've found ChatGPT pretty good at pointing me in the right direction with error messages and such, so I would suggest that
@jhuneatienza7160
@jhuneatienza7160 5 ай бұрын
Yo bud, why is the bot echoing (repeats what I say)
@VoloBuilds
@VoloBuilds 5 ай бұрын
I'm not sure how you have it configured, but perhaps you are using some simplified version of the code without the assistants API hooked up to it? The code posted here (github.com/VoloBuilds/openai-assistants-discord-bot/blob/main/bot.js) should not do that, unless your assistant is configured to repeat whatever is said to it!
@PabloFM27
@PabloFM27 5 ай бұрын
gm Volo I would like to have your help for a role game on the metaverse :D, how can I contact you? Love what you do
@VoloBuilds
@VoloBuilds 5 ай бұрын
Hey there Pablo! Sounds pretty cool :) you can get my email on my channel about page: www.youtube.com/@VoloBuilds/about
@Fever_Dreams_
@Fever_Dreams_ 5 ай бұрын
​@@VoloBuildsI can't see your email on that page.
@jayakrishnanp5988
@jayakrishnanp5988 5 ай бұрын
🌟🌟🌟🌟🌟 Hey buddy Make more exploration in the application of threads and on placing assistants api calls within code when each assistant can run separate parallel threads to completion of any given task and thus Enhance a current simple architectural design of any utility applications around ❤ Note 🌀🌀🌀 Threads videos are not much in KZbin for the people to explore and learn And you are amazing teacher too 🫵🫡🫡🫡🖖 🌍
@VoloBuilds
@VoloBuilds 5 ай бұрын
Thank you so much!! Really appreciate your ideas!
Add Flowise to ANYTHING! Flowise API Crash Course
28:17
Leon van Zyl
Рет қаралды 10 М.
YouTube's Biggest Mistake..
00:34
Stokes Twins
Рет қаралды 75 МЛН
Glow Stick Secret 😱 #shorts
00:37
Mr DegrEE
Рет қаралды 134 МЛН
Teenagers Show Kindness by Repairing Grandmother's Old Fence #shorts
00:37
Fabiosa Best Lifehacks
Рет қаралды 42 МЛН
OpenAI Assistants API Tutorial - Playground & NodeJS
17:47
Leon van Zyl
Рет қаралды 26 М.
How to Use OpenAI's ChatGPT API in JavaScript
7:32
Kodaps Academy
Рет қаралды 1,9 М.
Transform Your DnD Adventures with a Custom GPT
20:58
Tingenuity AI
Рет қаралды 2 М.
GPTs vs Assistants API - which one is best for you?
13:09
ChatGPT Can Now Talk Like a Human [Latest Updates]
22:21
ColdFusion
Рет қаралды 477 М.
OpenAI API Open-Source Alternative: LocalAI
13:52
Semaphore CI
Рет қаралды 10 М.
Prompt Engineering Tutorial - Master ChatGPT and LLM Responses
41:36
freeCodeCamp.org
Рет қаралды 1,3 МЛН
How does OpenAI Sora actually work?
18:18
Volo
Рет қаралды 6 М.
Is Learning To Code Still Worth It in 2024?
8:53
Volo
Рет қаралды 186 М.
Распаковка айфона в воде😱 #shorts
0:25
Mevaza
Рет қаралды 1,6 МЛН
IPad Pro fix screen
1:01
Tamar DB (mt)
Рет қаралды 3,2 МЛН
Я Создал Новый Айфон!
0:59
FLV
Рет қаралды 3,7 МЛН
Introducing GPT-4o
26:13
OpenAI
Рет қаралды 4,2 МЛН