""" EXAONE-3.0-7.8B-Instruct를 Ollama에 직접 추가하는 스크립트 토큰을 사용하여 모델을 추가합니다. """ import os import subprocess import json import sys # 프로젝트 루트를 Python 경로에 추가 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) def get_huggingface_token(): """ Hugging Face 토큰 가져오기 (환경 변수 우선, 없으면 DB에서) Google API 키 관리 방식과 동일한 패턴 """ # 환경 변수에서 먼저 확인 token = os.getenv('HUGGINGFACE_HUB_TOKEN', '').strip() if not token: token = os.getenv('HF_TOKEN', '').strip() if token: print(f"[Hugging Face] 환경 변수에서 토큰 가져옴 (길이: {len(token)}자)") return token # DB에서 가져오기 (순환 참조 방지를 위해 여기서 임포트) try: from app.database import SystemConfig token = SystemConfig.get_config('huggingface_token', '').strip() if token: print(f"[Hugging Face] DB에서 토큰 가져옴 (길이: {len(token)}자)") return token except Exception as e: print(f"[Hugging Face] DB에서 토큰 조회 실패 (환경 변수 사용): {e}") return '' # Hugging Face 토큰 가져오기 HF_TOKEN = get_huggingface_token() if not HF_TOKEN: raise ValueError("HUGGINGFACE_HUB_TOKEN 또는 HF_TOKEN 환경 변수를 설정하거나, 관리 페이지에서 토큰을 설정해주세요.") def create_simple_modelfile(): """간단한 Modelfile 생성 (로컬 경로 대신 모델 이름만 사용)""" modelfile_content = """# EXAONE-3.0-7.8B-Instruct 모델 설정 # 참고: Ollama가 Hugging Face 모델을 직접 지원하지 않는 경우 # 다른 방법이 필요할 수 있습니다. PARAMETER temperature 0.7 PARAMETER top_p 0.9 PARAMETER top_k 40 PARAMETER num_ctx 4096 SYSTEM \"\"\"You are EXAONE, a helpful AI assistant developed by LG AI Research. You can communicate in both Korean and English.\"\"\" """ with open("EXAONE-3.0-7.8B-Instruct.modelfile", "w", encoding="utf-8") as f: f.write(modelfile_content) print("[OK] Modelfile 생성 완료") def check_model_availability(): """모델이 이미 설치되어 있는지 확인""" try: result = subprocess.run(['ollama', 'list'], capture_output=True, text=True, timeout=5) if 'EXAONE' in result.stdout or 'exaone' in result.stdout.lower(): print("[INFO] EXAONE 모델이 이미 설치되어 있습니다.") return True return False except Exception as e: print(f"[WARNING] 모델 확인 중 오류: {e}") return False def main(): print("\n" + "=" * 60) print("EXAONE-3.0-7.8B-Instruct Ollama 추가 시도") print("=" * 60) # 토큰 설정 os.environ['HUGGINGFACE_HUB_TOKEN'] = HF_TOKEN print(f"[OK] Hugging Face 토큰 설정 완료") # 모델 확인 if check_model_availability(): print("\n모델이 이미 설치되어 있습니다.") return print("\n현재 Ollama 버전에서는 Hugging Face 모델을 직접 가져올 수 없습니다.") print("\n다음 방법을 시도해보세요:") print("\n1. Ollama를 최신 버전으로 업데이트") print(" https://ollama.ai/download") print("\n2. 수동으로 모델 정보 확인") print(" 현재 Ollama 버전 확인: ollama --version") print(" 사용 가능한 모델 확인: ollama list") print("\n3. EXAONE 모델의 GGUF 버전 찾기") print(" Hugging Face에서 GGUF 형식의 모델을 찾아보세요.") print("\n" + "=" * 60) print("참고: 현재 Ollama 0.13.0은 Hugging Face 모델 직접 지원이 제한적입니다.") print("=" * 60) if __name__ == "__main__": main()