Ollama, NGROK 및 LangChain 설정

발행: (2026년 2월 13일 오후 09:25 GMT+9)
3 분 소요
원문: Dev.to

Source: Dev.to

Breno A. V.

이 게시물은 Ollamangrok과 함께 빠르게 설정하고 LangChain에서 사용하는 방법을 보여줍니다.

Source:

Ollama

Linux, macOS, Windows용 Ollama를 쉽게 다운로드할 수 있습니다:

👉

실행 중인지 테스트하기

curl http://localhost:11434; echo   # should output “Ollama is running”

Note: 아무 응답도 없으면 ollama serve 명령으로 서버를 시작하세요.

원하는 모델을 가져오기

ollama pull phi4-mini
ollama pull nomic-embed-text:v1.5

Ollama 설치 테스트

Ollama에서 모델 가져오기

Ngrok

Linux, macOS, Windows용 ngrok을 다운로드하세요:

👉

Note: Remember to add your authtoken!
주의: authtoken을 반드시 추가하세요!

ngrok config add-authtoken 

Expose Ollama with ngrok (basic auth)

ngrok http 11434 \
  --host-header="localhost:11434" \
  --basic-auth="username:password"

Public URL from ngrok

이 명령은 공개 URL을 생성합니다. 예시:

https://09c6b3946ddd.ngrok-free.app

브라우저에서 테스트해 볼 수 있습니다:

Testing the public URL

인증에 성공하면 “Ollama is running” 이라는 메시지가 표시됩니다:

Ollama running response

/api/tags 엔드포인트를 통해 모델을 확인할 수도 있습니다:

/api/tags response

✨ 이전에 가져온 두 모델이 이제 사용 준비가 완료되었습니다.

LangChain & Ollama

필요한 Python 패키지를 설치합니다:

pip install langchain langchain-core langchain-ollama

다른 네트워크에서 Ollama (LLM & Embeddings) 사용하기

import base64
from langchain_ollama.llms import OllamaLLM
from langchain_ollama.embeddings import OllamaEmbeddings

BASE_URL = "https://09c6b3946ddd.ngrok-free.app"
user_pass = b"username:password"
auth_header = base64.b64encode(user_pass).decode("utf-8")

client_kwargs = {
    "headers": {
        "Authorization": f"Basic {auth_header}"
    }
}

llm = OllamaLLM(
    model="phi4-mini:latest",
    base_url=BASE_URL,
    client_kwargs=client_kwargs,
)

embeddings = OllamaEmbeddings(
    model="nomic-embed-text:v1.5",
    base_url=BASE_URL,
    client_kwargs=client_kwargs,
)

# Test the LLM
print(llm.invoke("Hello, Ollama LLM =)"))

# Test the embeddings
print(embeddings.embed_query("Hello, Ollama Embeddings =)"))

결과 예시:

LangChain 테스트 출력

추가 정보 - 셀프 호스팅 Ollama API 노출 및 보안

0 조회
Back to Blog

관련 글

더 보기 »