Skip to content

Commit 3bc2658

Browse files
committed
linted with black and checked with flake8
1 parent fd634a9 commit 3bc2658

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

aibot/AIbot.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,52 @@
88
# Configure the API key for the Gemini model
99
api_key = os.environ.get("GEMINI_API_KEY")
1010
if not api_key:
11-
raise ValueError("API key not found! Ensure GEMINI_API_KEY is set in the environment variables.")
11+
raise ValueError(
12+
"API key not found! Ensure GEMINI_API_KEY is "
13+
"set in the environment variables."
14+
)
1215

1316
genai.configure(api_key=api_key)
1417

1518
# Initialize the Generative Model
1619
model = genai.GenerativeModel("gemini-1.5-flash")
1720

21+
1822
def generate_response(user_input):
1923
"""
20-
This function interacts with the Gemini model to generate creative and intelligent responses.
21-
24+
This function interacts with the Gemini model
25+
to generate creative and intelligent responses.
26+
2227
:param user_input: The user's input to the chatbot.
2328
:return: A response generated by the AI.
2429
"""
2530
try:
26-
# Generate content based on the user input
2731
response = model.generate_content(user_input)
28-
return response.text if response else "Sorry, I couldn't generate a response."
32+
return (
33+
response.text
34+
if response
35+
else "Sorry, I couldn't generate a response."
36+
)
2937
except Exception as e:
3038
return f"An error occurred: {e}"
3139

40+
3241
def chatbot():
3342
"""
3443
Main function to handle continuous interaction with the chatbot.
3544
It allows the user to ask anything from blog posts to code explanations.
3645
"""
3746
print("🚀 Welcome to the most amazing AI Bot! 🌟")
38-
print("💬 You can ask me anything from writing blog posts, to explaining code, to creative writing.\n")
47+
print(
48+
"💬 You can ask me anything from writing blog posts, "
49+
"to explaining code, to creative writing.\n"
50+
)
3951
print("✨ Just type 'exit' anytime to quit.\n")
4052

4153
while True:
4254
# Get user input
4355
user_input = input("You: ")
44-
56+
4557
# Check for exit condition
4658
if user_input.lower() == "exit":
4759
print("👋 Goodbye! Thanks for chatting!")
@@ -51,6 +63,7 @@ def chatbot():
5163
ai_response = generate_response(user_input)
5264
print(f"AI Bot: {ai_response}\n")
5365

66+
5467
if __name__ == "__main__":
5568
# Run the chatbot
5669
chatbot()

0 commit comments

Comments
 (0)