본문 바로가기

ML&DL and LLM

LangChain - 1.3.1 LLM QuickStart

참조 : https://python.langchain.com/docs/modules/model_io/llms/quick_start

 

Quick Start | 🦜️🔗 Langchain

quick-start}

python.langchain.com

 

LLM

다양한 LLM providers 존재 (OpenAI, Cohere, Hugging Face 등)

 

Setup

사용하고자 하는 LLM의 python package 설치하고 API 접근을 위한 Key를 설정하면 끝!

Step Desc Etc.
1. Install Python package pip install openai  
2. Setup API Key OS> export OPEN_API_KEY="...'
or 
In program> os.environ["OPENAI_API_KEY"] = "..."
 

 

 

LCEL

LLMs implement the Runnable interface, the basic building block of the LangChain Expression Language (LCEL)

다음과 같은 Call을 제공함

Calls Code Etc.
(Prepare) prompt = "What are some theories about the relationship between unemployment and inflation?"  
invoke llm.invoke(prompt) 일반 동기 수행
stream for chunk in llm.stream(prompt):
    print(chunk, end="", flush=True)
Stream 동기 수행
batch llm.batch( [ prompt ] ) Batch 동기 수행
ainvoke await llmainvoke( prompt ) 일반 비동기 수행
astream async for chun in llm.astream( prompt ):
    print(chunk, end="", flush=True)
Stream 비동기 수행
abatch await llm.abatch( [ prompt ] ) Batch 비동기 수행
astream_log async for chunk in llm.astream_log( prompt) :
    print(chunk)
Log