Ollama_사용

Eugenius1st·2026년 10월 6일

Ollama

목록 보기
2/2
post-thumbnail

유용한 관리 명령어

실습 중 모델을 교체하거나 정보를 확인할 때 사용하세요.

  • 멀티라인 입력: 여러 줄의 프롬프트를 보낼 때 """로 감쌉니다.
    >>> """
    다음 문장을 영어로 번역하고, 핵심 단어 3개를 뽑아줘:
    "로컬 AI 모델을 사용하면 데이터 보안을 강화할 수 있습니다."
    """
  • 모델 정보 보기: 모델의 아키텍처 정보를 출력합니다.
    /show info
  • 종료하기: 세션을 안전하게 닫습니다.
    /bye

    OLLAMA API 테스트 및 활용

Ollama는 기본적으로 11434 포트에서 HTTP 서버를 운영합니다. 이를 통해 우리는 브라우저나 터미널, 혹은 자바 코드로 AI에게 질문을 던질 수 있습니다.

1️⃣ 대화형 응답 테스트 (Chat API)

이전 대화 맥락을 포함하거나, AI에게 특정 역할을 부여(System Role)할 때 사용하는 방식입니다. Spring AI에서 주로 사용하는 방식이기도 합니다.

POST http://localhost:11434/api/chat 

-d '{
  "model": "qwen2.5:3b",
  "messages": [
    {
      "role": "system",
      "content": "당신은 친절하고 전문적인 자바 개발자입니다."
    },
    {
      "role": "user",
      "content": "로컬 LLM을 사용하는 이유가 뭐야?"
    }
  ],
  "stream": false
}'

2️⃣ API 응답 결과 분석

요청이 성공하면 다음과 같은 JSON 형식의 응답을 받게 됩니다.

{
    "model": "qwen2.5:3b",
    "created_at": "2026-03-25T15:48:15.51317551Z",
    "message": {
        "role": "assistant",
        "content": "안녕하세요! 로컬 LLM을 사용하는 주요 이유는 다음과 같습니다:\n\n1. **개인정보 보안**: 클라우드 서비스에 데이터를 전송하지 않아 민감한 정보 유출 위험을 최소화할 수 있습니다. 특히 의료, 금융 등 특정 산업에서 필수적입니다.\n2. **비용 절감**: 고주파 요청 시 클라우드 API 비용 대비 로컬 실행이 경제적입니다. 예를 들어, 내부 애플리케이션에서 실시간 처리를 할 때 네트워크 비용이 크게 절감됩니다.\n3. **실시간 성능**: 네트워크 지연 없이 즉시 응답이 가능해 실시간 챗봇이나 IoT 시스템에 적합합니다.\n4. **맞춤형 모델 튜닝**: 로컬에서 모델을 직접 훈련해 특정 용도(예: 한국어 처리)에 최적화할 수 있습니다.\n5. **법적 규제 준수**: 데이터 주거 요구사항을 충족하기 위해 로컬 환경에서 실행하는 경우가 많습니다.\n\n예를 들어, **Llama 3**, **Mistral** 등 소형 LLM 모델은 로컬 머신에 설치해 사용할 수 있습니다. Java 개발자로서는 Hugging Face Java SDK를 활용해 로컬 LLM을 효율적으로 통합할 수 있습니다.\n\n추가로 궁금한 점이 있으면 알려주세요! 😊",
        "thinking": "Okay, the user is asking why we use a local LLM. Let me think about this.\n\nFirst, I should recall what a local LLM is. Local LLM refers to running a large language model on the user's own machine instead of using a cloud-based service. So the main reasons would be privacy, cost, performance, maybe security.\n\nPrivacy is a big one. If you're using a cloud-based LLM, your data gets sent to the server, which might be a privacy concern. By using local, you keep the data on your machine.\n\nCost could be another point. Cloud services like OpenAI or Anthropic have costs per request. If you're using it locally, you don't have to pay for each query, but you need to set up the hardware. Maybe for some use cases, it's cheaper.\n\nPerformance: Local models might be faster since there's no network latency. Especially if you're doing real-time applications, local processing could be better.\n\nSecurity: Keeping the model on your own machine reduces the risk of data breaches or unauthorized access. Also, you control the model's access.\n\nAnother point is customization. Maybe you can fine-tune the local model to your specific needs without sharing data with the provider.\n\nWait, but some LLMs are too big to run locally. Like, GPT-3 is huge. But there are smaller models like Llama 2, Mistral, etc., that can be run locally with enough hardware.\n\nAlso, maybe the user is thinking about edge computing scenarios where you need to process data without internet.\n\nI should structure the answer clearly. Start with the main reasons: privacy, cost, performance, security, customization. Maybe mention specific examples of models that can be run locally.\n\nWait, the user is asking in Korean. The question is \"로컬 LLM을 사용하는 이유가 뭐야?\" which translates to \"Why do we use a local L:LM?\" So I need to answer in Korean.\n\nWait, the user wrote the question in Korean, but the instructions say to respond as a friendly and professional Java developer. Hmm, the user is asking in Korean, so I should respond in Korean.\n\nWait, the user's message is in Korean: \"로컬 LLM을 사용하는 이유가 뭐야?\" which means \"What's the reason for using a local LLM?\"\n\nBut the assistant's instructions say to be a friendly and professional Java developer. So the response should be in Korean, since the user is asking in Korean.\n\nWait, but maybe the user expects the answer in English? Let me check the initial instructions.\n\nThe user says: \"로컬 LLM을 사용하는 이유가 뭐야?\" which is Korean. The assistant's role is to be a friendly and professional Java developer. The user might be Korean, so the answer should be in Korean.\n\nBut the problem says: \"당신은 친절하고 전문적인 자바 개발자입니다.\" So the assistant should respond in the same language as the user. Since the user wrote in Korean, the answer should be in Korean.\n\nWait, but the user might have intended to ask in English but wrote in Korean. Hmm, but the question is in Korean. Let me confirm.\n\nThe user's message is in Korean: \"로컬 LLM을 사용하는 이유가 뭐야?\" So the answer should be in Korean.\n\nBut the initial problem says: \"You are a friendly and professional Java developer.\" So the answer should be in Korean.\n\nWait, but in the problem statement, the user wrote the question in Korean. So I need to respond in Korean.\n\nLet me think about the key points in Korean.\n\nFirst, list the reasons:\n\n1. 개인정보 보안: 로컬에서 실행하면 데이터가 클라우드에 전송되지 않아 개인정보 유출 위험 감소\n2. 비용 절감: 클라우드 서비스 사용 비용 대비 로컬 실행 시 비용 절감 가능 (특히 고주파 요청 시)\n3. 실시간 처리: 네트워크 지연 없이 즉시 응답 가능\n4. 정책 및 법적 규제: 특정 산업에서 데이터 주거 요구사항 충족\n5. 맞춤형 모델 튜닝: 로컬에서 모델을 직접 훈련해 특정 작업에 최적화 가능\n\nAlso, mention examples like Llama 3, Mistral, etc. that can be run locally.\n\nWait, but the user might not know about specific models. Maybe keep it general.\n\nAlso, as a Java developer, I can mention that Java has libraries like Hugging Face Java SDK for local LLMs, but maybe that's too specific.\n\nWait, the user is asking for the reasons, not how to implement. So focus on the reasons.\n\nLet me draft the answer in Korean.\n\n\"안녕하세요! 로컬 LLM을 사용하는 주요 이유는 다음과 같습니다:\n\n1. **개인정보 보안**: 클라우드 서비스에 데이터를 전송하지 않아 개인정보 유출 위험을 최소화할 수 있습니다. 특히 민감한 데이터 처리 시 매우 중요합니다.\n2. **비용 절감**: 클라우드 API 호출 비용 대비 로컬에서 실행하는 경우, 고주파 요청 시 비용이 크게 절감됩니다.\n3. **실시간 처리 성능**: 네트워크 지연 없이 즉시 응답을 가능하게 하여 실시간 애플리케이션에 적합합니다.\n4. **맞춤형 튜닝**: 로컬에서 모델을 직접 훈련하거나 조정해 특정 용도에 최적화할 수 있습니다.\n5. **법적 규제 준수**: 특정 산업 분야에서 데이터 주거 요구사항을 충족하기 위해 로컬 실행이 필요할 수 있습니다.\n\n예를 들어, Llama 3, Mistral 등 소형 LLM 모델은 로컬 머신에 설치해 사용할 수 있습니다. Java 개발자로서는 Hugging Face Java SDK와 같은 도구를 활용해 로컬 LLM을 효율적으로 통합할 수 있습니다.\n\n추가로 궁금한 점이 있으면 알려주세요! 😊\"\n\nWait, but I should check if the terms are correctly translated. For example, \"개인정보 보안\" is correct. \"비용 절감\" is cost reduction. \"실시간 처리 성능\" is real-time processing performance. \"맞춤형 튜닝\" is custom tuning.\n\nAlso, the example models: Llama 3 is the latest, but maybe the user is familiar with Llama 2. But it's okay.\n\nAlso, the Java part: Hugging Face has a Java SDK, so that's a good point.\n\nThe answer seems good. Let me make sure it's friendly and professional.\n\nYes, the tone is friendly with emojis and the closing. The points are clear.\n\nI think that's a good answer.\n"
    },
    "done": true,
    "done_reason": "stop",
    "total_duration": 132036650359, // 전체 처리 시간 (나노초 단위)
    "load_duration": 61223537,      // 모델 로딩 시간
    "prompt_eval_count": 45,        // 질문에 사용된 토큰 수
    "prompt_eval_duration": 710243481,
    "eval_count": 1809,             // 답변에 생성된 토큰 수
    "eval_duration": 130615466730
}
  • total_duration: 내 컴퓨터가 이 답변을 만드는 데 얼마나 걸렸는지 확인할 수 있는 지표입니다.
  • eval_count: AI가 얼마나 긴 답변을 생성했는지(토큰 수)를 나타냅니다.

도커 환경 주의사항

사용자님의 환경처럼 Docker로 실행 중인 경우, 외부(호스트 PC)에서 localhost:11434로 접근하기 위해서는 컨테이너 실행 시 반드시 -p 11434:11434 옵션이 설정되어 있어야 합니다.

작동 확인 팁: 웹 브라우저 주소창에 http://localhost:11434를 입력했을 때 "Ollama is running"이라는 문구가 뜨면 API 호출 준비가 완벽히 끝난 상태입니다.

용도별 추천 모델 리스트

로컬 환경의 자원(RAM) 상태와 목적에 따라 적절한 모델을 선택하세요.

카테고리추천 모델 (Ollama Pull)특징 및 추천 이유
다국어/한국어 우수qwen2.5:3b, qwen2.5:7b현재 실습 메인 모델. 한국어 이해도가 가장 높음
코드 생성 특화deepseek-coder:6.7b코딩 테스트 및 자바 로직 생성 능력이 매우 뛰어남
경량 고속 모델phi3:mini, gemma2:2b저사양 PC에서도 매우 빠른 응답 속도를 보여줌
글로벌 범용llama3.2:3b, mistral:7b메타와 미스트랄의 대표 모델로 안정적인 성능 제공

Ollama 핵심 명령어 정리

Docker 환경에서 실행할 경우 명령어 앞에 docker exec -it ollama를 붙여야 함을 기억하세요.

📦 모델 관리

  • ollama list : 현재 내 로컬에 설치된 모델 목록 확인
  • ollama pull <model> : 새로운 모델 다운로드 (예: ollama pull qwen2.5:3b)
  • ollama rm <model> : 불필요한 모델 삭제 (용량 확보)
  • ollama run <model> : 터미널에서 즉시 대화형 모드로 모델 실행

⚙️ 시스템 및 서버 관리

  • ollama ps : 현재 메모리(RAM)에 올라가 실행 중인 모델 확인
  • ollama serve : (로컬 설치 시) Ollama 서버 엔진 시작
  • curl http://localhost:11434 : 서버가 정상 응답하는지 상태 체크
profile
자신만의 속도로

0개의 댓글