該應用程式使用透過 OpenAI API 存取的 LLM(大型語言模型)GPT-4o,以便根據使用者輸入來產生文字。使用者輸入用於從資料庫檢索相關信息,然後使用檢索到的信息生成文字。這種方法結合了 Transformer 的強大功能和對來源文件的存取。
在此特定應用程式中,將搜尋 1000 多個網站的資料庫以查找與特定人員相關的資訊。這裡真正的挑戰是,搜尋到的人「Michał Żarnecki」在 2 個不同的上下文中顯示為 2 個同名的不同人。目標不僅是找到特定訊息,還要了解上下文並避免錯誤,例如混淆兩個同名的不同人的信息。
我在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 的選項
“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,請使用此檔案底部的說明,但如果使用 docker,則不需要它。
*Ollama 提供本地 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 olama:
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
下載 ollamaollama 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
中的 MxbaiTextEncoder.php 類別(預設) 如果您發現任何問題或需要改進的地方,請告訴我。您可以透過電子郵件地址 [email protected] 與我聯繫。請隨意報告錯誤並在拉取請求中提出升級建議。