feat: AI model selector + i18n nav labels (RU/EN) on new modules
AI model selector:
- AiAssistantService::MODEL_DEFAULTS and MODEL_OPTIONS const tables (3 picks per
provider: Claude Opus 4.7 / Sonnet 4.6 / Haiku 4.5, OpenAI 4o / 4o-mini,
Gemini 1.5 Pro / Flash). Default upgraded from Sonnet 4.5 → Sonnet 4.6.
- modelFor(provider, company?) resolves tenant override > global default.
- All 8 hardcoded model strings replaced with modelFor() across callClaude
(chat with tool-use), callOpenAI, callGemini (chat), postClaude/postOpenAI/
postGemini (single-shot), and OcrInvoiceService.
- Settings page adds 3 model selectors per provider with persistence at
settings.ai.models.{claude,gpt,gemini}.
i18n nav labels:
- TireSet / Bodyshop / Subcontractor / SubcontractJob / PricingCoefficient /
ShopCustomer resources: getNavigationLabel / getNavigationGroup /
getModelLabel / getPluralModelLabel return __()-wrapped strings.
- 20 keys added to lang/ru.json and lang/en.json.
Tests (4 new): default model, tenant override wins, unknown provider falls
back to claude default, options dictionary contains each default key.
Full suite: 134 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,9 @@ class Settings extends Page
|
||||
'ai_claude_key' => $settings['ai']['claude_key'] ?? null,
|
||||
'ai_gpt_key' => $settings['ai']['gpt_key'] ?? null,
|
||||
'ai_gemini_key' => $settings['ai']['gemini_key'] ?? null,
|
||||
'ai_model_claude' => data_get($settings, 'ai.models.claude', \App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['claude']),
|
||||
'ai_model_gpt' => data_get($settings, 'ai.models.gpt', \App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['gpt']),
|
||||
'ai_model_gemini' => data_get($settings, 'ai.models.gemini', \App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['gemini']),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -193,8 +196,20 @@ class Settings extends Page
|
||||
->options(['claude' => 'Claude (Anthropic)', 'gpt' => 'ChatGPT (OpenAI)', 'gemini' => 'Gemini (Google)'])
|
||||
->default('claude'),
|
||||
Forms\Components\TextInput::make('ai_claude_key')->label('Claude API Key')->password()->revealable()->placeholder('sk-ant-...'),
|
||||
Forms\Components\Select::make('ai_model_claude')
|
||||
->label('Model Claude')
|
||||
->options(\App\Services\Ai\AiAssistantService::MODEL_OPTIONS['claude'])
|
||||
->default(\App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['claude']),
|
||||
Forms\Components\TextInput::make('ai_gpt_key')->label('OpenAI API Key')->password()->revealable()->placeholder('sk-proj-...'),
|
||||
Forms\Components\Select::make('ai_model_gpt')
|
||||
->label('Model OpenAI')
|
||||
->options(\App\Services\Ai\AiAssistantService::MODEL_OPTIONS['gpt'])
|
||||
->default(\App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['gpt']),
|
||||
Forms\Components\TextInput::make('ai_gemini_key')->label('Gemini API Key')->password()->revealable(),
|
||||
Forms\Components\Select::make('ai_model_gemini')
|
||||
->label('Model Gemini')
|
||||
->options(\App\Services\Ai\AiAssistantService::MODEL_OPTIONS['gemini'])
|
||||
->default(\App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['gemini']),
|
||||
]),
|
||||
])
|
||||
->statePath('data');
|
||||
@@ -246,6 +261,11 @@ class Settings extends Page
|
||||
'claude_key' => $data['ai_claude_key'] ?? null,
|
||||
'gpt_key' => $data['ai_gpt_key'] ?? null,
|
||||
'gemini_key' => $data['ai_gemini_key'] ?? null,
|
||||
'models' => [
|
||||
'claude' => $data['ai_model_claude'] ?? \App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['claude'],
|
||||
'gpt' => $data['ai_model_gpt'] ?? \App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['gpt'],
|
||||
'gemini' => $data['ai_model_gemini'] ?? \App\Services\Ai\AiAssistantService::MODEL_DEFAULTS['gemini'],
|
||||
],
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
@@ -134,6 +134,27 @@ class BodyshopJobResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('Tinichigerie / Detailing');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('Tinichigerie');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('lucrare caroserie');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('lucrări caroserie');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -97,6 +97,27 @@ class PricingCoefficientResource extends Resource
|
||||
->defaultSort('priority');
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('Coeficienți preț');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('Depozit');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('coeficient');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('coeficienți preț');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -93,6 +93,27 @@ class ShopCustomerResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('Clienți magazin');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('Magazin');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('client magazin');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('clienți magazin');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -122,6 +122,27 @@ class SubcontractJobResource extends Resource
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('Lucrări terți');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('Subcontractare');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('lucrare terți');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('lucrări terți');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -73,6 +73,27 @@ class SubcontractorResource extends Resource
|
||||
->defaultSort('name');
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('Subcontractori');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('Subcontractare');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('subcontractor');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('subcontractori');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -185,6 +185,27 @@ class TireSetResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('Seturi anvelope');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return __('Anvelope');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('set anvelope');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('seturi anvelope');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -21,6 +21,37 @@ use Illuminate\Support\Facades\Http;
|
||||
*/
|
||||
class AiAssistantService
|
||||
{
|
||||
/** Per-provider default model + the dropdown options exposed in Settings. */
|
||||
public const MODEL_DEFAULTS = [
|
||||
'claude' => 'claude-sonnet-4-6',
|
||||
'gpt' => 'gpt-4o-mini',
|
||||
'gemini' => 'gemini-1.5-flash',
|
||||
];
|
||||
|
||||
public const MODEL_OPTIONS = [
|
||||
'claude' => [
|
||||
'claude-opus-4-7' => 'Opus 4.7 — cel mai capabil',
|
||||
'claude-sonnet-4-6' => 'Sonnet 4.6 — echilibrat (recomandat)',
|
||||
'claude-haiku-4-5-20251001' => 'Haiku 4.5 — rapid și ieftin',
|
||||
],
|
||||
'gpt' => [
|
||||
'gpt-4o' => 'GPT-4o',
|
||||
'gpt-4o-mini' => 'GPT-4o mini (recomandat)',
|
||||
],
|
||||
'gemini' => [
|
||||
'gemini-1.5-pro' => 'Gemini 1.5 Pro',
|
||||
'gemini-1.5-flash' => 'Gemini 1.5 Flash (recomandat)',
|
||||
],
|
||||
];
|
||||
|
||||
/** Resolve the model id for a provider — tenant override > global default. */
|
||||
public function modelFor(string $provider, ?Company $company = null): string
|
||||
{
|
||||
$company ??= $this->currentCompany();
|
||||
$override = $company ? data_get($company->settings, "ai.models.{$provider}") : null;
|
||||
return $override ?: (self::MODEL_DEFAULTS[$provider] ?? 'claude-sonnet-4-6');
|
||||
}
|
||||
|
||||
public function ask(AiChat $chat, string $userMessage): AiMessage
|
||||
{
|
||||
// Persist user message.
|
||||
@@ -148,7 +179,7 @@ TXT;
|
||||
$r = Http::withHeaders($headers)->timeout(60)->post(
|
||||
'https://api.anthropic.com/v1/messages',
|
||||
[
|
||||
'model' => 'claude-sonnet-4-5',
|
||||
'model' => $this->modelFor('claude', $company),
|
||||
'max_tokens' => 1024,
|
||||
'system' => $system,
|
||||
'tools' => $tools,
|
||||
@@ -214,7 +245,7 @@ TXT;
|
||||
$r = Http::withHeaders(['Authorization' => 'Bearer ' . $key, 'content-type' => 'application/json'])
|
||||
->timeout(60)
|
||||
->post('https://api.openai.com/v1/chat/completions', [
|
||||
'model' => 'gpt-4o-mini',
|
||||
'model' => $this->modelFor('gpt', $company),
|
||||
'messages' => $messages,
|
||||
'max_tokens' => 1024,
|
||||
]);
|
||||
@@ -390,7 +421,7 @@ TXT;
|
||||
])
|
||||
->timeout(60)
|
||||
->post('https://api.anthropic.com/v1/messages', [
|
||||
'model' => 'claude-sonnet-4-5',
|
||||
'model' => $this->modelFor('claude'),
|
||||
'max_tokens' => 1024,
|
||||
'system' => $system,
|
||||
'messages' => $messages,
|
||||
@@ -413,7 +444,7 @@ TXT;
|
||||
$r = Http::withHeaders(['Authorization' => 'Bearer ' . $key, 'content-type' => 'application/json'])
|
||||
->timeout(60)
|
||||
->post('https://api.openai.com/v1/chat/completions', [
|
||||
'model' => 'gpt-4o-mini',
|
||||
'model' => $this->modelFor('gpt'),
|
||||
'messages' => array_merge([['role' => 'system', 'content' => $system]], $messages),
|
||||
'max_tokens' => 1024,
|
||||
]);
|
||||
@@ -442,7 +473,7 @@ TXT;
|
||||
}
|
||||
$r = Http::withHeaders(['content-type' => 'application/json'])
|
||||
->timeout(60)
|
||||
->post('https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=' . $key, [
|
||||
->post('https://generativelanguage.googleapis.com/v1beta/models/' . $this->modelFor('gemini') . ':generateContent?key=' . $key, [
|
||||
'systemInstruction' => ['parts' => [['text' => $system]]],
|
||||
'contents' => $contents,
|
||||
'generationConfig' => ['maxOutputTokens' => 1024],
|
||||
@@ -452,7 +483,7 @@ TXT;
|
||||
}
|
||||
$body = $r->json();
|
||||
$text = $body['candidates'][0]['content']['parts'][0]['text'] ?? '(răspuns gol)';
|
||||
return [$text, ['model' => 'gemini-1.5-flash', 'tokens' => $body['usageMetadata'] ?? null]];
|
||||
return [$text, ['model' => $this->modelFor('gemini'), 'tokens' => $body['usageMetadata'] ?? null]];
|
||||
}
|
||||
|
||||
protected function currentCompany(): ?Company
|
||||
@@ -474,7 +505,7 @@ TXT;
|
||||
|
||||
$r = Http::withHeaders(['content-type' => 'application/json'])
|
||||
->timeout(60)
|
||||
->post('https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=' . $key, [
|
||||
->post('https://generativelanguage.googleapis.com/v1beta/models/' . $this->modelFor('gemini', $company) . ':generateContent?key=' . $key, [
|
||||
'systemInstruction' => ['parts' => [['text' => $this->buildSystemPrompt($company)]]],
|
||||
'contents' => $contents,
|
||||
'generationConfig' => ['maxOutputTokens' => 1024],
|
||||
@@ -486,7 +517,7 @@ TXT;
|
||||
$body = $r->json();
|
||||
$text = $body['candidates'][0]['content']['parts'][0]['text'] ?? '(răspuns gol)';
|
||||
return [$text, [
|
||||
'model' => 'gemini-1.5-flash',
|
||||
'model' => $this->modelFor('gemini', $company),
|
||||
'tokens' => $body['usageMetadata'] ?? null,
|
||||
]];
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class OcrInvoiceService
|
||||
])
|
||||
->timeout(60)
|
||||
->post('https://api.anthropic.com/v1/messages', [
|
||||
'model' => 'claude-sonnet-4-5',
|
||||
'model' => app(AiAssistantService::class)->modelFor('claude', $company),
|
||||
'max_tokens' => 2048,
|
||||
'system' => $this->systemPrompt(),
|
||||
'messages' => [[
|
||||
|
||||
Reference in New Issue
Block a user