File tree Expand file tree Collapse file tree 3 files changed +73
-0
lines changed
Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ # AI Chat Bot
2+ It is an AI Chat bot that makes you use Chat GPT right from your console
3+
4+ # Getting API Key
5+
6+ Subscribe and Use the API Key from the link below
7+
8+ https://rapidapi.com/LightningDev/api/simple-chatgpt-api
9+
10+ # Installation & Run
11+ ` pip install -r requirements.txt `
12+
13+ ` python main.py `
14+
15+ # Screenshots
16+ ![ image.png] ( https://i.postimg.cc/X7cFsqBr/image.png )
Original file line number Diff line number Diff line change 1+ import requests
2+ import pyfiglet
3+ import itertools
4+ import threading
5+ import time
6+ import sys
7+
8+ url = "https://simple-chatgpt-api.p.rapidapi.com/ask"
9+
10+
11+ headers = {
12+ "content-type" : "application/json" ,
13+ "X-RapidAPI-Key" : "OUR API KEY" ,
14+ "X-RapidAPI-Host" : "simple-chatgpt-api.p.rapidapi.com"
15+ }
16+
17+ def animate ():
18+ for c in itertools .cycle (['|' , '/' , '-' , '\\ ' ]):
19+ if done :
20+ break
21+ sys .stdout .write ('\r ' + c )
22+ sys .stdout .flush ()
23+ time .sleep (0.1 )
24+
25+ # Clear the console output
26+ sys .stdout .write ('\r ' )
27+ sys .stdout .flush ()
28+
29+ def ask (question ):
30+ payload = { "question" : question }
31+ response = requests .post (url , json = payload , headers = headers )
32+ return response .json ().get ("answer" )
33+
34+ if __name__ == "__main__" :
35+ print (pyfiglet .figlet_format ("AI Chat BOT" ))
36+ print ("Enter the question to ask:" )
37+ print ()
38+ while True :
39+ # print("/>> ", end="")
40+ question = str (input (">> " ))
41+ if (question == 'q' ):
42+ print (">> Bye! Thanks for Using..." )
43+ break
44+ # loading
45+ done = False
46+ #here is the animation
47+ t = threading .Thread (target = animate )
48+ t .start ()
49+ answer = ask (question )
50+ time .sleep (5 )
51+ done = True
52+ t .join ()
53+ print (">> " ,answer )
54+ print ()
55+
Original file line number Diff line number Diff line change 1+ pyfiglet == 0.8.post1
2+ Requests == 2.31.0
You can’t perform that action at this time.
0 commit comments