You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
5.1 KiB

import requests
import json
import time
def test_summarize_document():
"""
Test the document summarization functionality of the LLM server by sending a POST request
to the summarize_document endpoint.
This function creates a sample document, sends it to the LLM server, and then polls for results.
"""
print("Testing document summarization...")
# Define server endpoint
url = "http://localhost:8100/summarise_document"
# Create a sample document
sample_document = {
"arango_doc": {
"text": """
The Impact of Climate Change on Coral Reefs
Climate change has significantly affected marine ecosystems worldwide, with coral reefs being among the most vulnerable.
Rising sea temperatures have led to increased coral bleaching events, where corals expel their symbiotic algae,
leading to whitening and potential death. Studies show that even a 1-2°C increase in water temperature
can trigger mass bleaching events. Additionally, ocean acidification caused by increased CO2 absorption
makes it difficult for corals to build their calcium carbonate skeletons.
Recent research by Johnson et al. (2023) suggests that if current trends continue, we may lose up to 90%
of coral reefs by 2050. However, some corals have shown remarkable resilience. Certain species can adapt
to higher temperatures through a process called adaptive bleaching, where they exchange their algal symbionts
for more heat-tolerant varieties. Conservation efforts focused on cultivating these resilient species may
provide hope for reef preservation.
""",
"chunks": []
},
"arango_db_name": "test_db",
"arango_id": "articles/test_article",
"is_sci": True
}
# Send request to server
print("Sending document to server for summarization...")
response = requests.post(url, json=sample_document)
if response.status_code == 200:
print("Request accepted. Response:", response.json())
# In a real-world scenario, you might poll the database to see when the summary is ready
print("Note: In a real implementation, you would check the database for results.")
print("Since this is just a test, we're showing how the request works.")
return True
else:
print(f"Error: {response.status_code}")
print(response.text)
return False
def test_summarize_chunks():
"""
Test the chunk summarization functionality directly by creating a sample document with chunks.
In a real application, you'd typically query the results from the database after processing.
"""
print("\nTesting chunk summarization example...")
# Sample document with chunks
sample_document_with_chunks = {
"arango_doc": {
"text": "",
"chunks": [
{
"text": "Climate change has significantly affected marine ecosystems worldwide, with coral reefs being among the most vulnerable. Rising sea temperatures have led to increased coral bleaching events.",
"pages": [1]
},
{
"text": "Studies by Smith et al. [1] show that even a 1-2°C increase in water temperature can trigger mass bleaching events. Additionally, ocean acidification makes it difficult for corals to build their calcium carbonate skeletons.",
"pages": [1, 2]
}
]
},
"arango_db_name": "test_db",
"arango_id": "interviews/test_interview",
"is_sci": False
}
# In a real implementation, you would:
# 1. Send this document to the server
# 2. Check the database later to see the summarized chunks
url = "http://localhost:8100/summarise_document"
print("Sending document with chunks for summarization...")
response = requests.post(url, json=sample_document_with_chunks)
if response.status_code == 200:
print("Request accepted. Response:", response.json())
return True
else:
print(f"Error: {response.status_code}")
print(response.text)
return False
if __name__ == "__main__":
print("LLM Server Test Script")
print("=====================\n")
# Test if server is running
try:
requests.get("http://localhost:8100")
print("Server is running at http://localhost:8100\n")
except requests.exceptions.ConnectionError:
print("ERROR: Cannot connect to server at http://localhost:8100")
print("Make sure the server is running before continuing.\n")
exit(1)
# Run tests
test_summarize_document()
time.sleep(2) # Brief pause between tests
test_summarize_chunks()
print("\nTest script completed. Check your ArangoDB instance for results.")
print("Note: Document summarization happens in background tasks, so results may not be immediate.")
print("You would typically query the database to see the updated documents with summaries.")