참조 : https://python.langchain.com/docs/modules/model_io/llms/quick_start
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 |
'ML&DL and LLM' 카테고리의 다른 글
LangChain - 2.1 Retrieval concept (1) | 2024.03.29 |
---|---|
LangChain 1.5.1 Types of output parser (0) | 2024.03.29 |
LangChain - 1.2.5 MessagePromptTemplate (0) | 2024.03.28 |
LangChain - 1.2.4 Few-shot prompt template (0) | 2024.03.28 |
LangChain - 1.2.1 PromptTemplate (0) | 2024.03.27 |