Skip to content

Commit 43fa5b9

Browse files
committed
ready to merge
1 parent fda9025 commit 43fa5b9

File tree

16 files changed

+43
-62
lines changed

16 files changed

+43
-62
lines changed

Modules/LlmDriver/app/BaseClient.php

-2
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,10 @@ public function modifyPayload(array $payload, bool $noTools = false): array
121121
$payload['tools'] = $this->getFunctions();
122122
}
123123

124-
125124
if ($this->system) {
126125
$payload['system'] = $this->system;
127126
}
128127

129-
130128
$payload = $this->addJsonFormat($payload);
131129

132130
return $payload;

Modules/LlmDriver/app/ClaudeClient.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,20 @@ public function remapMessages(array $messages, bool $userLast = false): array
357357
return true;
358358
})
359359
->transform(function (MessageInDto $item) {
360-
/**
361-
* @NOTE
362-
* Claude does not like to end a certain way
363-
*/
364-
$item->content = str(
365-
cleanString($item->content)
366-
)->replaceEnd("\n", '')->trim()->toString();
367-
368-
if (empty($item->content)) {
369-
$item->content = 'See content in thread.';
370-
}
360+
/**
361+
* @NOTE
362+
* Claude does not like to end a certain way
363+
*/
364+
$item->content = str(
365+
cleanString($item->content)
366+
)->replaceEnd("\n", '')->trim()->toString();
367+
368+
if (empty($item->content)) {
369+
$item->content = 'See content in thread.';
370+
}
371371

372-
return $item->toArray();
373-
});
372+
return $item->toArray();
373+
});
374374

375375
/**
376376
* Claude needs me to not use the role tool

Modules/LlmDriver/app/Functions/CreateTasksTool.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
namespace LlmLaraHub\LlmDriver\Functions;
44

55
use App\Models\Message;
6-
use App\Models\Project;
76
use App\Models\Task;
87
use App\Models\User;
9-
use Facades\App\Domains\Sources\WebSearch\GetPage;
108
use Illuminate\Support\Facades\Log;
119
use LlmLaraHub\LlmDriver\Responses\FunctionResponse;
12-
use LlmLaraHub\LlmDriver\ToolsHelper;
1310

1411
class CreateTasksTool extends FunctionContract
1512
{
@@ -26,7 +23,6 @@ class CreateTasksTool extends FunctionContract
2623
ToolTypes::ChatCompletion,
2724
];
2825

29-
3026
public function handle(
3127
Message $message): FunctionResponse
3228
{
@@ -50,7 +46,7 @@ public function handle(
5046
'details' => $details,
5147
'due_date' => $due_date,
5248
'assistant' => $assistant,
53-
'user_id' => ($user_id !== "" && User::whereId($user_id)->exists()) ? $user_id : null,
49+
'user_id' => ($user_id !== '' && User::whereId($user_id)->exists()) ? $user_id : null,
5450
]);
5551
}
5652

Modules/LlmDriver/tests/Feature/CreateTasksToolTest.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@
22

33
namespace LlmLaraHub\LlmDriver\Tests\Feature;
44

5-
use App\Domains\Chat\DateRangesEnum;
6-
use App\Domains\Chat\MetaDataDto;
75
use App\Models\Chat;
8-
use App\Models\Document;
9-
use App\Models\DocumentChunk;
10-
use App\Models\Filter;
116
use App\Models\Message;
127
use App\Models\Project;
13-
use Illuminate\Support\Facades\File;
14-
use LlmLaraHub\LlmDriver\DistanceQuery\DistanceQueryFacade;
15-
use LlmLaraHub\LlmDriver\DistanceQuery\Drivers\PostGres;
168
use LlmLaraHub\LlmDriver\Functions\CreateTasksTool;
17-
use Pgvector\Laravel\Vector;
189
use Tests\TestCase;
1910

2011
class CreateTasksToolTest extends TestCase
@@ -38,7 +29,7 @@ public function test_generates_tasks(): void
3829
'chat_id' => $chat->id,
3930
'args' => [
4031
'tasks' => $data,
41-
]
32+
],
4233
]);
4334

4435
$this->assertDatabaseCount('tasks', 0);

app/Domains/Projects/KickOffProject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class KickOffProject
1010
{
1111
public function handle(Project $project)
1212
{
13-
$chat = $project->chats?->first();
13+
$chat = $project->chats()->first();
1414

1515
$chat->updateQuietly([
1616
'chat_status' => UiStatusEnum::InProgress,

app/Domains/Projects/Orchestrate.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\Domains\Messages\RoleEnum;
66
use App\Models\Chat;
7-
use App\Models\Project;
87
use Illuminate\Support\Facades\Log;
98
use LlmLaraHub\LlmDriver\Functions\ToolTypes;
109
use LlmLaraHub\LlmDriver\LlmDriverFacade;

app/Domains/Projects/Prompts/CampaignPromptTemplate.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class CampaignPromptTemplate
66
{
7-
8-
public static function systemPrompt(): string {
7+
public static function systemPrompt(): string
8+
{
99
$now = now()->toISOString();
1010

1111
return <<<PROMPT
@@ -40,7 +40,7 @@ public static function systemPrompt(): string {
4040
public static function prompt(): string
4141
{
4242

43-
return <<<PROMPT
43+
return <<<'PROMPT'
4444
## Unique Selling Proposition (USP)
4545
[What makes your product/service unique? Why should your target audience choose you over competitors?]
4646
@@ -67,6 +67,5 @@ public static function prompt(): string
6767

6868
PROMPT;
6969

70-
7170
}
7271
}

app/Http/Controllers/ProjectController.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
namespace App\Http\Controllers;
44

55
use App\Domains\Chat\UiStatusEnum;
6-
use Facades\App\Domains\Projects\KickOffProject;
76
use App\Domains\Projects\Prompts\CampaignPromptTemplate;
87
use App\Domains\Projects\StatusEnum;
98
use App\Http\Resources\ChatResource;
10-
use App\Http\Resources\ProjectResource;
119
use App\Http\Resources\MessageResource;
10+
use App\Http\Resources\ProjectResource;
1211
use App\Http\Resources\ProjectResourceShow;
1312
use App\Models\Chat;
1413
use App\Models\Project;
15-
use Illuminate\Http\Request;
14+
use Facades\App\Domains\Projects\KickOffProject;
1615
use Facades\App\Domains\Projects\Orchestrate;
1716

1817
class ProjectController extends Controller
@@ -36,12 +35,12 @@ public function create()
3635
return inertia('Projects/Create', [
3736
'content_start' => [
3837
[
39-
'key' => "Campaign Template",
38+
'key' => 'Campaign Template',
4039
'content' => CampaignPromptTemplate::prompt(),
4140
'system_prompt' => CampaignPromptTemplate::systemPrompt(),
42-
]
41+
],
4342
],
44-
'statuses' => StatusEnum::selectOptions()
43+
'statuses' => StatusEnum::selectOptions(),
4544
]);
4645
}
4746

@@ -87,7 +86,8 @@ public function show(Project $project)
8786
]);
8887
}
8988

90-
public function showWithChat(Project $project, Chat$chat) {
89+
public function showWithChat(Project $project, Chat $chat)
90+
{
9191

9292
return inertia('Projects/Show', [
9393
'project' => new ProjectResourceShow($project),

app/Http/Resources/MessageResource.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ class MessageResource extends JsonResource
1515
public function toArray(Request $request): array
1616
{
1717
$user = [];
18-
if($this->user_id) {
18+
if ($this->user_id) {
1919
$user = new UserResource($this->user);
2020
}
21+
2122
return [
2223
'id' => $this->id,
2324
'role' => $this->role->value,

app/Models/Chat.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Chat extends Model implements HasDrivers
3737

3838
public function getDriver(): string
3939
{
40-
if($this->chat_driver) {
40+
if ($this->chat_driver) {
4141
return $this->chat_driver->value;
4242
}
4343

@@ -71,9 +71,10 @@ public function getChatable(): HasDrivers
7171

7272
public function getEmbeddingDriver(): string
7373
{
74-
if($this->embedding_driver) {
74+
if ($this->embedding_driver) {
7575
return $this->embedding_driver->value;
7676
}
77+
7778
return $this->chatable->getEmbeddingDriver();
7879
}
7980

@@ -144,7 +145,7 @@ public function addInputWithTools(
144145
string $message,
145146
mixed $tool_id,
146147
mixed $tool_name,
147-
mixed $tool_args) : Message
148+
mixed $tool_args): Message
148149
{
149150

150151
return DB::transaction(function () use ($message, $tool_id, $tool_name, $tool_args) {
@@ -192,7 +193,8 @@ public function getAiResponse($input)
192193
return $this->getChatResponse();
193194
}
194195

195-
public function getMessageThread(int $limit = 5): array {
196+
public function getMessageThread(int $limit = 5): array
197+
{
196198
return $this->getChatResponse($limit);
197199
}
198200

app/Models/Message.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,16 @@ public function getFromAiAttribute(): bool
5959
return $this->role !== RoleEnum::User;
6060
}
6161

62-
public function user() : BelongsTo
62+
public function user(): BelongsTo
6363
{
6464
return $this->belongsTo(User::class);
6565
}
6666

67-
6867
public function scopeNotSystem(Builder $query)
6968
{
7069
return $query->where('role', '!=', RoleEnum::System->value);
7170
}
7271

73-
7472
public function scopeNotTool(Builder $query)
7573
{
7674
return $query->where('role', '!=', RoleEnum::Tool->value);

app/Models/Project.php

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Illuminate\Database\Eloquent\Relations\MorphMany;
1111
use Illuminate\Database\Eloquent\SoftDeletes;
1212
use LlmLaraHub\LlmDriver\HasDrivers;
13-
use LlmLaraHub\LlmDriver\HasDriversTrait;
1413

1514
class Project extends Model implements HasDrivers
1615
{
@@ -34,7 +33,6 @@ public function tasks(): HasMany
3433
return $this->hasMany(Task::class);
3534
}
3635

37-
3836
public function chats(): MorphMany
3937
{
4038
return $this->morphMany(Chat::class, 'chatable');

database/migrations/2024_09_08_233618_add_status_to_chat.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
public function up(): void
1313
{
1414
Schema::table('chats', function (Blueprint $table) {
15-
$table->string("chat_status")
15+
$table->string('chat_status')
1616
->nullable()
1717
->default(\App\Domains\Chat\UiStatusEnum::NotStarted->value);
1818
});

tests/Feature/Http/Controllers/ProjectControllerTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function test_update(): void
130130

131131
$this->actingAs($user)->put(
132132
route('projects.update', $project), [
133-
"name" => "Test Campaign 2",
133+
'name' => 'Test Campaign 2',
134134
'start_date' => '2023-01-01',
135135
'system_prompt' => 'Test Description',
136136
'end_date' => '2023-01-01',
@@ -154,5 +154,4 @@ public function test_destroy(): void
154154
)->assertSessionHasNoErrors()
155155
->assertStatus(302);
156156
}
157-
158157
}

tests/Feature/Models/ChatTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ public function test_factory(): void
3636
$this->assertNotNull($collection->chats()->first()->id);
3737
}
3838

39-
public function test_default_driver() {
39+
public function test_default_driver()
40+
{
4041
$project = Project::factory()->create();
4142

4243
$chat = Chat::factory()->create([
4344
'chatable_id' => $project->id,
44-
"chatable_type" => Project::class,
45-
"chat_driver" => DriversEnum::Claude,
46-
"embedding_driver" => DriversEnum::Ollama,
45+
'chatable_type' => Project::class,
46+
'chat_driver' => DriversEnum::Claude,
47+
'embedding_driver' => DriversEnum::Ollama,
4748
]);
4849

4950
$this->assertEquals(DriversEnum::Claude->value, $chat->getDriver());

tests/Feature/ProjectOrchestrateTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ public function test_tools(): void
3737
CompletionResponse::from($response)
3838
);
3939

40-
4140
LlmDriverFacade::shouldReceive('driver->chat')
4241
->once()
4342
->andReturn(
4443
CompletionResponse::from($response)
4544
);
4645

47-
(new Orchestrate())->handle($chat, 'Test Prompt', "System Prompt");
46+
(new Orchestrate())->handle($chat, 'Test Prompt', 'System Prompt');
4847

4948
$this->assertDatabaseCount('messages', 4);
5049
$this->assertDatabaseCount('tasks', 5);

0 commit comments

Comments
 (0)