AI 모델 실행

AI 모델 다운로드하기

이제 구동할 AI 모델이 필요합니다.

저는 GPT4All 홈에서 mistral-7b-openorca.Q4_0.gguf 모델을 다운로드하겠습니다.

모델은 적당한 폴더에 위치시킵니다.

Python으로 AI 모델 실행하기

LangChain은 수많은 AI 모델 구동을 지원하고, 그중 GPT4All도 있습니다. 참고하여 다음과 같은 코드를 작성합니다.

llm_sample.py
from langchain_community.llms.gpt4all import GPT4All
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

model = GPT4All(model="model/mistral-7b-openorca.Q4_0.gguf", n_threads=8)

template = """
Answer to the question: {question}
"""
prompt = PromptTemplate(template=template, input_variables=["question"])

llm_chain = LLMChain(prompt=prompt, llm=model, verbose=True)

# run the question
print(llm_chain.invoke({
    "question": "Who is Son Heung-min?"
}))

실제로 실행해 보면 다음과 같습니다.

답변이 오긴 했는데, 손흥민 선수가 5자리 이름으로 개명을 했고 출생지도 틀렸습니다. (손흥민 선수는 춘천에서 태어났는데 고양으로 출생지가 바뀌었습니다)

이렇게 AI가 잘못된 정보나 허위 정보를 내놓는 것Hallucination이라고 합니다.

한국어로 질문했을 때

한국어로 질문을 바꿔 보았습니다. 알아듣기는 하는데, 대답은 영어로 나옵니다. Hallucination은 오히려 더 심해진 것 같기도 하고요. (손흥민 선수는 2010 ~ 2013년에 함부르크에서 뛰었습니다)

아무래도 많이 부족한 친구인 것 같습니다. 예시 코드부터 불안한데... 사용할 수 있을까요?

Last updated

Was this helpful?