soyailabs / add_exaone_with_token.py
SOY NV AI
feat: Parent Chunk ๆนฒ๊ณ•๋’ซ ็•ฐ๋ถฝ? ่ซ›?RAG ?์’–๋’ช??ๅช›์’–๊ฝ‘
d54e6a9
raw
history blame
5.97 kB
"""
EXAONE-3.0-7.8B-Instruct ๋ชจ๋ธ์„ Ollama์— ์ถ”๊ฐ€ํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ (ํ† ํฐ ํฌํ•จ)
"""
import os
import subprocess
from pathlib import Path
# Hugging Face ํ† ํฐ
HF_TOKEN = "YOUR_HUGGINGFACE_TOKEN_HERE"
def set_huggingface_token():
"""Hugging Face ํ† ํฐ ์„ค์ •"""
os.environ['HUGGINGFACE_HUB_TOKEN'] = HF_TOKEN
print(f"[OK] Hugging Face ํ† ํฐ ์„ค์ • ์™„๋ฃŒ")
def create_ollama_modelfile():
"""Ollama Modelfile ์ƒ์„ฑ"""
modelfile_content = f"""FROM huggingface:LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct
# ๋ชจ๋ธ ์„ค์ •
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER top_k 40
PARAMETER num_ctx 4096
PARAMETER num_predict 512
# ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ
SYSTEM \"\"\"You are EXAONE, a helpful AI assistant developed by LG AI Research.
You are designed to be helpful, harmless, and honest.
You can communicate in both Korean and English.\"\"\"
# EXAONE ๋ชจ๋ธ์˜ ์ฑ„ํŒ… ํ…œํ”Œ๋ฆฟ
TEMPLATE \"\"\"{{{{ if .System }}}}<|im_start|>system
{{{{ .System }}}}<|im_end|>
{{{{ end }}}}{{{{ if .Prompt }}}}<|im_start|>user
{{{{ .Prompt }}}}<|im_end|>
{{{{ end }}}}<|im_start|>assistant
{{{{ .Response }}}}<|im_end|>
\"\"\"
"""
modelfile_path = Path("EXAONE-3.0-7.8B-Instruct.modelfile")
modelfile_path.write_text(modelfile_content, encoding='utf-8')
print(f"[OK] Modelfile ์ƒ์„ฑ ์™„๋ฃŒ: {modelfile_path.absolute()}")
return modelfile_path
def create_model_with_modelfile(modelfile_path):
"""Modelfile์„ ์‚ฌ์šฉํ•˜์—ฌ Ollama ๋ชจ๋ธ ์ƒ์„ฑ"""
try:
print("\n" + "=" * 60)
print("Ollama ๋ชจ๋ธ ์ƒ์„ฑ ์‹œ์ž‘...")
print("=" * 60)
# ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •
env = os.environ.copy()
env['HUGGINGFACE_HUB_TOKEN'] = HF_TOKEN
# ollama create ๋ช…๋ น์–ด ์‹คํ–‰
cmd = ['ollama', 'create', 'EXAONE-3.0-7.8B-Instruct', '-f', str(modelfile_path)]
print(f"์‹คํ–‰ ๋ช…๋ น์–ด: {' '.join(cmd)}")
result = subprocess.run(
cmd,
env=env,
capture_output=True,
text=True,
timeout=3600 # 1์‹œ๊ฐ„ ํƒ€์ž„์•„์›ƒ
)
if result.returncode == 0:
print("[OK] ๋ชจ๋ธ ์ƒ์„ฑ ์„ฑ๊ณต!")
print(result.stdout)
return True
else:
print("[ERROR] ๋ชจ๋ธ ์ƒ์„ฑ ์‹คํŒจ")
print("์˜ค๋ฅ˜ ์ถœ๋ ฅ:")
print(result.stderr)
return False
except subprocess.TimeoutExpired:
print("[ERROR] ๋ชจ๋ธ ์ƒ์„ฑ ์‹œ๊ฐ„ ์ดˆ๊ณผ (1์‹œ๊ฐ„)")
return False
except Exception as e:
print(f"[ERROR] ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
return False
def check_ollama_installation():
"""Ollama ์„ค์น˜ ํ™•์ธ"""
try:
result = subprocess.run(['ollama', '--version'],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
version = result.stdout.strip()
print(f"[OK] Ollama ์„ค์น˜ ํ™•์ธ: {version}")
return True
else:
print("[ERROR] Ollama๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
return False
except FileNotFoundError:
print("[ERROR] Ollama๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
print(" ์„ค์น˜ ๋ฐฉ๋ฒ•: https://ollama.ai/download")
return False
except Exception as e:
print(f"[ERROR] Ollama ํ™•์ธ ์ค‘ ์˜ค๋ฅ˜: {e}")
return False
def verify_model():
"""์ƒ์„ฑ๋œ ๋ชจ๋ธ ํ™•์ธ"""
try:
result = subprocess.run(['ollama', 'list'],
capture_output=True, text=True, timeout=5)
if result.returncode == 0:
if 'EXAONE-3.0-7.8B-Instruct' in result.stdout:
print("\n[OK] ๋ชจ๋ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
print("\n์„ค์น˜๋œ ๋ชจ๋ธ ๋ชฉ๋ก:")
print(result.stdout)
return True
else:
print("\n[WARNING] ๋ชจ๋ธ์ด ๋ชฉ๋ก์— ๋‚˜ํƒ€๋‚˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.")
print("\nํ˜„์žฌ ์„ค์น˜๋œ ๋ชจ๋ธ:")
print(result.stdout)
return False
return False
except Exception as e:
print(f"[WARNING] ๋ชจ๋ธ ํ™•์ธ ์ค‘ ์˜ค๋ฅ˜: {e}")
return False
if __name__ == "__main__":
print("\n" + "=" * 60)
print("EXAONE-3.0-7.8B-Instruct Ollama ์ถ”๊ฐ€ ์Šคํฌ๋ฆฝํŠธ")
print("=" * 60 + "\n")
# ์‚ฌ์ „ ํ™•์ธ
if not check_ollama_installation():
print("\n[WARNING] Ollama๋ฅผ ๋จผ์ € ์„ค์น˜ํ•ด์ฃผ์„ธ์š”.")
exit(1)
# ํ† ํฐ ์„ค์ •
set_huggingface_token()
# Modelfile ์ƒ์„ฑ
modelfile_path = create_ollama_modelfile()
# ๋ชจ๋ธ ์ƒ์„ฑ ํ™•์ธ
print("\n[WARNING] ์ฃผ์˜์‚ฌํ•ญ:")
print("- ๋ชจ๋ธ ํฌ๊ธฐ๊ฐ€ ์•ฝ 15GB์ด๋ฏ€๋กœ ๋‹ค์šด๋กœ๋“œ์— ์‹œ๊ฐ„์ด ๊ฑธ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
print("- ์ถฉ๋ถ„ํ•œ ๋””์Šคํฌ ๊ณต๊ฐ„๊ณผ GPU ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
print("- Hugging Face์—์„œ ๋ชจ๋ธ ์•ก์„ธ์Šค ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
# ๋ชจ๋ธ ์ƒ์„ฑ ์‹œ์ž‘
print("\n๋ชจ๋ธ ์ƒ์„ฑ์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค...")
# ๋ชจ๋ธ ์ƒ์„ฑ
success = create_model_with_modelfile(modelfile_path)
if success:
verify_model()
print("\n" + "=" * 60)
print("[OK] ๋ชจ๋ธ ์ถ”๊ฐ€ ์™„๋ฃŒ!")
print("=" * 60)
print("\n์ด์ œ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
print("๋ชจ๋ธ ํ…Œ์ŠคํŠธ:")
print(" ollama run EXAONE-3.0-7.8B-Instruct \"์•ˆ๋…•ํ•˜์„ธ์š”\"")
print("=" * 60)
else:
print("\n" + "=" * 60)
print("[ERROR] ๋ชจ๋ธ ์ƒ์„ฑ ์‹คํŒจ")
print("=" * 60)
print("\n์ˆ˜๋™์œผ๋กœ ๋ชจ๋ธ์„ ์ƒ์„ฑํ•˜๋ ค๋ฉด:")
print(f" 1. Hugging Face ํ† ํฐ ์„ค์ •:")
print(f" $env:HUGGINGFACE_HUB_TOKEN='{HF_TOKEN}'")
print(f" 2. Modelfile๋กœ ๋ชจ๋ธ ์ƒ์„ฑ:")
print(f" ollama create EXAONE-3.0-7.8B-Instruct -f {modelfile_path}")
print("=" * 60)