From ed123da101606754e3f640d7e0f8a1f137842721 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Tue, 19 Aug 2025 15:42:09 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BE=D1=87=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=20rag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - переименована папка - написан новый скрипт quickstart - отказ от requirements.txt - добавлен забытый и актуализированный README --- .gitignore | 9 +++ @rag/.gitignore | 10 ---- @rag/1_download_page.sh | 49 ---------------- @rag/requirements.txt | 96 ------------------------------- README.md | 20 ++++++- rag/.env.example | 6 ++ rag/1_download_page.sh | 43 ++++++++++++++ {@rag => rag}/2_html_to_md.py | 0 {@rag => rag}/3_rag.py | 0 {@rag => rag}/input_html/.gitkeep | 0 {@rag => rag}/output_md/.gitkeep | 0 rag/quickstart.sh | 26 +++++++++ {@rag => rag}/ready_rag/.gitkeep | 0 13 files changed, 101 insertions(+), 158 deletions(-) delete mode 100644 @rag/.gitignore delete mode 100755 @rag/1_download_page.sh delete mode 100644 @rag/requirements.txt create mode 100644 rag/.env.example create mode 100755 rag/1_download_page.sh rename {@rag => rag}/2_html_to_md.py (100%) rename {@rag => rag}/3_rag.py (100%) rename {@rag => rag}/input_html/.gitkeep (100%) rename {@rag => rag}/output_md/.gitkeep (100%) create mode 100755 rag/quickstart.sh rename {@rag => rag}/ready_rag/.gitkeep (100%) diff --git a/.gitignore b/.gitignore index d7a1aa8..af6c485 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ /.data/* +/rag/input_html/* +/rag/output_md/* +/rag/ready_rag/* +/rag/venv + +.env +*.html +*.md +*.sqlite* !.gitkeep diff --git a/@rag/.gitignore b/@rag/.gitignore deleted file mode 100644 index 72c9a9e..0000000 --- a/@rag/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -/input_html/* -/output_md/* -/ready_rag/* -/venv - -*.html -*.md -*.sqlite* - -!.gitkeep diff --git a/@rag/1_download_page.sh b/@rag/1_download_page.sh deleted file mode 100755 index e45e16e..0000000 --- a/@rag/1_download_page.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -DELAY=1 - -# 1. Указать реквизиты доступа к confluence -USERNAME="" -PASSWORD="" -CONFLUENCE_URL="" - -# 2. Вызвать: ./1_download_page.sh - -################################################################## - -if [ $# -lt 1 ]; then - echo "Usage: $0 " - exit 1 -fi - -command -v curl >/dev/null 2>&1 || { echo >&2 "Error: curl is required but not installed."; exit 1; } -command -v jq >/dev/null 2>&1 || { echo >&2 "Error: jq is required but not installed."; exit 1; } - -PAGE_ID="$1" -API_ENDPOINT="${CONFLUENCE_URL}/rest/api/content/${PAGE_ID}?expand=body.storage,children.page" - -echo -echo "Downloading: $API_ENDPOINT" - -response=$(curl -s -u "$USERNAME:$PASSWORD" -H "Accept: application/json" "${API_ENDPOINT}") -if [ $? -ne 0 ]; then - echo "Error: Failed to retrieve article" -fi - -error_message=$(echo "$response" | jq -r '.message' 2>/dev/null) -if [ -n "$error_message" ] && [ "$error_message" != "null" ]; then - echo "API Error: $error_message" -else - output_path="./input_html/" - title=$(echo "$response" | jq -r .title) - content=$(echo "$response" | jq -r .body.storage.value) - [ ! -d "$output_path" ] && mkdir -p "$output_path" - echo "$content" > "$output_path/$title.html" - echo "Saved as: $output_path/$title.html" - - child_ids=$(echo "$response" | jq -r '.children.page.results[]?.id' 2>/dev/null) - for child_id in $child_ids; do - echo "Downloading child page ID: $child_id" - sleep $DELAY - ./confluence_get_article.sh "$child_id" - done -fi diff --git a/@rag/requirements.txt b/@rag/requirements.txt deleted file mode 100644 index 88863ca..0000000 --- a/@rag/requirements.txt +++ /dev/null @@ -1,96 +0,0 @@ -apt-xapian-index==0.49 -aptdaemon==2.0.2 -argcomplete==3.5.3 -asn1crypto==1.5.1 -attrs==25.1.0 -autocommand==2.2.2 -bcc==0.30.0 -bcrypt==4.2.0 -blinker==1.9.0 -Brlapi==0.8.6 -certifi==2025.1.31 -chardet==5.2.0 -click==8.1.8 -command-not-found==0.3 -cryptography==43.0.0 -cupshelpers==1.0 -dbus-python==1.3.2 -defer==1.0.6 -distro==1.9.0 -distro-info==1.13 -docker==7.1.0 -docker-compose==1.29.2 -dockerpty==0.4.1 -docopt==0.6.2 -fuse-python==1.0.9 -html5lib-modern==1.2 -httplib2==0.22.0 -idna==3.10 -importlib_metadata==8.6.1 -inflect==7.3.1 -jaraco.context==6.0.1 -jaraco.functools==4.1.0 -jsonpointer==2.4 -jsonschema==4.19.2 -jsonschema-specifications==2023.12.1 -language-selector==0.1 -launchpadlib==2.1.0 -lazr.restfulclient==0.14.6 -lazr.uri==1.0.6 -louis==3.32.0 -markdown-it-py==3.0.0 -mdurl==0.1.2 -mechanize==0.4.10 -more-itertools==10.6.0 -netaddr==1.3.0 -netifaces==0.11.0 -oauthlib==3.2.2 -packaging==24.2 -pipx==1.7.1 -platformdirs==4.3.6 -psutil==5.9.8 -pycairo==1.27.0 -pycups==2.0.4 -Pygments==2.18.0 -PyGObject==3.50.0 -PyJWT==2.10.1 -pylibacl==0.7.2 -pyparsing==3.1.2 -PyQt5==5.15.11 -PyQt5_sip==12.17.0 -PyQt6==6.8.1 -PyQt6_sip==13.10.0 -python-apt==3.0.0 -python-dateutil==2.9.0 -python-debian==1.0.1+ubuntu1 -python-dotenv==1.0.1 -python-magic==0.4.27 -pyxattr==0.8.1 -pyxdg==0.28 -PyYAML==6.0.2 -referencing==0.35.1 -requests==2.32.3 -rich==13.9.4 -rpds-py==0.21.0 -s3cmd==2.4.0 -sentry-sdk==2.18.0 -ssh-import-id==5.11 -systemd-python==235 -texttable==1.7.0 -tornado==6.4.2 -typeguard==4.4.2 -typing_extensions==4.12.2 -ubuntu-drivers-common==0.0.0 -ubuntu-pro-client==8001 -ufw==0.36.2 -unattended-upgrades==0.1 -urllib3==2.3.0 -usb-creator==0.3.16 -userpath==1.9.2 -wadllib==2.0.0 -webencodings==0.5.1 -websocket-client==1.8.0 -wheel==0.45.1 -xdg==5 -xkit==0.0.0 -zipp==3.21.0 diff --git a/README.md b/README.md index 830c77e..84b99d8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Набор скриптов для быстрого запуска локальных LLM. Модели подбираются вручную, примерно в пределазх 40 млрд параметров (обычно, максимум 32b или 34b). -Такие модели наиболее реально запускать на среднем ПК. +Такие модели наиболее реально запускать на домашних ПК разных мощностей. Меньше параметров → меньше памяти на диске и в ОЗУ → выше скорость (tps) → ниже качество. @@ -12,9 +12,23 @@ Модели до 7 млрд достаточно хорошо отвечают (до 5-10 tps) на i5-9400 CPU 2.90GHz + 32 Гб ОЗУ без видеокарты, при условии, что в один момент времени одна модель обрабатывает один запрос. Например, [phi4-mini:3.8b](phi4-mini/3.8b), [qwen2.5:7b](qwen2.5/7b) или небольшая llama. +## Структура проекта + +``` +./ +├── models/ # Директория со скриптами установки моделей ollama +├── rag/ # Директория с инструментами для подготовки RAG +├── up # Скрипт для запуска ollama + open-webui +├── down # Скрипт для остановки ollama + open-webui +├── ollama # Скрипт для выполнения произвольных команд ollama +├── ollama.code-workspace # Конфигурация VSCode Workspace +└── README.md # Этот файл +``` + ## Стек * bash +* python, venv, pip * [docker](https://docker.com) * [ollama](https://ollama.com) * [open-webui](https://docs.openwebui.com) @@ -36,9 +50,9 @@ Плагины должны соединиться с `localhost:11434` и подгрузить доступные модели из контейнера. -## Использование RAG системы +### Использование RAG системы -Для работы RAG системы необходимо обратиться к документу [@rag/README.md](@rag/README.md). +Для работы RAG системы необходимо обратиться к документу [rag/README.md](rag/README.md). ## Дополнительные материалы diff --git a/rag/.env.example b/rag/.env.example new file mode 100644 index 0000000..04e6a41 --- /dev/null +++ b/rag/.env.example @@ -0,0 +1,6 @@ +# Адрес Confluence, например, https://confluence.company.ltd +CONF_URL= + +# Имя пользователя и его пароль для авторизации +CONF_USERNAME= +CONF_PASSWORD= diff --git a/rag/1_download_page.sh b/rag/1_download_page.sh new file mode 100755 index 0000000..f173474 --- /dev/null +++ b/rag/1_download_page.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +command -v curl >/dev/null 2>&1 || { echo >&2 "Ошибка: curl не установлен"; exit 1; } +command -v jq >/dev/null 2>&1 || { echo >&2 "Ошибка: jq не установлен"; exit 1; } + +if [ $# -lt 1 ]; then + echo >&2 "Ошибка: не указан ID страницы для загрузки" + echo "Использование: $0 " + exit 1 +fi + +PAGE_ID="$1" +API_ENDPOINT="${CONF_URL}/rest/api/content/${PAGE_ID}?expand=body.storage,children.page" + +echo +echo "Загрузка: $API_ENDPOINT" + +response=$(curl -s -u "$CONF_USERNAME:$CONF_PASSWORD" -H "Accept: application/json" "${API_ENDPOINT}") +if [ $? -ne 0 ]; then + echo "$response" + exit 1 +fi + +error_message=$(echo "$response" | jq -r '.message' 2>/dev/null) +if [ -n "$error_message" ] && [ "$error_message" != "null" ]; then + echo "$response" + exit 1 +fi + +output_path="./input_html/" +[ ! -d "$output_path" ] && mkdir -p "$output_path" + +title=$(echo "$response" | jq -r .title) +content=$(echo "$response" | jq -r .body.storage.value) +echo "$content" > "$output_path/$title.html" +echo "Сохранено: $output_path/$title.html" + +child_ids=$(echo "$response" | jq -r '.children.page.results[]?.id' 2>/dev/null) +for child_id in $child_ids; do + echo "Переход к дочерней странице: $child_id" + sleep 1 + $0 "$child_id" +done diff --git a/@rag/2_html_to_md.py b/rag/2_html_to_md.py similarity index 100% rename from @rag/2_html_to_md.py rename to rag/2_html_to_md.py diff --git a/@rag/3_rag.py b/rag/3_rag.py similarity index 100% rename from @rag/3_rag.py rename to rag/3_rag.py diff --git a/@rag/input_html/.gitkeep b/rag/input_html/.gitkeep similarity index 100% rename from @rag/input_html/.gitkeep rename to rag/input_html/.gitkeep diff --git a/@rag/output_md/.gitkeep b/rag/output_md/.gitkeep similarity index 100% rename from @rag/output_md/.gitkeep rename to rag/output_md/.gitkeep diff --git a/rag/quickstart.sh b/rag/quickstart.sh new file mode 100755 index 0000000..370df44 --- /dev/null +++ b/rag/quickstart.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +command -v python3 >/dev/null 2>&1 || { echo >&2 "Ошибка: python3 не установлен"; exit 1; } +command -v pip >/dev/null 2>&1 || { echo >&2 "Ошибка: pip не установлен"; exit 1; } + +[ ! -f .env ] && cp .env.example .env +source .env + +[ -z "$CONF_URL" ] && { echo >&2 "Ошибка: CONF_URL не указан в файле .env"; exit 1; } +[ -z "$CONF_USERNAME" ] && { echo >&2 "Ошибка: CONF_USERNAME не указан в файле .env"; exit 1; } +[ -z "$CONF_PASSWORD" ] && { echo >&2 "Ошибка: CONF_PASSWORD не указан в файле .env"; exit 1; } + +echo "Поиск зависимостей..." + +python3 -m venv venv +source venv/bin/activate +[ "$(pip install --dry-run chromadb 2>&1 | grep -c 'Would install')" -gt 0 ] && pip install chromadb +[ "$(pip install --dry-run numpy 2>&1 | grep -c 'Would install')" -gt 0 ] && pip install numpy +[ "$(pip install --dry-run requests 2>&1 | grep -c 'Would install')" -gt 0 ] && pip install requests +[ "$(pip install --dry-run beautifulsoup4 2>&1 | grep -c 'Would install')" -gt 0 ] && pip install beautifulsoup4 + +echo "Начало работы" +./1_download_page.sh "$@" || exit 1 +python3 ./2_html_to_md.py +python3 ./3_rag.py --action build +python3 ./3_rag.py --action interactive diff --git a/@rag/ready_rag/.gitkeep b/rag/ready_rag/.gitkeep similarity index 100% rename from @rag/ready_rag/.gitkeep rename to rag/ready_rag/.gitkeep