Skip to content

Commit 0c4c3f9

Browse files
Initial commit - AI Chatbot project
0 parents  commit 0c4c3f9

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config.py
2+
.env

chat.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import requests
2+
import config
3+
4+
API_URL = "https://api.openai.com/v1/chat/completions"
5+
6+
def chat_with_ai(user_message):
7+
headers = {
8+
"Authorization": f"Bearer {config.API_KEY}",
9+
"Content-Type": "application/json"
10+
}
11+
12+
data = {
13+
"model": "gpt-4",
14+
"messages": [{"role": "user", "content": user_message}]
15+
}
16+
17+
response = requests.post(API_URL, json=data, headers=headers)
18+
19+
if response.status_code == 200:
20+
return response.json()["choices"][0]["message"]["content"]
21+
else:
22+
return f"Error: {response.status_code}, {response.text}"
23+
24+
# Greeting message
25+
print("Hi there! I am Markhor, the AI chatbot powered by ChatGPT-4, represented by Coding Moves.")
26+
print("How can I assist you today?\n")
27+
28+
# Example usage
29+
while True:
30+
user_input = input("You: ")
31+
if user_input.lower() in ["exit", "quit", "bye"]:
32+
print("Markhor AI: Goodbye! Have a great day.")
33+
break
34+
bot_response = chat_with_ai(user_input)
35+
print("Markhor AI:", bot_response)

0 commit comments

Comments
 (0)