tg-bot / ai_module.py
DjAbRaIlLL's picture
Create ai_module.py
1c3b084 verified
Raw History Blame Contribute Delete
902 Bytes
import google.generativeai as genai
import warnings
from config import GOOGLE_API_KEY, MODEL_NAME
warnings.filterwarnings("ignore", category=FutureWarning)
genai.configure(api_key=GOOGLE_API_KEY)
# Настройки для универсального ИИ (как Gemini)
generation_config = {
"temperature": 0.9,
"top_p": 0.95,
"max_output_tokens": 8192,
}
model = genai.GenerativeModel(
model_name=MODEL_NAME,
generation_config=generation_config
)
chat_sessions = {}
def get_chat_response(user_id, text):
if user_id not in chat_sessions:
chat_sessions[user_id] = model.start_chat(history=[])
try:
response = chat_sessions[user_id].send_message(text)
return response.text
except Exception as e:
return f"Ошибка ИИ: {str(e)}"
def clear_chat_history(user_id):
chat_sessions[user_id] = model.start_chat(history=[])