Files
crm.clientright.ru/allai2.php
Fedor ac7467f0b4 Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system
- Added comprehensive AI Assistant system (aiassist/ directory):
  * Vector search and embedding capabilities
  * Typebot proxy integration
  * Elastic search functionality
  * Message classification and chat history
  * MCP proxy for external integrations

- Implemented Court Status API (GetCourtStatus.php):
  * Real-time court document status checking
  * Integration with external court systems
  * Comprehensive error handling and logging

- Enhanced S3 integration:
  * Improved file backup system with metadata
  * Batch processing capabilities
  * Enhanced error logging and recovery
  * Copy operations with URL fixing

- Added Telegram contact creation API
- Improved error logging across all modules
- Enhanced callback system for AI responses
- Extensive backup file storage with timestamps
- Updated documentation and README files

- File storage improvements:
  * Thousands of backup files with proper metadata
  * Fix operations for broken file references
  * Project-specific backup and recovery systems
  * Comprehensive file integrity checking

Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
2025-10-16 11:17:21 +03:00

109 lines
4.0 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// 🔹 Настройки OpenAI API
const OPENAI_ASSISTANT_API = 'http://195.133.66.13:8000/v1/assistants';
const OPENAI_FILES_API = 'http://195.133.66.13:8000/v1/files';
const OPENAI_API_KEY = 'sk-NsasXO7IPLdzUSNaAy64R3EBveyIZNfIV3PaOEq5_WT3BlbkFJWTivsJpMK1J2YPfVDSMCrU6hQMxwEy64RktHVWEvEA'; // Замените на ваш API-ключ
const LOG_FILE = 'logs/assistants.log'; // Файл для логирования
// 🔹 Функция логирования
function logMessage($message) {
file_put_contents(LOG_FILE, date('Y-m-d H:i:s') . " - " . $message . "\n", FILE_APPEND | LOCK_EX);
}
// 🔹 1⃣ Получение списка ассистентов
function listAssistants() {
logMessage("Запрос списка ассистентов...");
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => OPENAI_ASSISTANT_API,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . OPENAI_API_KEY,
'OpenAI-Beta: assistants=v2'
]
]);
$response = curl_exec($curl);
curl_close($curl);
$decodedResponse = json_decode($response, true);
return $decodedResponse['data'] ?? [];
}
// 🔹 2⃣ Получение списка загруженных файлов
function listFilesForAssistant() {
logMessage("Запрос списка загруженных файлов...");
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => OPENAI_FILES_API,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . OPENAI_API_KEY,
'OpenAI-Beta: assistants=v2'
]
]);
$response = curl_exec($curl);
curl_close($curl);
$decodedResponse = json_decode($response, true);
return $decodedResponse['data'] ?? [];
}
// 🔹 3⃣ Основной скрипт
logMessage("Запуск скрипта для получения списка ассистентов и их документов.");
echo "<h1>Список ассистентов и загруженных файлов</h1>";
$assistants = listAssistants();
$files = listFilesForAssistant();
$fileMap = [];
foreach ($files as $file) {
$fileMap[$file['id']] = $file['filename'] ?? 'Неизвестное имя';
}
if (!empty($assistants)) {
logMessage("Вывод списка ассистентов в таблицу.");
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Имя</th><th>Модель</th><th>Инструкции</th><th>Создан</th><th>Файлы</th></tr>";
foreach ($assistants as $assistant) {
echo "<tr>";
echo "<td>" . htmlspecialchars($assistant['id']) . "</td>";
echo "<td>" . htmlspecialchars($assistant['name']) . "</td>";
echo "<td>" . htmlspecialchars($assistant['model']) . "</td>";
echo "<td><pre>" . htmlspecialchars($assistant['instructions']) . "</pre></td>";
echo "<td>" . date('Y-m-d H:i:s', $assistant['created_at']) . "</td>";
// 🔹 Выводим файлы, загруженные в ассистента
$fileList = [];
foreach ($assistant['tools'] ?? [] as $tool) {
if ($tool['type'] === 'file_search') {
foreach ($tool['file_ids'] ?? [] as $fileId) {
$fileList[] = $fileMap[$fileId] ?? "Неизвестный файл ($fileId)";
}
}
}
echo "<td>" . (!empty($fileList) ? implode("<br>", $fileList) : "Нет загруженных файлов") . "</td>";
echo "</tr>";
logMessage("Ассистент: " . json_encode($assistant, JSON_UNESCAPED_UNICODE));
}
echo "</table>";
} else {
logMessage("Ошибка: список ассистентов пуст.");
echo "<p>Ошибка: список ассистентов пуст.</p>";
}
logMessage("Завершение работы скрипта.");
?>