- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Building AI chatbot
Build an AI chatbot using gemini AI
#chatbot.py
import os
from google import genai
from dotenv import load_dotenv
load_dotenv()
api_key = os.environ.get("GEMINI_API_KEY")
#print(api_key)
if not api_key:
print("ERROR: 'GEMINI_API_KEY' not found. Please check your .env file.")
exit()
def run_chatbot():
print("--- Gemini Chatbot Initialized ---")
print("Model: gemini-2.5-flash")
print("Ask me anything! Type 'exit' to end the conversation.")
print("-" * 35)
try:
client = genai.Client()
model_name = "gemini-2.5-flash"
except Exception as e:
print(f"Failed to initialize the Gemini client. Error: {e}")
return
while True:
user_question = input("Ask: ")
if user_question.lower() in ['exit', 'quit']:
print("Chatbot: Goodbye!")
break
if not user_question:
continue
try:
response = client.models.generate_content(
model=f"models/{model_name}",
contents=[user_question]
)
if response and response.candidates:
answer = response.candidates[0].content.parts[0].text
print(f"Gemini: {answer}") # Print the extracted answer.
else:
print("Gemini: I am unable to provide a response at this time.")
except Exception as e:
print(f"An error occurred during Gemini AI analysis: {str(e)}")
break
if __name__ == "__main__":
run_chatbot()
Видео Building AI chatbot канала SQL Depository
#chatbot.py
import os
from google import genai
from dotenv import load_dotenv
load_dotenv()
api_key = os.environ.get("GEMINI_API_KEY")
#print(api_key)
if not api_key:
print("ERROR: 'GEMINI_API_KEY' not found. Please check your .env file.")
exit()
def run_chatbot():
print("--- Gemini Chatbot Initialized ---")
print("Model: gemini-2.5-flash")
print("Ask me anything! Type 'exit' to end the conversation.")
print("-" * 35)
try:
client = genai.Client()
model_name = "gemini-2.5-flash"
except Exception as e:
print(f"Failed to initialize the Gemini client. Error: {e}")
return
while True:
user_question = input("Ask: ")
if user_question.lower() in ['exit', 'quit']:
print("Chatbot: Goodbye!")
break
if not user_question:
continue
try:
response = client.models.generate_content(
model=f"models/{model_name}",
contents=[user_question]
)
if response and response.candidates:
answer = response.candidates[0].content.parts[0].text
print(f"Gemini: {answer}") # Print the extracted answer.
else:
print("Gemini: I am unable to provide a response at this time.")
except Exception as e:
print(f"An error occurred during Gemini AI analysis: {str(e)}")
break
if __name__ == "__main__":
run_chatbot()
Видео Building AI chatbot канала SQL Depository
Комментарии отсутствуют
Информация о видео
17 марта 2026 г. 21:22:13
00:12:13
Другие видео канала




















