Spaces:
Sleeping
Sleeping
| import os | |
| import google.generativeai as genai | |
| import os, sys | |
| current_dir = os.path.dirname(os.path.abspath(__file__)) | |
| project_root = os.path.abspath(os.path.join(current_dir, '..', '..')) | |
| sys.path.append(project_root) | |
| from support import get_key | |
| api_key = get_key.get_random_api_key() | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | |
| genai.configure(api_key=api_key) | |
| async def response_general(input:str)->str: | |
| api_key = get_key.get_random_api_key() | |
| genai.configure(api_key=api_key) | |
| generation_config = { | |
| "temperature": 1, | |
| "top_p": 0.95, | |
| "top_k": 40, | |
| "max_output_tokens": 8192, | |
| "response_mime_type": "text/plain", | |
| } | |
| model = genai.GenerativeModel( | |
| model_name="gemini-2.0-flash", | |
| generation_config=generation_config, | |
| ) | |
| chat_session = model.start_chat( | |
| history=[ | |
| { | |
| "role": "user", | |
| "parts": [ | |
| f"""Bạn vui lòng phản hồi lại câu chào hỏi dưới đây với giọng điệu thận trọng cẩn thận nhắc nhở người dùng rằng những câu hỏi này sẽ không được phép trả lời. | |
| Bạn hãy xử lý câu hỏi sau và trả lại cho mình kết quả: {input}. | |
| Vui lòng chỉ trả lời theo đúng yêu cầu mình đưa ra. Không được phép trả lời ngoài lề. """, | |
| ], | |
| } | |
| ] | |
| ) | |
| response = chat_session.send_message("Vui lòng chỉ phản hồi lại cho mình câu trả lời, không cần giải thích gì thêm") | |
| return response.text | |