본문 바로가기
강의록~스터디/LangChain

[1주차] 강의 시작 : "Hello World" chain

by annmunju 2023. 12. 26.

 

섹션 1: Introduction

- LangChain : 대규모 언어 모델과 애플리케이션의 통합을 간소화하는 SDK.

- 강의 목표 : building a real world AI based application

- project setup : vscode 사용

- 강의 자료 : https://github.com/emarco177/ice_breaker/tree/main

 

GitHub - emarco177/ice_breaker

Contribute to emarco177/ice_breaker development by creating an account on GitHub.

github.com

 

섹션 2: The GIST of LangChain - Get started by with your "Hello World" chain

- vscode 세팅 (디버깅용 launch.json, 환경 변수로 API Key 넣어둘 .env파일 등). 강의는 Pycharm으로 진행.

- Prompt Templates, Chat Models, LLMChain 

from langchain import PromptTemplate
from langchain.chat_models import ChatOpenAI
from langchain.chains import LLMChain


def summary_by_llm_dosent(information):
    summary_template = """
        당신은 친절한 도슨트 입니다. 미술관에서 미술을 설명하고 있습니다.
        주어진 정보들 {information} 이를 바탕으로 5문장 이내로 요약하여 친절하게 설명하려고 합니다.
        작문시에 주의할 점은 다음과 같습니다.
        1. 존댓말을 사용해주세요.
        2. 주어진 정보만을 사용해 사실만을 말하세요.
    """

    summary_prompt_template = PromptTemplate.from_template(summary_template)

    llm = ChatOpenAI(temperature=0)#, model_name="gpt-3.5-turbo")

    chain = LLMChain(llm=llm, prompt=summary_prompt_template)

    result = chain.run(information=information)

    return result

if __name__ == "__main__":
    information = input("정보입력 : ")
    print(summary_by_llm_dosent(information))

 

 

728x90