Skip to content

Commit

Permalink
Make sure the controller creates meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jul 3, 2024
1 parent b6ce75b commit f6693ea
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public function chat(Chat $chat)
$message = $chat->addInput(
message: $input,
role: RoleEnum::User,
show_in_thread: true);
show_in_thread: true,
meta_data: $meta_data);

$messagesArray = [];

Expand Down
1 change: 1 addition & 0 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Message extends Model
'role',
'in_out',
'is_chat_ignored',
'meta_data',
];

protected $dispatchesEvents = [
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/Http/Controllers/ChatControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Feature\Http\Controllers;

use App\Domains\Agents\VerifyPromptOutputDto;
use App\Domains\Chat\DateRangesEnum;
use App\Domains\Messages\RoleEnum;
use App\Models\Chat;
use App\Models\Collection;
Expand Down Expand Up @@ -79,6 +80,35 @@ public function test_will_verify_on_completion(): void
$this->assertEquals('test', $message->body);
}

public function test_adds_meta_data_and_date_range()
{
$user = User::factory()->create();
$collection = Collection::factory()->create();
$chat = Chat::factory()->create([
'chatable_id' => $collection->id,
'chatable_type' => Collection::class,
'user_id' => $user->id,
]);

Orchestrate::shouldReceive('handle')->once()->andReturn('Yo');

$this->assertDatabaseCount('messages', 0);
$this->actingAs($user)->post(route('chats.messages.create', [
'chat' => $chat->id,
]),
[
'system_prompt' => 'Foo',
'input' => 'user input',
'date_range' => DateRangesEnum::ThisWeek->value,
])->assertOk();


$this->assertDatabaseCount('messages', 1);

$message = Message::first();
$this->assertEquals("this_week", $message->meta_data->date_range);
}

public function test_a_function_based_chat()
{
$user = User::factory()->create();
Expand Down

0 comments on commit f6693ea

Please sign in to comment.