Quickstart | ๐ฆ๏ธ๐ LangChain
Quickstart | ๐ฆ๏ธ๐ LangChain
In this quickstart we'll show you how to:
python.langchain.com
์์๋ถํฐ Jupyter Notebook์ ์ธํ ํ๋ผ๊ณ ํ๋.. ์ธํ ํ์.
Project Jupyter | Installing Jupyter
Project Jupyter
The Jupyter Notebook is a web-based interactive computing platform. The notebook combines live code, equations, narrative text, visualizations, interactive dashboards and other media.
jupyter.org
์์์ OpenAI๋ฅผ ์ฌ์ฉํ์ฌ ์ค์ตํ ์์ ์ด๋ค.
OpenAI ํจํค์ง๋ฅผ ์ค์นํ์.
# pip install langchain-openai
๊ทธ๋ฆฌ๊ณ OPEN_API_KEY๋ฅผ ๋ฑ๋กํด์ค์ผ ํ๋ค. ์ด๊ฑธ ์๋์ ๊ฐ์ด ํ๊ฒฝ๋ณ์๋ก ๋ณดํต์ธํ ํ๋๋ฐ,
# export OPENAI_API_KEY="..."
ํ์์ ๊ฐ์ด ์๋์ฐ ํฐ๋ฏธ๋์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๊ทธ๋ฅ Python ์คํํ๋ฉด์ ํ๊ฒฝ๋ณ์ ์ธํ ํ๋๋ก ํด๋ฒ๋ฆฐ๋ค. ์๋ฅผ๋ค์ด ์๋ ์ฝ๋๋ฅผ ์ฐ์ ์คํ์์ผ OS๋ณ์๋ฅผ ๋ฃ๋๊ฒ๋ ๋ฐฉ๋ฒ์ด๋ค.
import os
os.environ['OPENAI_API_KEY'] = 'sk-prXXXXXXXX9XXXXXXXXXXXXXXXXXXXXX3'
์ฐธ๊ณ ๋ก OPEN AI ์ KEY๋ ์๋์์ ํ์ธํ๋ค.
https://platform.openai.com/api-keys
๊ทธ๋ฆฌ๊ณ ๋ ์๋์ ๊ฐ์ด llm ๊ฐ์ฒด๋ฅผ ์ ์ธํ ๋ค
from langchain_openai import ChatOpenAI
llm = ChatOpenAI()
๊ฐ๋จํ๊ฒ๋ ๋ช ์์ ์ธ ์ง์๋ฅผ ํตํด ๋ฌผ์ด๋ณผ์๋ ์๊ณ
llm.invoke("how can langsmith help with testing?")
์๋์ Prompt template์ ์กฐํฉํจ์ผ๋ก์จ ๋ ๋์ ๊ฒฐ๊ณผ๋ฅผ ๋์ถํ ์ ์์ต๋๋ค.
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages([
("system", "You are a world class technical documentation writer."),
("user", "{input}")
])
์ด Output์ Parser๋ฅผ ์ถ๊ฐํด ์ดํ๋ฆฌ์ผ์ด์ ๋ด๋ถ์์ ์ฌ์ฉํ ์๋ ์๋ค.
from langchain_core.output_parsers import StrOutputParser
output_parser = StrOutputParser()
chain = prompt | llm | output_parser
'AI * ML' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
LangChain ์์ํ๊ธฐ - Agent์ ๋ํด์ (0) | 2024.06.29 |
---|---|
LangChain ์์ํ๊ธฐ - ๋ํ๋ด์ฉ์ Context๋ก ๊ฐ์ง๋ Retriever ์ค์ (0) | 2024.06.23 |
LangChain ์์ํ๊ธฐ - Retrieval ๋ฅผ ํตํ ์ปจํ ์คํธ ์ ์ํ๊ธฐ (0) | 2024.06.21 |
Foundation Models ์ด๋? ๊ทธ๋ฆฌ๊ณ FMops๋? (0) | 2024.06.16 |
Kubernetes์ฉ ์์ฑ AI: K8sGPT ์คํ ์์ค ํ๋ก์ ํธ (0) | 2024.06.09 |