Chatbot AI Python
Posted by: fatners | Language: python | Views: 26 | Posted at: 4/11/2026, 11:22:05 AM
import requests
import pyfiglet
import itertools
import threading
import time
import sys
url = "https://simple-chatgpt-api.p.rapidapi.com/ask"
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "OUR API KEY",
"X-RapidAPI-Host": "simple-chatgpt-api.p.rapidapi.com"
}
def animate():
for c in itertools.cycle(['|', '/', '-', '\\']):
if done:
break
sys.stdout.write('\r' + c)
sys.stdout.flush()
time.sleep(0.1)
# Clear the console output
sys.stdout.write('\r')
sys.stdout.flush()
def ask(question):
payload = {"question": question}
response = requests.post(url, json=payload, headers=headers)
return response.json().get("answer")
if __name__ == "__main__":
print(pyfiglet.figlet_format("AI Chat BOT"))
print("Enter the question to ask:")
print()
while True:
# print("/>> ", end="")
question = str(input(">> "))
if (question == 'q'):
print(">> Bye! Thanks for Using...")
break
# loading
done = False
# here is the animation
t = threading.Thread(target=animate)
t.start()
answer = ask(question)
time.sleep(5)
done = True
t.join()
print(">> ", answer)
print()Cepetin
Platform tools online untuk file, gambar, dokumen, dan link sharing yang bisa diakses langsung dari browser.
Hubungi Kami
Email: [email protected] Telepon: +62 878-4437-2263 Cepetin adalah platform all-in-one untuk tool file converter, short URL, dan utilitas produktivitas digital.
Copyright Notice
Cepetin adalah platform tools online independen. Merek dagang, logo, dan nama brand milik pemiliknya masing-masing. Konten yang dibuat atau dibagikan pengguna menjadi tanggung jawab pengguna, dan laporan pelanggaran hak cipta dapat dikirim melalui halaman Report Content / DMCA .
© 2026 Cepetin. Hak cipta dilindungi.