แอปพลิเคชันนี้ใช้ LLM (โมเดลภาษาขนาดใหญ่) GPT-4o ที่เข้าถึงผ่าน OpenAI API เพื่อสร้างข้อความตามอินพุตของผู้ใช้ การป้อนข้อมูลของผู้ใช้จะใช้ในการดึงข้อมูลที่เกี่ยวข้องจากฐานข้อมูล จากนั้นข้อมูลที่ดึงมาจะถูกนำมาใช้เพื่อสร้างข้อความ แนวทางนี้เป็นการผสมผสานพลังของหม้อแปลงไฟฟ้าและการเข้าถึงเอกสารต้นฉบับ
ในแอปพลิเคชันเฉพาะนี้ ฐานข้อมูลของเว็บไซต์มากกว่า 1,000 แห่งจะถูกค้นหาข้อมูลที่เกี่ยวข้องกับบุคคลใดบุคคลหนึ่ง ความท้าทายที่แท้จริงคือผู้ที่ถูกค้นหา "Michał Żarnecki" ปรากฏใน 2 บริบทที่แตกต่างกัน โดยเป็น 2 คนที่มีชื่อเดียวกัน เป้าหมายคือไม่เพียงแต่ค้นหาข้อมูลที่เฉพาะเจาะจง แต่ยังเข้าใจบริบทและหลีกเลี่ยงข้อผิดพลาด เช่น การผสมข้อมูลเกี่ยวกับคน 2 คนที่มีชื่อเดียวกัน
ฉันอธิบายแนวคิดที่ใช้ในแอปพลิเคชันนี้พร้อมรายละเอียดเพิ่มเติมในบทความใน medium.com https://medium.com/@michalzarnecki88/a-guide-to-using-llm-retrieval-augmented-generator-with-php-3bff25ce6616
สำหรับการตั้งค่าคุณต้องติดตั้ง Docker และ Docker Compose ก่อน https://docs.docker.com/compose/install/
ทำงานใน CLI: cd app/src && composer install
ตั้งค่าโมเดลภาษา - เลือกจากตัวเลือกด้านล่าง:ตัวเลือกด้วย OpenAI API
"A" พร้อมโมเดลฟรีผ่าน ollama API3 ในเครื่อง
"B" ด้วย OpenAI API
ตัวเลือก B นั้นง่ายกว่าและต้องการทรัพยากร CPU และ RAM น้อยกว่า แต่คุณต้องมีคีย์ OpenAI API https://platform.openai.com/settings/profile?tab=api-keys
ตัวเลือก A ต้องใช้ทรัพยากร CPU และ RAM มากกว่า แต่คุณสามารถทำงานได้ ในเครื่องโดยใช้ ollama API สำหรับตัวเลือกนี้ การมี GPU ถือเป็นการดี
ปฏิบัติตามคำแนะนำสำหรับตัวเลือก A หรือ B ที่ต้องการด้านล่าง:
หากคุณต้องการตั้งค่า ollama ในเครื่อง โปรดใช้คำแนะนำที่ด้านล่างของไฟล์นี้ แต่ในกรณีของการใช้นักเทียบท่า ก็ไม่จำเป็นต้องใช้
*Ollama ให้บริการ API ท้องถิ่นที่ให้บริการ LLM: "เริ่มต้นและใช้งานโมเดลภาษาขนาดใหญ่" 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 ollama:
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
แนวคิดพื้นฐาน:
รายละเอียดเพิ่มเติมสำหรับคนเนิร์ด:
เพื่อเพิ่มความเร็วในการโหลดเอกสารหรือใช้มากขึ้นเพื่อการดึงข้อมูลที่ดีขึ้น ให้จัดการค่า $skipFirstN ใน app/src/service/DocumentLoader.php:20
หลังจากการเปลี่ยนแปลงสคริปต์ PHP ให้สร้างนักเทียบท่าใหม่ด้วยคำสั่ง:
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 pull llama3:latest
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
(ค่าเริ่มต้น) โปรดแจ้งให้เราทราบหากคุณพบปัญหาหรือสิ่งที่ต้องปรับปรุง คุณสามารถติดต่อฉันได้ที่ที่อยู่อีเมล [email protected] อย่าลังเลที่จะรายงานจุดบกพร่องและเสนอการอัพเกรดในคำขอดึง