First commit
This commit is contained in:
73
app/Models/ChatLog.php
Normal file
73
app/Models/ChatLog.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ChatLog extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'chat_session_id',
|
||||
'user_id',
|
||||
'category_id',
|
||||
'question',
|
||||
'answer',
|
||||
'sources_used',
|
||||
'context_chunks',
|
||||
'model_used',
|
||||
'tokens_used',
|
||||
'response_time',
|
||||
'has_answer',
|
||||
'is_flagged',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'sources_used' => 'array',
|
||||
'context_chunks' => 'array',
|
||||
'has_answer' => 'boolean',
|
||||
'is_flagged' => 'boolean',
|
||||
'response_time' => 'float',
|
||||
];
|
||||
|
||||
// === Relationships ===
|
||||
|
||||
public function session(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ChatSession::class, 'chat_session_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function feedback(): HasOne
|
||||
{
|
||||
return $this->hasOne(ChatFeedback::class);
|
||||
}
|
||||
|
||||
// === Scopes ===
|
||||
|
||||
public function scopeFlagged(Builder $query): Builder
|
||||
{
|
||||
return $query->where('is_flagged', true);
|
||||
}
|
||||
|
||||
public function scopeNoAnswer(Builder $query): Builder
|
||||
{
|
||||
return $query->where('has_answer', false);
|
||||
}
|
||||
|
||||
public function scopeWithoutFeedback(Builder $query): Builder
|
||||
{
|
||||
return $query->whereDoesntHave('feedback');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user