Files
hotels/N8N_HTTP_REQUEST_NATASHA.md
Фёдор 684fada337 🚀 Full project sync: Hotels RAG & Audit System
 Major Features:
- Complete RAG system for hotel website analysis
- Hybrid audit with BGE-M3 embeddings + Natasha NER
- Universal horizontal Excel reports with dashboards
- Multi-region processing (SPb, Orel, Chukotka, Kamchatka)

📊 Completed Regions:
- Орловская область: 100% (36/36)
- Чукотский АО: 100% (4/4)
- г. Санкт-Петербург: 93% (893/960)
- Камчатский край: 87% (89/102)

🔧 Infrastructure:
- PostgreSQL with pgvector extension
- BGE-M3 embeddings API
- Browserless for web scraping
- N8N workflows for automation
- S3/Nextcloud file storage

📝 Documentation:
- Complete DB schemas
- API documentation
- Setup guides
- Status reports
2025-10-27 22:49:42 +03:00

4.6 KiB
Raw Blame History

🔗 HTTP REQUEST для Natasha NER в n8n

📡 НАСТРОЙКИ HTTP REQUEST NODE:

Базовая информация:

  • Name: Natasha NER Check
  • Method: POST
  • URL: http://localhost:8004/extract_simple

Headers:

Content-Type: application/json
Accept: application/json

Body (JSON):

{
  "text": "{{ $json.quote }}",
  "max_length": 5000
}

Options:

  • Timeout: 30000 (30 секунд)
  • Response Format: JSON

📋 ГОТОВЫЙ cURL ДЛЯ ИМПОРТА:

Вариант 1: Для локального n8n (на том же сервере)

curl -X POST 'http://localhost:8004/extract_simple' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d '{
    "text": "{{ $json.quote }}",
    "max_length": 5000
  }'

Вариант 2: Если n8n на другом сервере

Нужно открыть порт 8004 или использовать SSH туннель:

# SSH туннель (запусти на машине с n8n)
ssh -L 8004:localhost:8004 root@147.45.146.17

# Затем в n8n используй:
# URL: http://localhost:8004/extract_simple

🎯 ИМПОРТ В n8n (ПОШАГОВО):

ШАГ 1: Создай HTTP Request Node

  1. Добавь ноду "HTTP Request"
  2. Назови: "Natasha NER"

ШАГ 2: Настрой Authentication

  • Authentication: None (API без авторизации)

ШАГ 3: Настрой Request

  • Method: POST
  • URL: http://localhost:8004/extract_simple

ШАГ 4: Настрой Headers

Добавь 2 заголовка:

  1. Content-Type: application/json
  2. Accept: application/json

ШАГ 5: Настрой Body

  • Body Content Type: JSON
  • Specify Body: Using JSON
  • JSON:
{
  "text": "={{ $json.quote }}",
  "max_length": 5000
}

ШАГ 6: Настрой Options

  • Timeout: 30000
  • Response Format: Auto-detect (JSON)

📊 ОЖИДАЕМЫЙ ОТВЕТ:

{
  "organizations": ["ИП", "Фролов С.А."],
  "persons": ["Иван Петров"],
  "locations": ["Петропавловск-Камчатский", "Пограничная"],
  "has_organizations": true,
  "has_persons": true,
  "has_locations": true,
  "total": 4
}

💻 CODE NODE ПОСЛЕ HTTP REQUEST:

// Обрабатываем ответ от Natasha API

const criterion = $input.item.json;
const nerResult = $('Natasha NER').first().json;

// Определяем NER score в зависимости от критерия
let nerScore = 0.0;
let nerEntities = [];

if (criterion.criterion_id === 1) {
  // Критерий 1: Организации
  if (nerResult.has_organizations) {
    nerScore = 1.0;
    nerEntities = nerResult.organizations;
  }
} else if (criterion.criterion_id === 2) {
  // Критерий 2: Адреса
  if (nerResult.has_locations) {
    nerScore = 1.0;
    nerEntities = nerResult.locations;
  }
}

// Комбинируем с regex score
const regexScore = parseFloat(criterion.score) || 0.0;
const finalScore = Math.max(regexScore, nerScore);

return {
  json: {
    ...criterion,
    ner_score: nerScore,
    ner_entities: nerEntities,
    final_score: finalScore,
    method: finalScore === nerScore ? 'Natasha NER' :
            finalScore === regexScore ? 'Регулярные выражения' :
            'Гибрид'
  }
};

🔧 ПРОВЕРКА ДОСТУПНОСТИ:

# Локально (на сервере)
curl http://localhost:8004/health

# Извне (если порт открыт)
curl http://147.45.146.17:8004/health

# Если не работает извне - открой порт в firewall:
# sudo ufw allow 8004/tcp

🚀 БЫСТРЫЙ ТЕСТ:

# Тест с реальным текстом
curl -X POST 'http://localhost:8004/extract_simple' \
  -H 'Content-Type: application/json' \
  -d '{
    "text": "Гостиница Певек, ИНН 8707003759, ОГРН 1028700516476. Адрес: г. Певек, ул. Ленина, 10. Директор Иван Иванов.",
    "max_length": 5000
  }'

Ожидаемый ответ:

{
  "organizations": ["Гостиница Певек"],
  "persons": ["Иван Иванов"],
  "locations": ["Певек", "ул. Ленина"],
  "has_organizations": true,
  "has_persons": true,
  "has_locations": true,
  "total": 4
}

Готово! Используй этот cURL в n8n! 🚀