-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai-test.php
More file actions
62 lines (49 loc) · 1.75 KB
/
ai-test.php
File metadata and controls
62 lines (49 loc) · 1.75 KB
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
<?php
/**
* Simple test endpoint for AI comment generation
* This endpoint simulates an AI API for testing purposes
*/
header('Content-Type: application/json');
// Only allow POST requests
if ( $_SERVER['REQUEST_METHOD'] !== 'POST' ) {
http_response_code(405);
echo json_encode(array('error' => 'Method not allowed. Use POST.'));
exit;
}
// Read JSON input
$input = file_get_contents('php://input');
$data = json_decode($input, true);
if ( !$data ) {
http_response_code(400);
echo json_encode(array('error' => 'Invalid JSON'));
exit;
}
// Validate required fields
if ( !isset($data['instructions']) || !isset($data['paper']) ) {
http_response_code(400);
echo json_encode(array('error' => 'Missing required fields: instructions and paper'));
exit;
}
$instructions = $data['instructions'];
$paper = $data['paper'];
$max_length = isset($data['max_length']) ? intval($data['max_length']) : 500;
// Simple test implementation
$word_count = str_word_count(strip_tags($paper));
$instructions_length = strlen(trim($instructions));
// Generate a test comment
$comment = "This is a test AI-generated comment from the test endpoint. ";
$comment .= "Your paper contains approximately {$word_count} words. ";
if ( !empty($instructions) ) {
$comment .= "The rubric/instructions (" . $instructions_length . " characters) have been considered. ";
}
$comment .= "This is simulated feedback - in production, this would be actual AI analysis of your paper against the rubric. ";
// Truncate if needed
if ( strlen($comment) > $max_length ) {
$comment = substr($comment, 0, $max_length - 3) . '...';
}
// Return response in expected format
echo json_encode(array(
'comment' => $comment,
'test_mode' => true,
'word_count' => $word_count
));