62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
// Claude API 모델 테스트
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
||
|
|
|
||
|
|
if ($level > 5) {
|
||
|
|
die(json_encode(['error' => '접근 권한이 없습니다.']));
|
||
|
|
}
|
||
|
|
|
||
|
|
// API 키 읽기
|
||
|
|
$apiKeyFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/claude_api.txt';
|
||
|
|
$apiKey = trim(file_get_contents($apiKeyFile));
|
||
|
|
|
||
|
|
// 테스트할 모델들
|
||
|
|
$models = [
|
||
|
|
'claude-3-5-sonnet-20241022',
|
||
|
|
'claude-3-5-sonnet-20240620',
|
||
|
|
'claude-3-opus-20240229',
|
||
|
|
'claude-3-sonnet-20240229',
|
||
|
|
'claude-3-haiku-20240307'
|
||
|
|
];
|
||
|
|
|
||
|
|
$results = [];
|
||
|
|
|
||
|
|
foreach ($models as $model) {
|
||
|
|
$requestBody = [
|
||
|
|
'model' => $model,
|
||
|
|
'max_tokens' => 100,
|
||
|
|
'messages' => [
|
||
|
|
[
|
||
|
|
'role' => 'user',
|
||
|
|
'content' => 'Hello, just testing. Reply with OK.'
|
||
|
|
]
|
||
|
|
]
|
||
|
|
];
|
||
|
|
|
||
|
|
$ch = curl_init('https://api.anthropic.com/v1/messages');
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||
|
|
'Content-Type: application/json',
|
||
|
|
'x-api-key: ' . $apiKey,
|
||
|
|
'anthropic-version: 2023-06-01'
|
||
|
|
]);
|
||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBody));
|
||
|
|
|
||
|
|
$response = curl_exec($ch);
|
||
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||
|
|
curl_close($ch);
|
||
|
|
|
||
|
|
$responseData = json_decode($response, true);
|
||
|
|
|
||
|
|
$results[$model] = [
|
||
|
|
'status' => $httpCode,
|
||
|
|
'success' => ($httpCode === 200),
|
||
|
|
'error' => isset($responseData['error']) ? $responseData['error']['message'] : null,
|
||
|
|
'response' => $httpCode === 200 ? 'OK' : null
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
header('Content-Type: application/json');
|
||
|
|
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|