File size: 5,267 Bytes
6ee1a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Тест HuggingFace Space
# Запустите после успешного деплоя

$baseUrl = "https://calcifer0323-matching.hf.space"

Write-Host "🧪 Тестирование HuggingFace Space: $baseUrl" -ForegroundColor Cyan
Write-Host ""

# Test 1: Health Check
Write-Host "1️⃣ Health Check..." -ForegroundColor Yellow
try {
    $health = Invoke-RestMethod -Uri "$baseUrl/health" -Method Get
    Write-Host "   ✅ Status: $($health.status)" -ForegroundColor Green
    Write-Host "   ✅ Model: $($health.model)" -ForegroundColor Green
    Write-Host "   ✅ Dimensions: $($health.embedding_dimensions)" -ForegroundColor Green
} catch {
    Write-Host "   ❌ Error: $($_.Exception.Message)" -ForegroundColor Red
    Write-Host "   💡 Space может еще собираться. Подождите 2-3 минуты." -ForegroundColor Yellow
    exit
}

Write-Host ""

# Test 2: Single Embedding
Write-Host "2️⃣ Генерация одного эмбеддинга..." -ForegroundColor Yellow
try {
    $body = @{
        text = "Современная трёхкомнатная квартира в центре Москвы"
    } | ConvertTo-Json

    $embedding = Invoke-RestMethod -Uri "$baseUrl/embed" -Method Post -Body $body -ContentType "application/json"
    Write-Host "   ✅ Embedding dimensions: $($embedding.dimensions)" -ForegroundColor Green
    Write-Host "   ✅ Vector length: $($embedding.embedding.Count)" -ForegroundColor Green
    Write-Host "   ✅ First 5 values: $($embedding.embedding[0..4] -join ', ')" -ForegroundColor Green
} catch {
    Write-Host "   ❌ Error: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host ""

# Test 3: Batch Embeddings
Write-Host "3️⃣ Пакетная генерация эмбеддингов..." -ForegroundColor Yellow
try {
    $body = @{
        texts = @(
            "Студия 30 кв.м, ремонт, метро рядом",
            "2-комнатная квартира, 65 кв.м, Арбат",
            "Пентхаус с панорамным видом"
        )
    } | ConvertTo-Json

    $batch = Invoke-RestMethod -Uri "$baseUrl/embed-batch" -Method Post -Body $body -ContentType "application/json"
    Write-Host "   ✅ Embeddings count: $($batch.embeddings.Count)" -ForegroundColor Green
    Write-Host "   ✅ Dimensions: $($batch.dimensions)" -ForegroundColor Green
} catch {
    Write-Host "   ❌ Error: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host ""

# Test 4: Register Property
Write-Host "4️⃣ Регистрация объекта недвижимости..." -ForegroundColor Yellow
try {
    $body = @{
        entity_type = "properties"
        entity_id = "test-prop-001"
        text = "Просторная 3-комнатная квартира 85 кв.м, современный ремонт, район Арбат"
        metadata = @{
            price = 25000000
            rooms = 3
            area = 85
            location = "Арбат"
        }
    } | ConvertTo-Json -Depth 3

    $register = Invoke-RestMethod -Uri "$baseUrl/register" -Method Post -Body $body -ContentType "application/json"
    Write-Host "   ✅ Registered: $($register.entity_id)" -ForegroundColor Green
    Write-Host "   ✅ Type: $($register.entity_type)" -ForegroundColor Green
} catch {
    Write-Host "   ❌ Error: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host ""

# Test 5: Search Similar
Write-Host "5️⃣ Поиск похожих объектов..." -ForegroundColor Yellow
try {
    $body = @{
        entity_type = "properties"
        query_text = "Хочу купить просторную квартиру в центре Москвы"
        top_k = 5
        min_similarity = 0.0
    } | ConvertTo-Json

    $matches = Invoke-RestMethod -Uri "$baseUrl/match-text" -Method Post -Body $body -ContentType "application/json"
    Write-Host "   ✅ Matches found: $($matches.matches.Count)" -ForegroundColor Green
    if ($matches.matches.Count -gt 0) {
        Write-Host "   ✅ Top match ID: $($matches.matches[0].entity_id)" -ForegroundColor Green
        Write-Host "   ✅ Similarity: $([math]::Round($matches.matches[0].similarity, 4))" -ForegroundColor Green
    }
} catch {
    Write-Host "   ❌ Error: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host ""

# Test 6: Stats
Write-Host "6️⃣ Статистика хранилища..." -ForegroundColor Yellow
try {
    $stats = Invoke-RestMethod -Uri "$baseUrl/store/stats" -Method Get
    Write-Host "   ✅ Total entities: $($stats.total_entities)" -ForegroundColor Green
    Write-Host "   ✅ Properties: $($stats.by_type.properties)" -ForegroundColor Green
    Write-Host "   ✅ Model: $($stats.model)" -ForegroundColor Green
} catch {
    Write-Host "   ❌ Error: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host ""
Write-Host "=" * 60 -ForegroundColor Cyan
Write-Host "🎉 Все тесты завершены!" -ForegroundColor Green
Write-Host ""
Write-Host "📚 Swagger UI: $baseUrl/docs" -ForegroundColor Cyan
Write-Host "📖 ReDoc: $baseUrl/redoc" -ForegroundColor Cyan
Write-Host "🏠 Space: https://huggingface.co/spaces/Calcifer0323/matching" -ForegroundColor Cyan
Write-Host ""