File size: 2,648 Bytes
fd06b5a |
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 |
"""
Quick test script to upload and query the test_policy.txt document
"""
import requests
import os
# Configuration
API_BASE = "http://localhost:8000"
TEST_FILE = "uploads/test_policy.txt"
def test_document_query():
"""Test uploading and querying a document"""
# Check if file exists
if not os.path.exists(TEST_FILE):
print(f"❌ File not found: {TEST_FILE}")
return
# Step 1: Upload the file
print("📤 Step 1: Uploading test_policy.txt...")
with open(TEST_FILE, 'rb') as f:
files = {'file': (os.path.basename(TEST_FILE), f, 'text/plain')}
response = requests.post(f"{API_BASE}/upload", files=files)
if response.status_code != 200:
print(f"❌ Upload failed: {response.text}")
return
upload_result = response.json()
print(f"✅ Upload successful!")
print(f" File path: {upload_result['file_path']}")
print(f" Document ID: {upload_result['document_id']}")
file_path = upload_result['file_path']
# Step 2: Query about remote work policy
print("\n🤔 Step 2: Asking 'What is the remote work policy?'...")
response = requests.post(
f"{API_BASE}/chat",
json={
"query": "What is the remote work policy?",
"file_path": file_path
}
)
if response.status_code != 200:
print(f"❌ Query failed: {response.text}")
return
result = response.json()
print(f"\n✅ Response:\n{result['response']}")
# Step 3: Query about specific details
print("\n\n🤔 Step 3: Asking 'What equipment does the company provide?'...")
response = requests.post(
f"{API_BASE}/chat",
json={
"query": "What equipment does the company provide for remote work?",
"file_path": file_path
}
)
if response.status_code == 200:
result = response.json()
print(f"\n✅ Response:\n{result['response']}")
# Step 4: Query about work hours
print("\n\n🤔 Step 4: Asking 'What are the core hours?'...")
response = requests.post(
f"{API_BASE}/chat",
json={
"query": "What are the core work hours for remote employees?",
"file_path": file_path
}
)
if response.status_code == 200:
result = response.json()
print(f"\n✅ Response:\n{result['response']}")
if __name__ == "__main__":
print("=" * 60)
print("DOCUMENT AGENT TEST - Remote Work Policy")
print("=" * 60)
test_document_query()
print("\n" + "=" * 60)
print("TEST COMPLETED!")
print("=" * 60)
|