summ의 블로그

[Langchain] langchain 본문

langchain

[Langchain] langchain

summ._ 2024. 7. 11. 01:29

 

Langchain이란 ?

LLM 개발을 중점으로 둔 프레임워크

 

사용 전 

pip install langchain

코랩사용시 (!붙여서)

 

langchian 구성 시 프롬프트 설정 필요

 

프롬프트란? 요구사항, 작업을 정의하기 위해 만들어짐. 

 

PromptTemplate을 가져와서 {변수}를 할당하며 초기화, 생성 

prompt 생성됨. question이 prompt에 들어가 llm을 거쳐 답변을 사용자에게 알려줌. 

 

from langchain import PromptTemplate

template = """Question: {question}

Answer: """

prompt = PromptTemplate(
        template=template,
    input_variables=['question']
)

question = "Which NFL team won the Super Bowl in the 2010 season?"

 

 

temperature

 

temperature은 값이 낮을수록 정확한 결과를 제시함. 0에서 2 사이의 값을 지정할 수 있으며, 일반적으로 0.5 ~ 1.0 사이의 값을 사용

 

 

동일한 PromptTemplate 객체로 여러 질문에 대해 답변도 가능하다. 딕셔너리 형태로

 

qs = [
    {'question': "Which NFL team won the Super Bowl in the 2010 season?"},
    {'question': "If I am 6 ft 4 inches, how tall am I in centimeters?"},
    {'question': "Who was the 12th person on the moon?"},
    {'question': "How many eyes does a blade of grass have?"}
]
res = llm_chain.generate(qs)
res

 

'langchain' 카테고리의 다른 글

[Langchain] AI agent  (0) 2024.09.04
[Langchain] Retrieval Agents  (0) 2024.08.21
[Langchain] chain  (0) 2024.07.15
[Langchain] fewshot prompting  (0) 2024.07.15
[Langchain] OpenAI api key 발급받기  (0) 2024.07.08