Life and Tech Talk

라마(LLAMA) 모델 사용법
  • 라마 설치 및 모델 다운로드
  • ollama 프로그램 설치
  • ollama 모델 다운로드: ollama pull 모델명
  • ollama 프로그램 실행: ollama run 모델명
  • 관련 Url: https://wikidocs.net/238531


  • 파이썬 사용 코드 (모델명: mistral, 답변형태: stream)
  • 'ollama run 모델명' sLLM local 실행 후, 파이썬에서 local sLLM 접속 하는 방식
  • url: http://localhost:11434/api/generate


import requests
import json


url = "http://localhost:11434/api/generate"
data = {
    "model": "mistral",
    "prompt": "Python에 대해 설명해줘.",
    "stream": True
}


response = requests.post(url, json=data, stream=True)


if response.status_code == 200:
    for line in response.iter_lines():
        if line:
            result = json.loads(line.decode('utf-8'))
            print(result["response"], end='', flush=True)
else:
    print("에러 발생:", response.status_code, response.text)
올린날: 2025년 3월 11일
주제: AI 뉴스 관련 포스팅 클릭!!

* 올린이: 마이클

* VIEW: 11       0           위키홈     게시판     수정