Compare commits
No commits in common. "474f1274c0c4781c8ae0e4a16a535b47f259bb42" and "6720cc17742e751dcd165c7b94bef4e6ec24da13" have entirely different histories.
474f1274c0
...
6720cc1774
|
@ -1,44 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\AiTool;
|
|
||||||
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use App\Entity\Person;
|
|
||||||
use App\Service\Explore;
|
|
||||||
|
|
||||||
class PersonService
|
|
||||||
{
|
|
||||||
private EntityManagerInterface $em;
|
|
||||||
private \App\Cog\PersonService $cogPersonService;
|
|
||||||
public function __construct(EntityManagerInterface $em, \App\Cog\PersonService $cogPersonService)
|
|
||||||
{
|
|
||||||
$this->em = $em;
|
|
||||||
$this->cogPersonService = $cogPersonService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* دریافت اطلاعات یک شخص بر اساس کد و اطلاعات دسترسی
|
|
||||||
*/
|
|
||||||
public function getPersonInfoByCode($code, $acc): array
|
|
||||||
{
|
|
||||||
if (!$code) {
|
|
||||||
return [
|
|
||||||
'error' => 'کد شخص الزامی است'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
if (!$acc) {
|
|
||||||
return [
|
|
||||||
'error' => 'اطلاعات دسترسی (acc) الزامی است'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return $this->cogPersonService->getPersonInfo($code, $acc);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return [
|
|
||||||
'error' => 'خطا در دریافت اطلاعات شخص: ' . $e->getMessage()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -7,6 +7,7 @@ use App\Entity\Person;
|
||||||
use App\Entity\PersonType;
|
use App\Entity\PersonType;
|
||||||
use App\Entity\HesabdariRow;
|
use App\Entity\HesabdariRow;
|
||||||
use App\Service\Explore;
|
use App\Service\Explore;
|
||||||
|
use App\Service\Access;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* سرویس مدیریت اشخاص
|
* سرویس مدیریت اشخاص
|
||||||
|
@ -16,12 +17,12 @@ use App\Service\Explore;
|
||||||
class PersonService
|
class PersonService
|
||||||
{
|
{
|
||||||
private EntityManagerInterface $entityManager;
|
private EntityManagerInterface $entityManager;
|
||||||
private array $access;
|
private Access $access;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* سازنده سرویس
|
* سازنده سرویس
|
||||||
*/
|
*/
|
||||||
public function __construct(EntityManagerInterface $entityManager, array $access)
|
public function __construct(EntityManagerInterface $entityManager, Access $access)
|
||||||
{
|
{
|
||||||
$this->entityManager = $entityManager;
|
$this->entityManager = $entityManager;
|
||||||
$this->access = $access;
|
$this->access = $access;
|
||||||
|
|
|
@ -32,8 +32,7 @@ class wizardController extends AbstractController
|
||||||
Log $log
|
Log $log
|
||||||
): JsonResponse
|
): JsonResponse
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
$acc = $access->hasRole('join');
|
$acc = $access->hasRole('join');
|
||||||
if (!$acc) {
|
if (!$acc) {
|
||||||
return $this->json([
|
return $this->json([
|
||||||
|
@ -46,8 +45,7 @@ class wizardController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
// بررسی دسترسی هوش مصنوعی
|
// بررسی دسترسی هوش مصنوعی
|
||||||
$acc = $access->hasRole('ai');
|
if (!$acc['ai']) {
|
||||||
if (!$acc) {
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'error' => 'شما دسترسی استفاده از هوش مصنوعی را ندارید',
|
'error' => 'شما دسترسی استفاده از هوش مصنوعی را ندارید',
|
||||||
|
@ -98,11 +96,7 @@ class wizardController extends AbstractController
|
||||||
'showChargeButton' => true,
|
'showChargeButton' => true,
|
||||||
'debug_info' => [
|
'debug_info' => [
|
||||||
'balance' => $currentBalance,
|
'balance' => $currentBalance,
|
||||||
'required' => $estimatedCost,
|
'required' => $estimatedCost
|
||||||
'business' => [
|
|
||||||
'id' => $business->getId(),
|
|
||||||
'name' => $business->getName(),
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
@ -148,27 +142,15 @@ class wizardController extends AbstractController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// پاکسازی خروجی از اشیای Doctrine (Business, User و ...)
|
|
||||||
array_walk_recursive($response, function (&$item) {
|
|
||||||
if (is_object($item) && method_exists($item, 'getId')) {
|
|
||||||
$item = $item->getId();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return $this->json($response);
|
return $this->json($response);
|
||||||
} else {
|
} else {
|
||||||
$errorResponse = [
|
return $this->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'error' => $result['error'] ?? 'خطای نامشخص در سرویس هوش مصنوعی',
|
'error' => $result['error'] ?? 'خطای نامشخص در سرویس هوش مصنوعی',
|
||||||
'debug_info' => $result['debug_info'] ?? ['fallback' => 'no debug info from service', 'result' => $result]
|
'debug_info' => $result['debug_info'] ?? ['fallback' => 'no debug info from service', 'result' => $result]
|
||||||
];
|
]);
|
||||||
array_walk_recursive($errorResponse, function (&$item) {
|
|
||||||
if (is_object($item) && method_exists($item, 'getId')) {
|
|
||||||
$item = $item->getId();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return $this->json($errorResponse);
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
|
|
@ -64,13 +64,15 @@ class AGIService
|
||||||
'service_status' => $status,
|
'service_status' => $status,
|
||||||
'inputs' => [
|
'inputs' => [
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
|
'business' => $business,
|
||||||
|
'user' => $user,
|
||||||
'conversationId' => $conversationId
|
'conversationId' => $conversationId
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// مدیریت گفتگو و تاریخچه
|
// مدیریت گفتگو و تاریخچه
|
||||||
$conversation = $this->manageConversation($conversationId, $business, $user, $message);
|
$conversation = $this->manageConversation($conversationId, $business, $user, $message);
|
||||||
$conversationHistory = $this->getConversationHistory($conversation);
|
$conversationHistory = $this->getConversationHistory($conversation);
|
||||||
|
@ -78,8 +80,8 @@ class AGIService
|
||||||
// ذخیره پیام کاربر
|
// ذخیره پیام کاربر
|
||||||
$this->saveUserMessage($conversation, $message);
|
$this->saveUserMessage($conversation, $message);
|
||||||
|
|
||||||
// فقط سوال کاربر به عنوان prompt
|
// ساخت پرامپ هوشمند
|
||||||
$userPrompt = $message;
|
$prompt = $this->buildSmartPrompt($message, $business, $conversationHistory);
|
||||||
$service = $this->getAIAgentSource();
|
$service = $this->getAIAgentSource();
|
||||||
$apiKey = $this->getAIApiKey($service);
|
$apiKey = $this->getAIApiKey($service);
|
||||||
|
|
||||||
|
@ -92,14 +94,16 @@ class AGIService
|
||||||
'service' => $service,
|
'service' => $service,
|
||||||
'inputs' => [
|
'inputs' => [
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
|
'business' => $business,
|
||||||
|
'user' => $user,
|
||||||
'conversationId' => $conversationId
|
'conversationId' => $conversationId
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ارسال درخواست با function calling (فقط سوال کاربر)
|
// ارسال درخواست با function calling
|
||||||
$result = $this->sendToAIServiceWithFunctionCalling($userPrompt, $apiKey, $service, $conversationHistory, $acc);
|
$result = $this->sendToAIServiceWithFunctionCalling($prompt, $apiKey, $service, $conversationHistory, $acc);
|
||||||
|
|
||||||
if (!$result['success']) {
|
if (!$result['success']) {
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -125,8 +129,18 @@ class AGIService
|
||||||
'tool_results' => $result['tool_results'] ?? []
|
'tool_results' => $result['tool_results'] ?? []
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
try {
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$this->log->error('خطا در ارسال درخواست به هوش مصنوعی: ' . $e->getMessage(), [
|
||||||
|
'context' => 'AGIService::sendRequest',
|
||||||
|
'message' => $message,
|
||||||
|
'business' => $business,
|
||||||
|
'user' => $user,
|
||||||
|
'conversationId' => $conversationId,
|
||||||
|
'exception' => $e->getMessage(),
|
||||||
|
'trace' => $e->getTraceAsString()
|
||||||
|
]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'error' => 'خطا در پردازش درخواست: ' . $e->getMessage(),
|
'error' => 'خطا در پردازش درخواست: ' . $e->getMessage(),
|
||||||
|
@ -135,6 +149,8 @@ class AGIService
|
||||||
'exception' => $e->getMessage(),
|
'exception' => $e->getMessage(),
|
||||||
'inputs' => [
|
'inputs' => [
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
|
'business' => $business,
|
||||||
|
'user' => $user,
|
||||||
'conversationId' => $conversationId
|
'conversationId' => $conversationId
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
@ -150,36 +166,33 @@ class AGIService
|
||||||
$urls = $this->getServiceUrls($service);
|
$urls = $this->getServiceUrls($service);
|
||||||
$model = $this->getAIModel();
|
$model = $this->getAIModel();
|
||||||
|
|
||||||
// پیام system شامل قوانین خروجی و مثال دقیق
|
// ساخت messages با تاریخچه
|
||||||
$systemPrompt = "شما دستیار هوشمند حسابیکس هستید. فقط پاسخ را به صورت JSON مطابق مثال خروجی بده. اگر نیاز به ابزار داشتی، از function calling استفاده کن."
|
$messages = [];
|
||||||
. $this->promptService->getOutputFormatPrompt();
|
|
||||||
$messages = [
|
// اضافه کردن تاریخچه گفتگو
|
||||||
[
|
|
||||||
'role' => 'system',
|
|
||||||
'content' => $systemPrompt
|
|
||||||
]
|
|
||||||
];
|
|
||||||
// تاریخچه گفتگو
|
|
||||||
foreach ($conversationHistory as $historyItem) {
|
foreach ($conversationHistory as $historyItem) {
|
||||||
$messages[] = [
|
$messages[] = [
|
||||||
'role' => $historyItem['role'],
|
'role' => $historyItem['role'],
|
||||||
'content' => $historyItem['content']
|
'content' => $historyItem['content']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
// پیام user فقط سوال فعلی
|
|
||||||
|
// اضافه کردن پیام فعلی
|
||||||
$messages[] = [
|
$messages[] = [
|
||||||
'role' => 'user',
|
'role' => 'user',
|
||||||
'content' => $prompt
|
'content' => $prompt
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// تعریف ابزارهای موجود
|
||||||
$tools = $this->buildToolsFromPromptServices();
|
$tools = $this->buildToolsFromPromptServices();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'model' => $model,
|
'model' => $model,
|
||||||
'messages' => $messages,
|
'messages' => $messages,
|
||||||
'tools' => $tools,
|
'tools' => $tools,
|
||||||
'tool_choice' => 'auto',
|
'tool_choice' => 'auto', // اجازه انتخاب ابزار به مدل
|
||||||
'max_tokens' => 12000,
|
'max_tokens' => 12000,
|
||||||
'temperature' => 0.9
|
'temperature' => 0.1
|
||||||
];
|
];
|
||||||
|
|
||||||
$maxIterations = 5; // حداکثر تعداد تکرار برای جلوگیری از حلقه بینهایت
|
$maxIterations = 5; // حداکثر تعداد تکرار برای جلوگیری از حلقه بینهایت
|
||||||
|
@ -207,12 +220,7 @@ class AGIService
|
||||||
'context' => 'sendToAIServiceWithFunctionCalling',
|
'context' => 'sendToAIServiceWithFunctionCalling',
|
||||||
'url_list' => $urls,
|
'url_list' => $urls,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'iteration' => $iteration,
|
'iteration' => $iteration
|
||||||
'result' => $result,
|
|
||||||
'apiKey' => $apiKey,
|
|
||||||
'service' => $service,
|
|
||||||
'conversationHistory' => $conversationHistory,
|
|
||||||
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -305,22 +313,63 @@ class AGIService
|
||||||
try {
|
try {
|
||||||
switch ($tool) {
|
switch ($tool) {
|
||||||
case 'getPersonInfo':
|
case 'getPersonInfo':
|
||||||
// استفاده مستقیم از سرویس جدید
|
// استفاده مستقیم از سرویس Cog\PersonService
|
||||||
$cogPersonService = new \App\Cog\PersonService($this->em, $params['acc'] ?? null);
|
return $this->callGetPersonInfoFromCog($params);
|
||||||
$personService = new \App\AiTool\PersonService($this->em, $cogPersonService);
|
|
||||||
return $personService->getPersonInfoByCode($params['code'] ?? null, $params['acc'] ?? null);
|
|
||||||
default:
|
default:
|
||||||
return [
|
return [
|
||||||
'error' => 'ابزار ناشناخته: ' . $tool
|
'error' => 'ابزار ناشناخته: ' . $tool
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$this->log->error('خطا در اجرای ابزار: ' . $e->getMessage(), [
|
||||||
|
'context' => 'AGIService::callTool',
|
||||||
|
'tool' => $tool,
|
||||||
|
'params' => $params,
|
||||||
|
'exception' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'error' => 'خطا در اجرای ابزار: ' . $e->getMessage()
|
'error' => 'خطا در اجرای ابزار: ' . $e->getMessage()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* اجرای ابزار getPersonInfo با استفاده از سرویس Cog\PersonService
|
||||||
|
*/
|
||||||
|
private function callGetPersonInfoFromCog(array $params)
|
||||||
|
{
|
||||||
|
$code = $params['code'] ?? null;
|
||||||
|
if (!$code) {
|
||||||
|
return [
|
||||||
|
'error' => 'کد شخص الزامی است'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// دریافت اطلاعات دسترسی (acc) از context یا پارامترها
|
||||||
|
$acc = $params['acc'] ?? null;
|
||||||
|
if (!$acc) {
|
||||||
|
return [
|
||||||
|
'error' => 'اطلاعات دسترسی (acc) الزامی است'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
// استفاده از سرویس Cog\PersonService
|
||||||
|
$personService = new \App\Cog\PersonService($this->em, $this->provider->getAccessService());
|
||||||
|
$result = $personService->getPersonInfo($code, $acc);
|
||||||
|
return $result;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->log->error('خطا در دریافت اطلاعات شخص از Cog: ' . $e->getMessage(), [
|
||||||
|
'context' => 'AGIService::callGetPersonInfoFromCog',
|
||||||
|
'code' => $code,
|
||||||
|
'exception' => $e->getMessage()
|
||||||
|
]);
|
||||||
|
return [
|
||||||
|
'error' => 'خطا در دریافت اطلاعات شخص: ' . $e->getMessage()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ساخت پرامپ هوشمند
|
* ساخت پرامپ هوشمند
|
||||||
*/
|
*/
|
||||||
|
@ -371,19 +420,9 @@ class AGIService
|
||||||
*/
|
*/
|
||||||
private function makeHttpRequest(string $url, array $data, string $apiKey): array
|
private function makeHttpRequest(string $url, array $data, string $apiKey): array
|
||||||
{
|
{
|
||||||
$requestJson = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
||||||
$debugInfo = [
|
$debugInfo = [
|
||||||
'request_url' => $url,
|
'request_url' => $url,
|
||||||
'request_data' => $data,
|
'request_data' => $data,
|
||||||
'request_headers' => [
|
|
||||||
'Content-Type' => 'application/json',
|
|
||||||
'Authorization' => 'Bearer ' . $apiKey,
|
|
||||||
],
|
|
||||||
'api_key' => $apiKey,
|
|
||||||
'model' => $data['model'] ?? null,
|
|
||||||
'request_json' => $requestJson,
|
|
||||||
'request_time' => date('Y-m-d H:i:s'),
|
|
||||||
'request_size_bytes' => strlen($requestJson),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -401,10 +440,6 @@ class AGIService
|
||||||
$content = $response->getContent(false); // false: throw exception on 4xx/5xx نمیدهد
|
$content = $response->getContent(false); // false: throw exception on 4xx/5xx نمیدهد
|
||||||
$debugInfo['http_code'] = $statusCode;
|
$debugInfo['http_code'] = $statusCode;
|
||||||
$debugInfo['raw_response'] = $content;
|
$debugInfo['raw_response'] = $content;
|
||||||
$debugInfo['response_headers'] = $response->getHeaders(false);
|
|
||||||
$debugInfo['response_time'] = date('Y-m-d H:i:s');
|
|
||||||
$debugInfo['response_size_bytes'] = strlen($content);
|
|
||||||
$debugInfo['response_sample'] = mb_substr($content, 0, 500, 'UTF-8');
|
|
||||||
|
|
||||||
if ($statusCode !== 200) {
|
if ($statusCode !== 200) {
|
||||||
$debugInfo['http_error_message'] = $this->getHttpErrorMessage($statusCode);
|
$debugInfo['http_error_message'] = $this->getHttpErrorMessage($statusCode);
|
||||||
|
@ -426,7 +461,6 @@ class AGIService
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$debugInfo['response_data'] = $responseData;
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'data' => $responseData,
|
'data' => $responseData,
|
||||||
|
@ -595,6 +629,13 @@ class AGIService
|
||||||
return (bool) ($this->registryMGR->get('system', 'aiEnabled') ?? false);
|
return (bool) ($this->registryMGR->get('system', 'aiEnabled') ?? false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* دریافت پرامپ هوش مصنوعی
|
||||||
|
*/
|
||||||
|
public function getAIPrompt(): string
|
||||||
|
{
|
||||||
|
return $this->registryMGR->get('system', 'aiPrompt') ?? 'شما یک دستیار هوشمند برای سیستم حسابداری هستید.';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* مدیریت گفتگو - ایجاد یا بازیابی گفتگوی موجود
|
* مدیریت گفتگو - ایجاد یا بازیابی گفتگوی موجود
|
||||||
|
@ -792,19 +833,6 @@ class AGIService
|
||||||
*/
|
*/
|
||||||
private function buildToolsFromPromptServices(): array
|
private function buildToolsFromPromptServices(): array
|
||||||
{
|
{
|
||||||
// بر اساس آخرین مستندات OpenAI و OpenRouter، باید هر ابزار به صورت زیر باشد:
|
return $this->promptService->getAllTools();
|
||||||
// [
|
|
||||||
// 'type' => 'function',
|
|
||||||
// 'function' => [
|
|
||||||
// 'name' => ..., 'description' => ..., 'parameters' => [...]
|
|
||||||
// ]
|
|
||||||
// ]
|
|
||||||
// این ساختار در PromptService رعایت شده اما اینجا یکبار دیگر چک و لاگ میکنیم
|
|
||||||
$tools = $this->promptService->getAllTools();
|
|
||||||
// ابزارها را در لاگ دیباگ ذخیره کن
|
|
||||||
if (method_exists($this->log, 'debug')) {
|
|
||||||
$this->log->debug('AIService tools', ['tools' => $tools]);
|
|
||||||
}
|
|
||||||
return $tools;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,13 +26,6 @@ class BankPromptService
|
||||||
$bankAccountInfoData = json_decode($bankAccountInfoPrompt, true);
|
$bankAccountInfoData = json_decode($bankAccountInfoPrompt, true);
|
||||||
|
|
||||||
if ($bankAccountInfoData) {
|
if ($bankAccountInfoData) {
|
||||||
// اصلاح ساختار properties
|
|
||||||
$properties = [
|
|
||||||
'code' => [
|
|
||||||
'type' => 'string',
|
|
||||||
'description' => 'Bank account code (e.g., 1001, 1002)'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
$tools[] = [
|
$tools[] = [
|
||||||
'type' => 'function',
|
'type' => 'function',
|
||||||
'function' => [
|
'function' => [
|
||||||
|
@ -40,8 +33,8 @@ class BankPromptService
|
||||||
'description' => $bankAccountInfoData['description'],
|
'description' => $bankAccountInfoData['description'],
|
||||||
'parameters' => [
|
'parameters' => [
|
||||||
'type' => 'object',
|
'type' => 'object',
|
||||||
'properties' => $properties,
|
'properties' => $bankAccountInfoData['input'],
|
||||||
'required' => ['code']
|
'required' => array_keys($bankAccountInfoData['input'])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
@ -26,13 +26,6 @@ class InventoryPromptService
|
||||||
$itemInfoData = json_decode($itemInfoPrompt, true);
|
$itemInfoData = json_decode($itemInfoPrompt, true);
|
||||||
|
|
||||||
if ($itemInfoData) {
|
if ($itemInfoData) {
|
||||||
// اصلاح ساختار properties
|
|
||||||
$properties = [
|
|
||||||
'code' => [
|
|
||||||
'type' => 'string',
|
|
||||||
'description' => 'Item code (e.g., 1001, 1002)'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
$tools[] = [
|
$tools[] = [
|
||||||
'type' => 'function',
|
'type' => 'function',
|
||||||
'function' => [
|
'function' => [
|
||||||
|
@ -40,8 +33,8 @@ class InventoryPromptService
|
||||||
'description' => $itemInfoData['description'],
|
'description' => $itemInfoData['description'],
|
||||||
'parameters' => [
|
'parameters' => [
|
||||||
'type' => 'object',
|
'type' => 'object',
|
||||||
'properties' => $properties,
|
'properties' => $itemInfoData['input'],
|
||||||
'required' => ['code']
|
'required' => array_keys($itemInfoData['input'])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
@ -26,13 +26,6 @@ class PersonPromptService
|
||||||
$personInfoData = json_decode($personInfoPrompt, true);
|
$personInfoData = json_decode($personInfoPrompt, true);
|
||||||
|
|
||||||
if ($personInfoData) {
|
if ($personInfoData) {
|
||||||
// اصلاح ساختار properties
|
|
||||||
$properties = [
|
|
||||||
'code' => [
|
|
||||||
'type' => 'string',
|
|
||||||
'description' => 'Person code (e.g., 1001, 1002)'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
$tools[] = [
|
$tools[] = [
|
||||||
'type' => 'function',
|
'type' => 'function',
|
||||||
'function' => [
|
'function' => [
|
||||||
|
@ -40,8 +33,8 @@ class PersonPromptService
|
||||||
'description' => $personInfoData['description'],
|
'description' => $personInfoData['description'],
|
||||||
'parameters' => [
|
'parameters' => [
|
||||||
'type' => 'object',
|
'type' => 'object',
|
||||||
'properties' => $properties,
|
'properties' => $personInfoData['input'],
|
||||||
'required' => ['code']
|
'required' => array_keys($personInfoData['input'])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue