Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3994a63

Browse files
Merge pull request avinashkranjan#2207 from Swapnil-Singh-99/AI_Chat_Bot
added ai chat bot
2 parents 6bceedc + ac35691 commit 3994a63

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

‎AI Chat Bot/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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)

‎AI Chat Bot/main.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+

‎AI Chat Bot/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyfiglet==0.8.post1
2+
Requests==2.31.0

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /