[Ollama] 로컬 LLM으로 crewAI사용하기

최영섭·2024년 4월 15일
1

1. Ollama설치

Ollama
위 링크에 들어가서 자신의 os에 맞는 버전을 다운로드 받으면 된다.

이후는 과정을 따라가면 정상적으로 설치가 완료된다.

2. 모델 다운로드

1) 모델 다운

heegyu/EEVE-Korean-Instruct-10.8B-v1.0-GGUF · Hugging Face

아래와 같이 스크립트로 진행해도 되고 직접 다운받아도 된다.

pip install --user huggingface-hub
huggingface-cli download \
	heegyu/EEVE-Korean-Instruct-10.8B-v1.0-GGU \
	ggml-model-Q5_K_M.gguf \
	--local-dir /Users/youngsup/desktop/eeve_model
	--local-dir-use-symlinks False
  • 내가 다운받고자 하는 레포
  • 다운받고자하는 파일명
  • 다운받고자하는 local상의 위치
  • symlinks사용 여부

allama에서 gguf파일을 변환을 해서 올려줘야하는데 이때 Modelfile이 필요

2) Modelfile작성

Modelfile로부터 커스텀 모델 생성하기

FROM ggul-model-Q5_K_M.gguf

TEMPLATE """{{- if .System}}
<s>{{ .System}}</s>
{{- end}}
<s>Human:
{{ .Prompt }}</s>
<s>Assistant:
"""

SYSTEM """A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's question."""

TEMPERATURE 0
PARAMETER stop <s>
PARAMETER stop </s>

모델파일을 제대로 설정하지 않으면 답변이 끝난뒤에 계속 이상한 텍스트를 생성함, 모델별로 템플릿을 정확하게 확인해두고 넣어야한다.

각각의 모델마다 Modelfile이 정해져있음

간혹 Modelfile을 잘 정의해두지 않을때가 있는데 그때는 해당모델의 basemodel의 Modelfile을 확인하면 된다.

3. 실행

파일이 있는 디렉토리에서 아래와 같이 실행하면 된다.

ollama create EEVE-Korean-10.8B -f Modelfile

모델이 성공적으로 생성된것 을 확인할 수 있다

ollama list

아래 스크립트로 실행한다.

ollama run EEVE-Korean-10.8B:latest

아래와 같이 성공적으로 local에서 LLM을 실행하였다.

4. CrewAI와 연결

아래와 같이 agent의 llm parameter에 Ollama로 올린 모델을 넣어주면된다.


from langchain_community.llms import Ollama

EEVE = Ollama(model = "EEVE-Korean-10.8B:latest")

my_agent = Agent(role="Expert Travel Agent",
    backstory=dedent(
        f"""Expert in travel planning and logistics. 
        I have decades of expereince making travel iteneraries."""),
    goal=dedent(f"""
        Create a 7-day travel itinerary with detailed per-day plans,
        include budget, packing suggestions, and safety tips.
        """),
    tools=[
        SearchTools.search_internet,
        CalculatorTools.calculate
            ],
    verbose=True,
    # llm=self.OpenAIGPT4,
    llm=EEVE
    )
profile
세상에 필요한 것을 고민하고 그것을 만드는 과정에서 문제를 해결하는 일이 즐겁습니다. 창업, 백엔드, RAG에 관심을 가지고있습니다.

0개의 댓글