/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/models/BatchLog.php
141 строка
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\models; use Yii; use yii\db\ActiveQuery; use yii\helpers\ArrayHelper; use yii\helpers\Json; use yii\web\ServerErrorHttpException; /** * Логирование запросов к AI * * @property integer $request_batch_id * @property integer $request_id * @property integer $response_id * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2025 * @deprecated */ class BatchLog extends \common\models\base\BaseModel { /** * {@inheritdoc} */ public static function tableName() { return 'batch_log'; } /** * @inheritdoc */ public static function primaryKey() { return ['request_batch_id']; } /** * {@inheritdoc} */ public function rules() { return ArrayHelper::merge(parent::rules(), [ [ [ 'request_batch_id', 'request_id', ], 'required' ], [ [ 'request_batch_id', 'request_id', 'response_id', ], 'number' ], ]); } /** * {@inheritdoc} */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'request_batch_id' => Yii::t('app', 'Request Batch'), 'request_id' => Yii::t('app', 'Request'), 'response_id' => Yii::t('app', 'Response'), ]); } /** * @return ActiveQuery */ public function getRequestBatch() { return $this->hasOne(RequestBatch::class, ['id' => 'request_batch_id']); } /** * @return ActiveQuery */ public function getRequest() { return $this->hasOne(TextSegment::class, ['id' => 'request_id']); } /** * @return ActiveQuery */ public function getResponse() { return $this->hasOne(TextSegment::class, ['id' => 'response_id']); } /** * Создать лог-запрос * @param $batch_id * @param $body * @return void * @throws ServerErrorHttpException * @throws \yii\db\Exception */ public static function createRequest($batch_id, $body) { $segment = TextSegment::setText(Json::encode($body)); $bl = BatchLog::findOrNew([ 'request_batch_id' => $batch_id, ]); $bl->setAttributes([ 'request_id' => $segment->id ]); if (!$bl->save()) { throw new ServerErrorHttpException(Yii::t('app', 'Error save BatchLog')); } } /** * Создать лог-ответ * @param $batch_id * @param $body * @return void * @throws ServerErrorHttpException * @throws \yii\db\Exception */ public static function createResponse($batch_id, $body) { $segment = TextSegment::setText(Json::encode($body)); BatchLog::updateAll([ 'response_id' => $segment->id ], [ 'request_batch_id' => $batch_id, ]); } }