Migrate to laravel ai sdk (#181)
Also * upgrade to livewire 4 * replace rappsoft tables with filament
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class AgentConversationMessage extends Model
|
||||
{
|
||||
protected $table = 'agent_conversation_messages';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'conversation_id',
|
||||
'user_id',
|
||||
'agent',
|
||||
'role',
|
||||
'content',
|
||||
];
|
||||
|
||||
public function conversation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ChatWithConversation::class, 'conversation_id');
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AiChat extends Model
|
||||
{
|
||||
use HasUuids;
|
||||
|
||||
protected $fillable = [
|
||||
'role',
|
||||
'content',
|
||||
];
|
||||
|
||||
protected $hidden = [];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($chat) {
|
||||
|
||||
$chat->user_id = auth()->user()->id;
|
||||
});
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function chatable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ChatWithConversation extends Model
|
||||
{
|
||||
protected $table = 'agent_conversations';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'user_id',
|
||||
'title',
|
||||
'chatable_type',
|
||||
'chatable_id',
|
||||
];
|
||||
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function (ChatWithConversation $model) {
|
||||
if (empty($model->id)) {
|
||||
$model->id = (string) Str::uuid7();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function chatable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function messages(): HasMany
|
||||
{
|
||||
return $this->hasMany(AgentConversationMessage::class, 'conversation_id');
|
||||
}
|
||||
}
|
||||
+8
-10
@@ -8,7 +8,9 @@ use App\Traits\HasMarketData;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
@@ -161,14 +163,10 @@ class Holding extends Model
|
||||
->orderBy('date', 'DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* Related chats for holding
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function chats()
|
||||
public function chatWithConversation(): MorphOne
|
||||
{
|
||||
return $this->morphMany(AiChat::class, 'chatable')->where('user_id', auth()->user()->id);
|
||||
return $this->morphOne(ChatWithConversation::class, 'chatable')
|
||||
->where('user_id', auth()->id());
|
||||
}
|
||||
|
||||
public function scopeWithMarketData($query)
|
||||
@@ -449,7 +447,7 @@ class Holding extends Model
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function qtyOwned(?\Illuminate\Support\Carbon $date = null)
|
||||
public function qtyOwned(?Carbon $date = null)
|
||||
{
|
||||
if ($date == null) {
|
||||
$date = now();
|
||||
@@ -470,8 +468,8 @@ class Holding extends Model
|
||||
* @return void
|
||||
*/
|
||||
public function dailyPerformance(
|
||||
?\Illuminate\Support\Carbon $start_date = null,
|
||||
?\Illuminate\Support\Carbon $end_date = null,
|
||||
?Carbon $start_date = null,
|
||||
?Carbon $end_date = null,
|
||||
) {
|
||||
if ($start_date == null) {
|
||||
$start_date = now();
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Models;
|
||||
|
||||
use App\Interfaces\MarketData\MarketDataInterface;
|
||||
use App\Models\ChatWithConversation;
|
||||
use App\Notifications\InvitedOnboardingNotification;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
@@ -68,14 +69,10 @@ class Portfolio extends Model
|
||||
return $this->hasMany(DailyChange::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Related chats for portfolio
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function chats()
|
||||
public function chatWithConversation(): \Illuminate\Database\Eloquent\Relations\MorphOne
|
||||
{
|
||||
return $this->morphMany(AiChat::class, 'chatable')->where('user_id', auth()->user()->id);
|
||||
return $this->morphOne(ChatWithConversation::class, 'chatable')
|
||||
->where('user_id', auth()->id());
|
||||
}
|
||||
|
||||
public function scopeMyPortfolios()
|
||||
|
||||
Reference in New Issue
Block a user