2024/03 21

[GPT] LCEL Based Memory

메모리를 수동으로 관리하는 방법 으로 커스트마이징하기 쉬움 RunnablePassthrough RunnablePassthrough를 사용하면 입력을 그대로 전달하거나 추가 키를 추가하여 전달할 수 있음 Runnable Passthrough()는 자체적으로 호출되며, 입력을 받아 전달하기만 하면됨 RunnablePassthrough는 assign(RunnablePassthrough.assign(키=값)형태로 호출 [결과] content='Hello Hong! How can I assist you today?' [결과] content='Your name is Hong. How can I assist you today, Hong?'

python 2024.03.30

[GPT] ConversationSummaryBufferMemory

ConversationSummaryBufferMemory 메세지를 저장하다가 Token 기준으로 최대치를 넘어가면 이전 대화를 요약해서 저장 [결과] {'history': [HumanMessage(content="Hi I'm Hong, I live in South Korea"), AIMessage(content='Wow that is so cool!')]} 만약 token 값이 max_token_limit 를 초과할 경우 SystemMessage 가 새롭게 생성되면서 이전 대화내용을 요약하여 메세지에 저장 [결과값] {'history': [SystemMessage(content='The human introduces themselves as Hong from South Korea.'), AIMessage..

python 2024.03.29

[GPT] ConversationBufferMemory

ConversationBufferMemory ConversationBufferMemory는 메시지를 저장한 다음 변수에서 메시지를 추출합니다. 단순히 이전 대화 내용 전체를 저장 대화 내용이 길어질수록 메모리도 계속 커져서 비효율적 [결과] {'history': 'Human: Hi!\nAI: How are you?'} ConversationBufferMemory(return_messages=True)를 이용하여 결과를 문자열이 아닌 리스트 형태로 받을수 있음 [chat model 사용시 유용] [결과] {'history': [HumanMessage(content='Hi!'), AIMessage(content='How are you?')]}

python 2024.03.29

[GPT] Caching

캐싱을 사용하면 언어모델의 응답을 저장할 수 있음 이후 동일 질문을 받을경우 언어모델에 질의를 하지 않고 캐싱된 답변을 가져옴 set_llm_cache 새 LLM 캐시 설정, 이전 값 덮어쓰기(있는 경우) 캐시 종류 InMemoryCache: 메모리를 이용하여 캐시를 저장. 서버 재실행시 캐싱된 내용이 사라짐 SQLite Cache: SQLite cache를 이용하여 캐시를 저장 그외에도 여러가지의 캐시가 있음 https://python.langchain.com/docs/integrations/llms/llm_caching#in-memory-cache LLM Caching integrations | 🦜️🔗 Langchain This notebook covers how to cache results of ..

python 2024.03.28