0. 잘 정리가 된 글

 

https://www.itworld.co.kr/news/307189

 

“LLM 개발을 더 간편하게” 랭체인(LangChain)의 이해

대규모 언어 모델(LLM)을 위한 효과적인 프롬프트를 작성하는 데는 기술이 필요하지만 LLM 사용법은 대체로 간단하다. 반면 언어 모델을 사용한

www.itworld.co.kr

 

https://brunch.co.kr/@ywkim36/146?fbclid=IwZXh0bgNhZW0CMTEAAR319OC5XNzAqUsQQDLzkUkg4_FAlzEk85JcBZL4V933vq89KgkBd6tXnVE_aem_AUmRdSQ_sYdbSO6ij2orZen6qipd1K29FHRaqCBCcWfcJEGGjUUrKpUp0Rf3miV4pzbHoxc1UvIW_Pfm3rSGIbaw&mibextid=K35XfP

 

10분 만에 RAG 이해하기

AI의 새로운 핫 토픽 RAG(검색-증강 생성)를 설명해 드립니다. | 소프트웨어 산업에는 하루에도 수십 개의 새로운 약어와 개념이 등장합니다. 특히나 빠르게 변하는 AI 기술 같은 경우라면 더욱 말

brunch.co.kr

 

 

1. 모델 I/O는 프롬프트를 관리하고 공통 인터페이스를 통해 언어 모델을 호출하고 모델 출력에서 정보를 추출할 수 있게 해준다

 

2. 데이터 연결은 데이터를 로드, 변형, 저장 및 쿼리하기 위한 빌딩 블록을 제공한다

 

3. Chain : 구성 요소를 조합해서 하나의 파이프라인을 구성한다.

 

 

4. 메모리

메모리는 데이터를 저장하는 공간. 데이터는 대화과정에서 발생하는 데이터를 의미.
챕봇 앱은 이전 대화를 기억해야 하지만, LLM은 채팅 기록을 장ㅇ기적으로 ㅂ관하지 않는다. 

대화 내용은 다음과 같은 형태로 저장될 수 있다. 

  • Conversation Buffer: 그동안의 모든 대화를 저장한다. 대화가 길어질 수록 메모리 용량이 증가한다는 점이 단점이다.
  • Conversation Buffer Window: 마지막 k개의 대화만 저장한다. 최근 대화만 저장하기에 메모리 용량이 과도하게 늘어나지 않는다는 장점이 있지만, 이전 내용을 잊게 된다는 단점이 있다.
  • Conversation Summary: LLM을 사용하여 대화 내용을 요약하며 저장한다.
  • Conversation Summary Buffer: max_token_limit을 초과할 경우에 요약하여 저장한다. Buffer Window와 Summary의 결합이다.
  • Conversation Knowledge Graph: 대화 속 주요 entity를 추출해 지식 그래프(knowledge graph)를 생성한다.

 

https://blog.futuresmart.ai/langchain-memory-with-llms-for-advanced-conversational-ai-and-chatbots

 

Langchain Memory with LLMs for Advanced Conversational AI and Chatbots

Explore the concept and types of Langchain memory, and learn how to integrate it with Streamlit and OpenAI's GPT API to build smarter, context-aware chatbot

blog.futuresmart.ai

 

 

https://medium.com/@miloszivic99/finetuning-large-language-models-customize-llama-3-8b-for-your-needs-bfe0f43cd239#45a2

 

https://fornewchallenge.tistory.com/entry/LLAMA3-RAG-%EC%8B%9C%EC%8A%A4%ED%85%9C-AI-%EC%96%B4%EC%8B%9C%EC%8A%A4%ED%84%B4%ED%8A%B8%EB%A1%9C-10%EC%B4%88%EB%A7%8C%EC%97%90-%EC%9E%90%EB%8F%99-%EB%B3%B4%EA%B3%A0%EC%84%9C-%EB%A7%8C%EB%93%A4%EA%B8%B0?fbclid=IwZXh0bgNhZW0CMTEAAR0S8Jj99tNYS02OV2i9HzBarxXfl4JamgACqSXQO27rSIJnWXKk_Y2KQyE_aem_AbrBa-sw_OShDPaM50W1CAAOg7p3qiD7VFpHc9A-pH0hAGMtUV68D9iTlyVd0YJcLAyzZNXWPHcro8FZw4xPeHtu

 

LLAMA3 RAG 시스템: AI 어시스턴트로 10초만에 자동 보고서 만들기

안녕하세요! 오늘은 요즘 가장 인기 있는 언어 모델, LLAMA3로 AI 어시스턴트를 만들어 보겠습니다. 이 앱은 Groq과 Phidata를 이용해서 주어진 웹 사이트나 pdf를 기반으로 "원클릭" 보고서를 작성하고

fornewchallenge.tistory.com

 

'머신러닝 > RAG' 카테고리의 다른 글

1. Local LLM에 대하여  (0) 2024.04.12
0 환경 설정 - ollama 설치  (0) 2024.04.10

Implementing RAG using Langchain Ollama and Chainlit on Windows using WSL

https://medium.aiplanet.com/implementing-rag-using-langchain-ollama-and-chainlit-on-windows-using-wsl-92d14472f15d

 

Implementing RAG using Langchain Ollama and Chainlit on Windows using WSL

What is Ollama ?

medium.aiplanet.com

 

RUN LLMs locally

PrivateGPT,llama.cpp, Ollama, GTP4All, llamafile 과 같은 다양한 프로젝트에 대한 Overview

https://python.langchain.com/docs/guides/development/local_llms/

 

LangServe + Ollama

- ollama를 통해  OpenModel를 서버에 설치하고, Remote에서 Chain을 호출한다. 한글 모델(야놀자 제공,heegye님이 변환, Teddy님의 공개 강좌)

- '24 4/12부터 이 구조를 사용하고 개발 진행함..

- Teddy님의 소개 자료 https://github.com/teddylee777/langserve_ollama?tab=readme-ov-file 

 

 

 

Ollama model 받기

1.  Hugging Face에서 받기

 

# 1. https://huggingface.co/asiansoul/KoDolph-2x8b-GGUF 에서
# 2. kodolph-2x8b-Q8_0.gguf 모델을 받는 다고 가정한다.

#1. Model 다운로드 사용법
huggingface-cli download \
  asiansoul/KoDolph-2x8b-GGUF \           #hugging face의 URL이다.
  kodolph-2x8b-Q8_0.gguf \                # files and version dir에서 받고 싶은 모델이다.
  --local-dir 본인의_컴퓨터_다운로드폴더_경로 \
  --local-dir-use-symlinks False
  
 #예시
 
 huggingface-cli download \
> asiansoul/KoDolph-2x8b-GGUF \
> kodolph-2x8b-Q8_0.gguf \
> --local-dir /workspace/home/hankh/langserve_ollama/ollama-modelfile/LLAMA3-Ko-Instruct --local-dir-use-symlinks False

#2. Modelfile 설정
#Model파일을 만들거나 Get한다. kodolph-2x8b-Q8_0.gguf는 친절하게 Modelfile_Q5_K_M 파일을 제공한다.
#내용은 확인하세요

#3. Ollama 모델 등록
ollama create Llama3-KoDolph -f ./Modelfile_Q8_K_M

#4 Ollama List 확인

ollama list

NAME                    	ID          	SIZE  	MODIFIED
EEVE-Korean-10.8B:latest	c3ebb32b93a5	7.7 GB	2 days ago
Llama3-KoDolph:latest   	915768bf8359	8.5 GB	11 seconds ago
gemma:7b-instruct       	a72c7f4d0a15	5.0 GB	12 hours ago

#5 Ollama 실행

ollama run Llama3-KoDolph

 

'머신러닝 > RAG' 카테고리의 다른 글

LLM 개발을 더 간편하게 랭체인의 이해  (0) 2024.04.14
0 환경 설정 - ollama 설치  (0) 2024.04.10

 

 

1. Install Ollama - 로컬에서 무료로 사용할 수 있는 LLM 도구, Ollama 활용 가이드


 - Ollama는 로컬에서 대형 언어 모델(LLM)을 쉽게 사용할 수 있도록 지원하는 플랫폼입니다. macOS, Windows(WSL2를 통한 설치 가능), Linux에서 간편하게 설치할 수 있으며, Docker를 지원하여 더욱 다양한 환경에서 활용 가능합니다. Ollama는 ollama run llama2와 같은 간단한 명령어로 빠르게 AI 모델과 상호작용할 수 있습니다. Llama 2, Mistral, Vicuna, LLaVa 등의 다양한 오픈 소스 모델을 지원하며, 사용자는 이들 중 필요한 모델을 선택하여 사용할 수 있습니다. 자세한 내용은 Ollama 공식 웹사이트에서 확인하실 수 있습니다.

 - Installation on Linux https://github.com/ollama/ollama/blob/main/docs/linux.md
 - # Run the most popular AI model among open licenses
     ollama run mistral
 참고 자료 : https://anpigon.tistory.com/434  

 

실해예시

 

-Ollama WebUI 설치 하기 

터미널 작업은 귀찮다. Web으로 제공된다. 참으로 대단한 사람들이 많다.

#리눅스 환경, NVIDIA GPU 사용한다. port를 설정하면 웹포트를 설정할 수 있다. 기본 포트는 3000
# Docker build
run-compose.sh --enable-gpu --webui[port=xxxx] --build
# Docker 실행
run-compose.sh --enable-gpu --webui[port=xxxx]

참고 자료  https://docs.openwebui.com/getting-started/

 

실행결과

그러나 '24 4/11부터 LangServe를 알게 된 이후부터 사용안함..

 

- LangServer + Ollama

 

(hankh) [hankh@tb-eipms-tau1 app]$ pwd
/workspace/home/hankh/langserve_ollama/app
(hankh) [hankh@tb-eipms-tau1 app]$ python server.py

 

도움 받은 글 : https://github.com/teddylee777/langserve_ollama?tab=readme-ov-file

 

 

- 랭체인으로 LLM기반의 AI서비스 개발하기

요즘 읽고 있는책이며, 소스는 아래 링크 참조

OpenAI대신 langserve_ollama로 변환하면서 적응하기...(아..가난뱅이)

https://github.com/gilbutITbook/080413

 

GitHub - gilbutITbook/080413: <랭체인으로 LLM 서비스 만들기> 소스 코드

<랭체인으로 LLM 서비스 만들기> 소스 코드. Contribute to gilbutITbook/080413 development by creating an account on GitHub.

github.com

 

2. ChatGPT를 대신하는 Ollam LLM,Chat

최종 하려는 것은 유료 OpenAI사의 Chat, LLM 대신 Ollam를 통해 무료 model을 사용한다. 유료보다는 떨어지겠지만..

LangChain학습하는데는 충분하지 않을까...

 

1. LLM모델

%config Completer.use_jedi = False  # JupyterNotebook에서 도움말 얻기..

from langchain_community.llms import Ollama
llm = Ollama(model="EEVE-Korean-10.8B")

 

2. Chat모델

# OpenAI대신 Ollama를 호출해서 학습을 한다.
# from langchain_openai import ChatOpenAI
# llm = ChatOpenAI()

from langchain_community.chat_models import ChatOllama
chatLlm = ChatOllama(model="EEVE-Korean-10.8B")

 

3. Embedding

embedding에 사용되는 모델은 좀 더 확인을 해보자

from langchain_community.embeddings import OllamaEmbeddings
embeddings = OllamaEmbeddings(model = 'EEVE-Korean-10.8B')  ## OpenAI 임베딩 대신 Ollama를 사용한다

 

 

3. NVIDIA GPU 보는법 

  • nvidia-smi
  • watch -n 1 nvidia-smi

 

https://velog.io/@claude_ssim/NVIDIA-GPU-%EB%B3%B4%EB%8A%94%EB%B2%95nvidia-smi

'머신러닝 > RAG' 카테고리의 다른 글

LLM 개발을 더 간편하게 랭체인의 이해  (0) 2024.04.14
1. Local LLM에 대하여  (0) 2024.04.12

+ Recent posts