🖥️
Dive to AI
  • Get started
  • GPT4All
    • LangChain, GPT4All 설치
    • AI 모델 실행
    • 번역을 맡겨 보자
    • AI 응답 개선하기
  • AI 사용하기
    • AI를 효율적으로 사용하는 법
    • 어떻게 AI를 활용해야 할까?
  • 여러 가지 AI
    • Chat AI
    • Coding AI
    • Hugging Face
  • AI 관련 개념들
    • Reader-Retriever Model
    • RAG
    • Fine-tuning
  • Other
    • 그 외
  • Links
    • GitHub
    • Dive to Argo
Powered by GitBook
On this page

Was this helpful?

  1. GPT4All

AI 응답 개선하기

여기서 한 가지가 떠올랐습니다. AI를 다룰 때, 중요한 점은 질문도 잘해야 정확한 대답을 받을 수 있다는 것입니다.

확실히 이전의 질문 템플릿은 엉성했습니다. 이를 개선하면 되지 않을까요? 그래서 한 번 바꾸어 보기로 했습니다.

하나의 방법은 바로 AI에게 역할 또는 상황을 부여하는 것입니다. 다음과 같이 변경해 보겠습니다.

llm_trans_advanced.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 = """
You're a assistant that translates Korean to English.
You only translates the first received sentence, and do not answer except result sentence.

Translate this: {sentence}
"""
prompt = PromptTemplate(template=template, input_variables=["sentence"])

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


def translate_ai_advanced(sentence: str) -> str:
    result = llm_chain.invoke({
        "sentence": sentence
    })
    return result["text"]

"넌 이제 번역 도우미다"라고 역할을 부여했고, 첫 번째 받은 문장만 번역하고, 결과만 말하라고 했습니다. 이걸로 결과가 달라질까요?

이전에 이상한 결과를 내놓았던 문장이 제대로 번역되었습니다. 그런데 저는 앞에 붙는 Translation: 도 표시가 안 되었으면 합니다.

llm_trans_advanced.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 = """
You're a assistant that translates Korean to English. Be terse.

Translate this: {sentence}
Result:
"""
prompt = PromptTemplate(template=template, input_variables=["sentence"])

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


def translate_ai_advanced(sentence: str) -> str:
    result = llm_chain.invoke({
        "sentence": sentence
    })
    return result["text"]

깔끔하게 문장만 출력된 것을 볼 수 있습니다.

실제로 비정상적인 답변도 많이 줄어들었고, 전체적인 번역 퀄리티도 높아졌습니다. 추가 질문을 생성하는 경우가 있어서 아래 조건만 추가해서 사용 중입니다.

Only translate the first received sentence.
Previous번역을 맡겨 보자NextAI를 효율적으로 사용하는 법

Last updated 1 year ago

Was this helpful?

이에 관해 찾아보던 중, 에서 Be terse.라는 문장을 발견했고 AI가 간단하게 답하도록 설정할 때 사용하는 문구임을 알게 되었습니다. 바로 적용해 봅시다.

GPT4All 문서