Skip to content

Commit

Permalink
ok ready to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Sep 9, 2024
1 parent 736be0e commit fda9025
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 26 deletions.
7 changes: 4 additions & 3 deletions Modules/LlmDriver/app/Functions/CreateTasksTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Message;
use App\Models\Project;
use App\Models\Task;
use App\Models\User;
use Facades\App\Domains\Sources\WebSearch\GetPage;
use Illuminate\Support\Facades\Log;
use LlmLaraHub\LlmDriver\Responses\FunctionResponse;
Expand All @@ -27,11 +28,11 @@ class CreateTasksTool extends FunctionContract


public function handle(
Message $message,
array $args = []): FunctionResponse
Message $message): FunctionResponse
{
Log::info('TaskTool called');

$args = $message->args;
foreach (data_get($args, 'tasks', []) as $taskArg) {
$name = data_get($taskArg, 'name', null);
$details = data_get($taskArg, 'details', null);
Expand All @@ -49,7 +50,7 @@ public function handle(
'details' => $details,
'due_date' => $due_date,
'assistant' => $assistant,
'user_id' => $user_id,
'user_id' => ($user_id !== "" && User::whereId($user_id)->exists()) ? $user_id : null,
]);
}

Expand Down
19 changes: 8 additions & 11 deletions Modules/LlmDriver/tests/Feature/CreateTasksToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,24 @@ public function test_generates_tasks(): void
'chatable_type' => Project::class,
]);

$message = Message::factory()->create([
'chat_id' => $chat->id,
]);


$data = get_fixture('claude_chat_response.json');

$data = data_get($data, 'tool_calls.1.arguments.tasks');

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


(new CreateTasksTool())->handle($message, [
'tasks' => $data,
$message = Message::factory()->create([
'chat_id' => $chat->id,
'args' => [
'tasks' => $data,
]
]);

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

(new CreateTasksTool())->handle($message);

$this->assertDatabaseCount('tasks', 5);

$this->assertCount(5, $project->refresh()->tasks);

}

}
10 changes: 5 additions & 5 deletions app/Domains/Projects/Orchestrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public function handle(Chat $chat, string $prompt, string $systemPrompt = ''): v
'tool_count' => count($response->tool_calls),
]);

$tool = app()->make($tool_call->name);
$tool->handle($chat, $tool_call->arguments);

$chat->addInputWithTools(
message: sprintf('Tool %s complete', $tool_call->name),
$message = $chat->addInputWithTools(
message: sprintf('Tool %s', $tool_call->name),
tool_id: $tool_call->id,
tool_name: $tool_call->name,
tool_args: $tool_call->arguments,
);

$tool = app()->make($tool_call->name);
$tool->handle($message, $tool_call->arguments);

$count++;
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function showWithChat(Project $project, Chat$chat) {
'chat' => new ChatResource($chat),
'messages' => MessageResource::collection($chat->messages()
->notSystem()
->notTool()
->latest()
->paginate(3)),
]);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public function scopeNotSystem(Builder $query)
}


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

/**
* Return a compressed message
*/
Expand Down
9 changes: 5 additions & 4 deletions resources/js/Layouts/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ const theme = ref('dark')
</Link>
<ul class="menu menu-horizontal px-1">
<li class="hidden lg:flex">
<a href="https://larallama.io" target="_blank">
LaraLlama.io
</a>
<Link :href="route('projects.index')"
:class="{ 'underline' : route().current('projects.index') }">
Projects
</Link>
</li>
<li class="hidden sm:flex">
<Link :href="route('dashboard')"
<Link :href="route('collections.index')"
:class="{ 'underline' : route().current('collections.index') }">
Collections
</Link>
Expand Down
1 change: 1 addition & 0 deletions resources/js/Layouts/MainMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const logout = () => {
Main Menu
</summary>
<ul class="p-2 z-50">
<li class="flex sm:hidden"><Link :href="route('projects.index')">Projects</Link></li>
<li class="flex sm:hidden"><Link :href="route('collections.index')">Collections</Link></li>
<li class="flex sm:hidden"><Link :href="route('style_guide.show')">Style Guides</Link></li>
<li><Link :href="route('profile.show')">Profile</Link></li>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Projects/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const activeLlms = computed(() => {
</div>

<div class="col-span-12 sm:col-span-6">
<InputLabel for="Content" value="Content" />
<InputLabel for="Content" value="Prompt" />
<textarea
v-model="form.content"
class="
Expand Down
11 changes: 9 additions & 2 deletions tests/Feature/ProjectOrchestrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ public function test_tools(): void
$this->assertDatabaseCount('messages', 0);
$this->assertDatabaseCount('tasks', 0);

LlmDriverFacade::shouldReceive('driver->setToolType->chat')
->once()
->andReturn(
CompletionResponse::from($response)
);


LlmDriverFacade::shouldReceive('driver->chat')
->twice()
->once()
->andReturn(
CompletionResponse::from($response)
);

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

$this->assertDatabaseCount('messages', 3);
$this->assertDatabaseCount('messages', 4);
$this->assertDatabaseCount('tasks', 5);
}
}
88 changes: 88 additions & 0 deletions tests/fixtures/create_tasks_args.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"tasks": [
{
"name": "Refine and finalize USP",
"details": "Craft a compelling one-sentence USP and create 3-5 key bullet points highlighting unique aspects of the book",
"due_date": "2023-08-07",
"user_id": "1",
"assistant": "false"
},
{
"name": "Set up book landing page",
"details": "Design and launch a dedicated landing page for the book. Implement email sign-up form for updates and pre-orders",
"due_date": "2023-08-14",
"user_id": "1",
"assistant": "false"
},
{
"name": "Develop content marketing calendar",
"details": "Plan Twitter content (20 tweets), outline 5 LinkedIn posts, draft 3 Medium articles, and script 5 YouTube tutorial videos",
"due_date": "2023-08-21",
"user_id": "1",
"assistant": "false"
},
{
"name": "Leverage larallama.io",
"details": "Write a blog post connecting larallama.io to book concepts. Create a video showcasing larallama.io and its relation to the book",
"due_date": "2023-08-28",
"user_id": "1",
"assistant": "false"
},
{
"name": "Launch pre-order campaign",
"details": "Set up pre-order system, create early-bird offer, and design a contest for free book copies",
"due_date": "2023-09-04",
"user_id": "1",
"assistant": "false"
},
{
"name": "Conduct influencer outreach",
"details": "Identify 10 key influencers, craft personalized messages, and coordinate potential collaborations or reviews",
"due_date": "2023-09-11",
"user_id": "1",
"assistant": "false"
},
{
"name": "Plan and host webinar",
"details": "Decide on webinar topic, create outline, set up registration page, and promote across all social channels",
"due_date": "2023-09-18",
"user_id": "1",
"assistant": "false"
},
{
"name": "Set up targeted advertising",
"details": "Research platforms, create ad copy and visuals, set budget and launch campaigns",
"due_date": "2023-09-25",
"user_id": "1",
"assistant": "false"
},
{
"name": "Engage with online communities",
"details": "Identify 5 relevant online communities and create a schedule for regular participation",
"due_date": "2023-10-02",
"user_id": "1",
"assistant": "false"
},
{
"name": "Implement tracking and analytics",
"details": "Set up unique tracking links for each promotional channel and create a spreadsheet to monitor sales",
"due_date": "2023-10-09",
"user_id": "1",
"assistant": "false"
},
{
"name": "Schedule progress review meetings",
"details": "Set bi-weekly check-ins to review sales numbers and strategy effectiveness",
"due_date": "2023-10-16",
"user_id": "1",
"assistant": "false"
},
{
"name": "Prepare for book launch",
"details": "Plan launch day activities and promotions. Coordinate with partners or collaborators for launch support",
"due_date": "2023-10-23",
"user_id": "1",
"assistant": "false"
}
]
}

0 comments on commit fda9025

Please sign in to comment.