Skip to content

Commit ada1b4d

Browse files
committed
refactor(customer): rename AiService and AiController to AiChatService and AiChatController
1 parent 8f058d6 commit ada1b4d

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

app/Http/Controllers/Customer/AiController.php renamed to app/Http/Controllers/Customer/AiChatController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
use App\Http\Controllers\Controller;
66
use App\Http\Requests\Ai\AskAiRequest;
7-
use App\Services\AiService;
7+
use App\Services\AiChatService;
88

9-
class AiController extends Controller
9+
class AiChatController extends Controller
1010
{
1111
/**
12-
* Inject AiService.
12+
* Inject AiChatService.
1313
*
14-
* @param AiService $aiService
14+
* @param AiChatService $aiChatService
1515
*/
1616
public function __construct(
17-
protected AiService $aiService
17+
protected AiChatService $aiChatService
1818
) {}
1919

2020
/**
2121
* Handle a customer AI chat message and return the AI's reply.
2222
*/
2323
public function ask(AskAiRequest $request)
2424
{
25-
$reply = $this->aiService->ask(
25+
$reply = $this->aiChatService->ask(
2626
$request->validated()['message'],
2727
$request->validated()['history']
2828
);
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,8 @@
77
use Gemini\Laravel\Facades\Gemini;
88
use Illuminate\Support\Facades\File;
99

10-
class AiService
10+
class AiChatService
1111
{
12-
/**
13-
* Load system prompt from the markdown file
14-
*
15-
* @return string
16-
*/
17-
private function getSystemPrompt(): string
18-
{
19-
$path = resource_path('views/prompts/ai-assistant.md');
20-
21-
return File::exists($path) ? File::get($path) : '';
22-
}
23-
2412
/**
2513
* Send a message to Gemini with conversation history and get a response.
2614
*
@@ -31,7 +19,7 @@ private function getSystemPrompt(): string
3119
public function ask(string $message, array $history = []): string
3220
{
3321
$formattedHistory = collect($history)->map(
34-
fn ($item) => Content::parse(
22+
fn($item) => Content::parse(
3523
$item['content'],
3624
$item['role'] === 'model' ? Role::MODEL : Role::USER
3725
)
@@ -44,4 +32,16 @@ public function ask(string $message, array $history = []): string
4432

4533
return $response->text();
4634
}
35+
36+
/**
37+
* Load system prompt from the markdown file
38+
*
39+
* @return string
40+
*/
41+
private function getSystemPrompt(): string
42+
{
43+
$path = resource_path('views/prompts/ai-assistant.md');
44+
45+
return File::exists($path) ? File::get($path) : '';
46+
}
4747
}

routes/customer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use App\Enums\UserRole;
4-
use App\Http\Controllers\Customer\AiController;
4+
use App\Http\Controllers\Customer\AiChatController;
55
use App\Http\Controllers\Customer\CartController;
66
use App\Http\Controllers\Customer\ChatController;
77
use App\Http\Controllers\Customer\CheckoutController;
@@ -72,7 +72,7 @@
7272

7373
// AI Chat
7474
Route::prefix('ai')->name('ai.')->group(function () {
75-
Route::controller(AiController::class)->group(function () {
75+
Route::controller(AiChatController::class)->group(function () {
7676
Route::post('/ask', 'ask')->name('ask');
7777
});
7878
});

0 commit comments

Comments
 (0)