이 애플리케이션은 사용자 입력을 기반으로 텍스트를 생성하기 위해 OpenAI API를 통해 액세스되는 LLM(Large Language Model) GPT-4o를 사용합니다. 사용자 입력은 데이터베이스에서 관련 정보를 검색하는 데 사용되며 검색된 정보는 텍스트를 생성하는 데 사용됩니다. 이 접근 방식은 변환기의 성능과 소스 문서에 대한 액세스를 결합합니다.
이 특정 애플리케이션에서는 1000개 이상의 웹사이트 데이터베이스에서 특정 인물과 관련된 정보를 검색합니다. 여기서 진짜 문제는 검색된 사람 "Michał Żarnecki"가 두 가지 다른 맥락에서 같은 이름을 가진 두 명의 다른 사람으로 나타난다는 것입니다. 목표는 특정 정보를 찾는 것뿐만 아니라 맥락을 이해하고 이름이 같은 두 사람에 대한 정보를 혼합하는 것과 같은 실수를 피하는 것입니다.
저는 이 애플리케이션에 사용된 개념을 Medium.com https://medium.com/@michalzarnecki88/a-guide-to-using-llm-retrieval-augmented- Generation-with-php-3bff25ce6616의 기사에서 더 자세히 설명했습니다.
설정을 위해서는 먼저 Docker 및 Docker Compose https://docs.docker.com/compose/install/을 설치해야 합니다.
CLI에서 실행: cd app/src && composer install
언어 모델 설정 - 아래 옵션 중에서 선택하세요. OpenAI API 옵션
로컬 ollama API3를 통한 무료 모델이 포함된 "A"
OpenAI API를 사용하는 "B"
옵션 B는 더 간단하고 더 적은 리소스 CPU 및 RAM이 필요하지만 OpenAI API 키 https://platform.openai.com/settings/profile?tab=api-keys
가 필요합니다. 옵션 A에는 더 많은 리소스 CPU 및 RAM이 필요하지만 실행할 수 있습니다. ollama API를 사용하여 로컬로 수행합니다. 이 옵션의 경우 GPU를 사용하는 것이 좋습니다.
아래에서 선호하는 옵션 A 또는 B에 대한 지침을 따르세요.
ollama를 로컬로 설정하려면 이 파일 하단에 있는 지침을 따르세요. 하지만 docker를 사용하는 경우에는 필요하지 않습니다.
*Ollama는 LLM을 제공하는 로컬 API를 제공합니다. "대규모 언어 모델을 시작하고 실행하세요." https://ollama.com/
docker-compose up
*힌트: 스크립트는 먼저 소스 문서를 변환해야 하며 30분 정도 걸릴 수 있습니다. 시간을 절약하려면 app/src/documents에서 문서의 일부를 제거하세요.
컨테이너 설정이 완료될 때까지 기다립니다. 콘솔 로그에 다음이 표시됩니다.
php-app | Loaded documents complete
php-app | Postgres is ready - executing command
php-app | [Sat Nov 02 11:32:28.365214 2024] [core:notice] [pid 1:tid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
아래와 같이 요청을 사용하여 애플리케이션을 API로 사용할 수 있습니다.
옵션 A 올라마:
curl -d '{"prompt":"what is result of 2+2?"}' -H "Content-Type: application/json" -X POST http://127.0.0.1:2037/processOllama.php?api
옵션 B OpenAI GPT:
curl -d '{"prompt":"what is result of 2+2?"}' -H "Content-Type: application/json" -X POST http://127.0.0.1:2037/processGpt.php?api
docker Interactive docker exec -it php-app sh
실행
CLI에서 실행: php minicli rag
질문하기
##### INPUT:
What is the result of 2 + 2?
##### RESPONSE:
The result of 2 + 2 is 4.
##### INPUT:
what is specialization of Michał Żarnecki based on his website content
##### RESPONSE:
Michał Żarnecki is a programmer and lecturer specializing in several key areas related to modern software development and data-driven technologies.
His expertise includes:
1. **Programming Languages**: Python, PHP, JavaScript.
2. **AI and Machine Learning**: Designing systems and solutions related to artificial intelligence and machine learning.
3. **Data Mining and Big Data**: Extracting valuable insights from large datasets.
4. **Natural Language Processing (NLP)**: Working on systems that understand and generate human language.
5. **Software Development Frameworks**: Utilizing various tools and frameworks such as Streamlit, TensorFlow, PyTorch, and langchain.
6. **Database Systems**: Implementing and working with databases like PostgreSQL, Elasticsearch, Neo4j, and others.
His portfolio highlights projects such as an AI chatbot for analyzing company documents and a self-driving vehicle based on TensorFlow and Raspberry Pi.
Additionally, he has contributed to conferences and created e-learning courses focused on machine learning, underscoring his dual role as a developer and educator.
##### INPUT:
Is Michał Żarnecki programmer the same person as Michał Żarnecki audio engineer?
##### RESPONSE:
Based on the information provided, it appears that Michał Żarnecki the programmer and Michał Żarnecki the audio engineer are not the same person.
Here’s why:
1. **Fields of Expertise**:
- Michał Żarnecki, the audio engineer, was a well-known operator and reżyser dźwięku (sound director) in Poland, with notable contributions to the Polish film industry, as mentioned in the Wikipedia excerpt.
- Michal Żarnecki, the programmer, has a portfolio focused on programming in Python, PHP, and JavaScript, with projects related to AI, machine learning, data mining, and software development.
2. **Lifespan**:
- Michał Żarnecki the audio engineer was born on November 12, 1946, and passed away on November 21, 2016.
- The projects listed in Michał Żarnecki the programmer’s portfolio date from 2014 to 2016, which would be conflicting if he had passed away in 2016 and was actively working in those years.
3. **Occupational Focus**:
- The audio engineer has a career documented in film sound engineering and education.
- The programmer’s career is centered around software development, mobile applications, ERP systems, and consulting in technology.
Given the distinct differences in their professional domains, timelines, and expertise, it is highly unlikely that they are the same individual
기본 사상:
전문가를 위한 자세한 내용:
문서 로딩 속도를 높이거나 더 나은 검색을 위해 더 많은 문서를 사용하려면 app/src/service/DocumentLoader.php:20에서 $skipFirstN 값을 조작하십시오.
PHP 스크립트를 변경한 후 다음 명령을 사용하여 Docker를 다시 빌드합니다.
docker-compose rm
docker rmi -f php-rag
docker-compose up
벡터 데이터베이스를 채우는 데 사용되는 웹사이트는 Kaggle의 "웹사이트 분류" 데이터세트에서 가져옵니다. 작성자: Hetul Mehta 링크: https://www.kaggle.com/datasets/hetulmehta/website-classification?resource=download
관련 기사/저장소:
https://medium.com/mlearning-ai/create-a-chatbot-in-python-with-langchain-and-rag-85bfba8c62d2
https://github.com/Krisseck/php-rag
https://ollama.com/download
에서 ollama를 다운로드하세요.ollama pull llama3:latest
사용하여 Llama 3 8B를 다운로드하세요.ollama pull mxbai-embed-large
ollama list
NAME ID SIZE MODIFIED
mxbai-embed-large:latest 468836162de7 669 MB 7 seconds ago
llama3:latest 365c0bd3c000 4.7 GB 17 seconds ago
ollama serve
시작app/src/loadDocuments.php
에서 MxbaiTextEncoder.php 클래스 사용(기본값) 문제점이나 개선할 점을 발견하시면 알려주시기 바랍니다. 이메일 주소 [email protected]로 저에게 연락하실 수 있습니다. 끌어오기 요청을 통해 자유롭게 버그를 보고하고 업그레이드를 제안하세요.