python
[GPT] OutputParser and LCEL
으누아빠
2024. 3. 26. 17:37
반응형
[결과값]
['mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune']
BaseOutputParser
LLM 호출의 출력을 구문 분석하는 기본 클래스
parse 메서드는 추상 메서드임 parse를 하기위한 기본 메서드
CommaOutputParser(BaseOutputParser)
CommaOutputParser 클레스에 BaseOutputParser 클래스를 상속시킴
위의 코드를 아래처럼 LCEL(LangChain expression language)형태로 변경할 수 있음LCEL은 다양한 template 와 LLM 호출, response를 사용하게 해줌
[결과값]
['pikachu', 'charmander', 'bulbasaur', 'squirtle', 'jigglypuff']
Chain
기본적으로, 모든 요소를 합쳐주는 역할
"|": operator 를 이용하여 연결시켜줌
invoke()를 이용하여 입력에 따라 chain을 호출함
(method) def invoke(
input: Dict,
config: RunnableConfig | None = None
) -> Any
입력하는 값은 Dict 형태 로 입력된다.
LCEL
standard interface
- invoke : 입력에 대해 chain을 호출한다.
- batch : 입력 리스트에 대해 chain을 호출한다.
- stream : 응답을 스트리밍한다.
input type 과 output type은 구성요소에 따라 다름