Spaces:
Runtime error
Runtime error
Download ai_module.py from DjAbRaIlLL/tg-bot: direct link, hf CLI and curl.
- Browser
- Download file 902 Bytes
-
https://huggingface.co/spaces/DjAbRaIlLL/tg-bot/resolve/main/ai_module.py
- Command line
-
hf download hf://spaces/DjAbRaIlLL/tg-bot/ai_module.py
-
curl -L -o ai_module.py https://huggingface.co/spaces/DjAbRaIlLL/tg-bot/resolve/main/ai_module.py
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=[]) |