Files
crm.clientright.ru/aiassist/gpt_handler.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

64 lines
3.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// assistance/gpt_handler.php
/**
* Функция формирования запроса и получения финального анализа от GPT.
*
* @param string $combinedContent Объединённый текст для анализа (например, объединённый текст всех документов кейса).
* @param array $searchResults Результаты семантического поиска, которые можно использовать как контекст.
* @param array $caseDetails Извлечённые данные (истец, ответчик, суть спора) для уточнения запроса.
* @return array Результат анализа от GPT, включая вывод и вердикт.
*/
function analyzeDocumentWithGPT($combinedContent, $searchResults, $caseDetails) {
// Формируем промпт для GPT, объединяя информацию:
$prompt = "Проанализируй следующие данные:\n";
$prompt .= "Детали кейса:\n";
$prompt .= "Истец: " . ($caseDetails['истец'] ?? 'Не определено') . "\n";
$prompt .= "Ответчик: " . ($caseDetails['ответчик'] ?? 'Не определено') . "\n";
$prompt .= "Суть спора: " . ($caseDetails['суть_спора'] ?? 'Не определено') . "\n\n";
$prompt .= "Содержимое документов:\n" . $combinedContent . "\n\n";
$prompt .= "Найденные похожие решения:\n" . json_encode($searchResults, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
$prompt .= "Сформируй подробный анализ, укажи вердикт, вероятность выигрыша дела, а также рекомендации по дальнейшим действиям.";
// Параметры для запроса к OpenAI
$data = [
"assistant_id" => ASSISTANT_ID,
"thread" => [
"messages" => [
["role" => "user", "content" => $prompt]
]
],
"stream" => false
];
$payload = json_encode($data, JSON_UNESCAPED_UNICODE);
// Настройка cURL для запроса в OpenAI
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => OPENAI_THREADS_API . "/runs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . OPENAI_API_KEY,
'OpenAI-Beta: assistants=v2'
]
]);
$response = curl_exec($curl);
$curlError = curl_error($curl);
curl_close($curl);
if ($curlError) {
logMessage("Ошибка cURL в analyzeDocumentWithGPT: " . $curlError);
return null;
}
$result = json_decode($response, true);
// Здесь можно добавить дополнительную обработку ответа, например, извлечение вердикта
return $result;
}
?>