Skip to content

Commit

Permalink
Merge pull request #2001 from amit-webkul/magic-ai
Browse files Browse the repository at this point in the history
✨ feat : Implementing the AI in krayin CRM.
  • Loading branch information
devansh-webkul authored Jan 31, 2025
2 parents 657593d + dadf3b0 commit 9b33760
Show file tree
Hide file tree
Showing 22 changed files with 1,083 additions and 52 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"maatwebsite/excel": "^3.1",
"mpdf/mpdf": "^8.2",
"prettus/l5-repository": "^2.7.9",
"smalot/pdfparser": "^2.11",
"webklex/laravel-imap": "^5.3"
},
"require-dev": {
Expand Down
57 changes: 54 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions packages/Webkul/Admin/src/Config/core_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,77 @@
'options' => 'Webkul\Core\Core@locales',
],
],
], [
'key' => 'general.magic_ai',
'name' => 'admin::app.configuration.index.magic-ai.title',
'info' => 'admin::app.configuration.index.magic-ai.info',
'icon' => 'icon-setting',
'sort' => 3,
], [
'key' => 'general.magic_ai.settings',
'name' => 'admin::app.configuration.index.magic-ai.settings.title',
'info' => 'admin::app.configuration.index.magic-ai.settings.info',
'sort' => 1,
'fields' => [
[
'name' => 'enable',
'title' => 'admin::app.configuration.index.magic-ai.settings.enable',
'type' => 'boolean',
'channel_based' => true,
], [
'name' => 'model',
'title' => 'admin::app.configuration.index.magic-ai.settings.models.title',
'type' => 'select',
'channel_based' => true,
'depends' => 'enable:1',
'options' => [
[
'title' => 'admin::app.configuration.index.magic-ai.settings.models.gpt-4o',
'value' => 'gpt-4o',
], [
'title' => 'admin::app.configuration.index.magic-ai.settings.models.gpt-4o-mini',
'value' => 'gpt-4o-mini',
], [
'title' => 'admin::app.configuration.index.magic-ai.settings.models.gemini-flash',
'value' => 'gemini-1.5-flash',
], [
'title' => 'admin::app.configuration.index.magic-ai.settings.models.deepseek-r1',
'value' => 'deepseek-r1:8b',
], [
'title' => 'admin::app.configuration.index.magic-ai.settings.models.ollama',
'value' => 'llama3.2:latest',
], [
'title' => 'admin::app.configuration.index.magic-ai.settings.models.llama',
'value' => 'llama-3.3-70b-versatile',
],
],
], [
'name' => 'api_key',
'title' => 'admin::app.configuration.index.magic-ai.settings.api-key',
'type' => 'password',
'depends' => 'enable:1,model:gpt-4o,model:gpt-4o-mini,model:gemini-1.5-flash,model:llama-3.3-70b-versatile',
'validation' => 'required_if:enable,1',
'info' => 'admin::app.configuration.index.magic-ai.settings.api-key-info',
], [
'name' => 'api_domain',
'title' => 'admin::app.configuration.index.magic-ai.settings.api-domain',
'type' => 'text',
'info' => 'admin::app.configuration.index.magic-ai.settings.api-domain-info',
'depends' => 'enable:1',
],
],
], [
'key' => 'general.magic_ai.pdf_generation',
'name' => 'admin::app.configuration.index.magic-ai.settings.pdf-generation',
'info' => 'admin::app.configuration.index.magic-ai.settings.pdf-generation-info',
'sort' => 1,
'fields' => [
[
'name' => 'enabled',
'title' => 'admin::app.configuration.index.magic-ai.settings.enable',
'type' => 'boolean',
],
],
],

/**
Expand Down
69 changes: 69 additions & 0 deletions packages/Webkul/Admin/src/Http/Controllers/Lead/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\Contact\Repositories\PersonRepository;
use Webkul\DataGrid\Enums\DateRangeOptionEnum;
use Webkul\Lead\Helpers\Lead;
use Webkul\Lead\Repositories\LeadRepository;
use Webkul\Lead\Repositories\PipelineRepository;
use Webkul\Lead\Repositories\ProductRepository;
use Webkul\Lead\Repositories\SourceRepository;
use Webkul\Lead\Repositories\StageRepository;
use Webkul\Lead\Repositories\TypeRepository;
use Webkul\Lead\Services\LeadService;
use Webkul\Tag\Repositories\TagRepository;
use Webkul\User\Repositories\UserRepository;

Expand All @@ -44,6 +46,7 @@ public function __construct(
protected StageRepository $stageRepository,
protected LeadRepository $leadRepository,
protected ProductRepository $productRepository,
protected PersonRepository $personRepository
) {
request()->request->add(['entity_type' => 'leads']);
}
Expand Down Expand Up @@ -625,4 +628,70 @@ private function getKanbanColumns(): array
],
];
}

/**
* Create Lead with specified AI.
*/
public function createByAI(LeadForm $request)
{
if (! $pdfFile = $request->file('file')) {
return response()->json([
'status' => 'error',
'message' => trans('admin::app.leads.file.not-found'),
], 400);
}

$extractedData = LeadService::extractDataFromPdf($pdfFile->getPathName());

if (! empty($extractedData['error'])) {
return response()->json([
'status' => 'error',
'message' => $extractedData['error'],
], 400);
}

$leadData = Lead::mapAIDataToLead($extractedData);

if (
! empty($leadData['status'])
&& $leadData['status'] === 'error'
) {
return response()->json([
'status' => 'error',
'message' => $leadData['message'],
], 400);
}

return self::leadCreate($leadData);
}

/**
* Create lead independent entity.
*/
private function leadCreate($data)
{
$person = $this->personRepository->create($data['person']);

$pipeline = $this->pipelineRepository->getDefaultPipeline();

$stage = $pipeline->stages()->first();

$data = array_merge($data, [
'lead_pipeline_id' => $pipeline->id,
'lead_pipeline_stage_id' => $stage->id,
'expected_close_date' => Carbon::now()->addDays(7),
'person' => [
'id' => $person->id,
'organization_id' => $data['person']['organization_id'] ?? null,
],
]);

$lead = $this->leadRepository->create($data);

Event::dispatch('lead.create.after', $lead);

return response()->json([
'message' => trans('admin::app.leads.create-success'),
], 200);
}
}
66 changes: 54 additions & 12 deletions packages/Webkul/Admin/src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,12 @@
'destroy-success' => 'تم حذف العميل المحتمل بنجاح.',
'destroy-failed' => 'لا يمكن حذف العميل المحتمل.',

'file' => [
'invalid-format' => 'تنسيق JSON غير صالح.',
'invalid-response' => 'تنسيق استجابة الذكاء الاصطناعي غير صالح.',
'not-found' => 'الملف غير موجود.',
],

'index' => [
'title' => 'العملاء المحتملون',
'create-btn' => 'إنشاء عميل محتمل',
Expand Down Expand Up @@ -1936,6 +1942,15 @@
'all-pipelines' => 'كل المسارات',
'create-new-pipeline' => 'إنشاء مسار جديد',
],

'upload' => [
'create-lead' => 'إنشاء عميل محتمل باستخدام الذكاء الاصطناعي',
'file' => 'تحميل ملف',
'file-info' => 'يتم قبول ملفات بصيغة PDF فقط.',
'save-btn' => 'حفظ',
'sample-pdf' => 'نموذج PDF',
'upload-pdf' => 'تحميل PDF',
],
],

'create' => [
Expand Down Expand Up @@ -2069,22 +2084,49 @@
],

'email' => [
'title' => 'Email Settings',
'info' => 'Email configuration for the application.',
'title' => 'إعدادات البريد الإلكتروني',
'info' => 'تكوين البريد الإلكتروني للتطبيق.',

'imap' => [
'title' => 'IMAP Settings',
'info' => 'IMAP email configuration for receiving emails.',
'title' => 'إعدادات IMAP',
'info' => 'تكوين البريد الإلكتروني IMAP لتلقي الرسائل.',

'account' => [
'title' => 'IMAP Account',
'title-info' => 'Configure your IMAP account settings here.',
'host' => 'Host',
'port' => 'Port',
'encryption' => 'Encryption Type',
'validate-cert' => 'Validate SSL Certificate',
'username' => 'IMAP Username',
'password' => 'IMAP Password',
'title' => 'حساب IMAP',
'title-info' => 'قم بتكوين إعدادات حساب IMAP هنا.',
'host' => 'المضيف',
'port' => 'المنفذ',
'encryption' => 'نوع التشفير',
'validate-cert' => 'التحقق من شهادة SSL',
'username' => 'اسم مستخدم IMAP',
'password' => 'كلمة مرور IMAP',
],
],
],

'magic-ai' => [
'title' => 'الذكاء الاصطناعي السحري',
'info' => 'تكوين الذكاء الاصطناعي السحري للتطبيق.',

'settings' => [
'api-domain' => 'نطاق API لـ LLM',
'api-domain-info' => 'لـ Olama و Grow فقط، مثال: http://localhost:11434',
'api-key' => 'مفتاح API',
'api-key-info' => 'يرجى التأكد من استخدام مفتاح API فريد لكل نوع نموذج للحفاظ على الأداء الأمثل والأمان.',
'enable' => 'تمكين',
'info' => 'عزز تجربتك مع ميزة الذكاء الاصطناعي السحري عن طريق إدخال مفتاح API الحصري الخاص بك وتوضيح التكامل السهل. استحوذ على التحكم في بيانات اعتماد OpenAI الخاصة بك وقم بتخصيص الإعدادات وفقًا لاحتياجاتك الخاصة.',
'pdf-generation' => 'توليد PDF',
'pdf-generation-info' => 'قم بتمكين ميزة توليد PDF لاستخراج البيانات تلقائيًا من ملفات PDF وتحويلها إلى تنسيق نصي. عزز إنتاجيتك وكفاءتك بتمكين هذه الميزة لتبسيط سير العمل الخاص بك.',
'title' => 'الإعدادات العامة',

'models' => [
'deepseek-r1' => 'DeepSeek-R1 8db',
'gemini-flash' => 'Gemini-1.5 Flash',
'gpt-4o' => 'GPT-4.0',
'gpt-4o-mini' => 'GPT-4.0 mini',
'llama' => 'Llama 3.3 (Groq)',
'ollama' => 'Ollama (llama3.2:latest)',
'title' => 'النماذج',
],
],
],
Expand Down
Loading

0 comments on commit 9b33760

Please sign in to comment.