From ecb24aaa2d205413b69dbbe9614cc43b968737d4 Mon Sep 17 00:00:00 2001 From: MaestroError <46760939+MaestroError@users.noreply.github.com> Date: Mon, 13 Jan 2025 23:00:20 +0000 Subject: [PATCH] Fix styling --- src/Drivers/OpenAi/OpenAiDriver.php | 4 ++-- src/History/JsonChatHistory.php | 3 ++- src/LarAgent.php | 2 +- test-json-history-2.php | 5 +---- test-json-history.php | 5 +---- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Drivers/OpenAi/OpenAiDriver.php b/src/Drivers/OpenAi/OpenAiDriver.php index e8d8f64..d9cd346 100644 --- a/src/Drivers/OpenAi/OpenAiDriver.php +++ b/src/Drivers/OpenAi/OpenAiDriver.php @@ -57,7 +57,7 @@ public function sendMessage(array $messages, array $options = []): AssistantMess ]; if ($finishReason === 'tool_calls') { - + // Collect tool calls from the response $toolCalls = array_map(function ($toolCall) { return new ToolCall($toolCall->id, $toolCall->function->name, $toolCall->function->arguments); @@ -65,7 +65,7 @@ public function sendMessage(array $messages, array $options = []): AssistantMess // Build tool calls message with needed structure $message = $this->toolCallsToMessage($toolCalls); - + return new ToolCallMessage($toolCalls, $message, $metaData); } diff --git a/src/History/JsonChatHistory.php b/src/History/JsonChatHistory.php index 5b7eed6..e59f4b0 100644 --- a/src/History/JsonChatHistory.php +++ b/src/History/JsonChatHistory.php @@ -13,7 +13,7 @@ class JsonChatHistory extends ChatHistory implements ChatHistoryInterface public function __construct(string $name, array $options = []) { // By default store the JSON files in the json_storage folder at project root - $this->folder = $options['folder'] ?? dirname(__DIR__, 2) . "/json_storage"; + $this->folder = $options['folder'] ?? dirname(__DIR__, 2).'/json_storage'; parent::__construct($name, $options); } @@ -25,6 +25,7 @@ public function readFromMemory(): void $file = $this->getFullPath(); if (file_exists($file) === false) { $this->messages = []; + return; } // Read JSON diff --git a/src/LarAgent.php b/src/LarAgent.php index 1f8a6d3..27c5d62 100644 --- a/src/LarAgent.php +++ b/src/LarAgent.php @@ -301,7 +301,7 @@ protected function buildConfig(): array 'temperature' => $this->getTemperature(), ]; - if (!empty($this->tools)) { + if (! empty($this->tools)) { $configs['parallel_tool_calls'] = $this->getParallelToolCalls(); // @todo make tool choice controllable (required & specific tool) $configs['tool_choice'] = 'auto'; diff --git a/test-json-history-2.php b/test-json-history-2.php index b0da7ad..5ec08ac 100644 --- a/test-json-history-2.php +++ b/test-json-history-2.php @@ -6,22 +6,19 @@ use Maestroerror\LarAgent\History\JsonChatHistory; use Maestroerror\LarAgent\LarAgent; use Maestroerror\LarAgent\Message; -use Maestroerror\LarAgent\Messages\ToolCallMessage; -use Maestroerror\LarAgent\Tool; // Setup $yourApiKey = include 'openai-api-key.php'; $driver = new OpenAiDriver($yourApiKey); $chatKey = 'test-json-history'; $chatHistory = new JsonChatHistory($chatKey, [ - "folder" => __DIR__.'/chat-history', + 'folder' => __DIR__.'/chat-history', ]); $agent = LarAgent::setup($driver, $chatHistory, [ 'model' => 'gpt-4o-mini', ]); - $userMessage = Message::user('Please remind me my name'); $instuctions = 'You are handfull assistant and you always use my name in the conversation'; diff --git a/test-json-history.php b/test-json-history.php index 6a41689..c5f68f6 100644 --- a/test-json-history.php +++ b/test-json-history.php @@ -6,22 +6,19 @@ use Maestroerror\LarAgent\History\JsonChatHistory; use Maestroerror\LarAgent\LarAgent; use Maestroerror\LarAgent\Message; -use Maestroerror\LarAgent\Messages\ToolCallMessage; -use Maestroerror\LarAgent\Tool; // Setup $yourApiKey = include 'openai-api-key.php'; $driver = new OpenAiDriver($yourApiKey); $chatKey = 'test-json-history'; $chatHistory = new JsonChatHistory($chatKey, [ - "folder" => __DIR__.'/chat-history', + 'folder' => __DIR__.'/chat-history', ]); $agent = LarAgent::setup($driver, $chatHistory, [ 'model' => 'gpt-4o-mini', ]); - $userMessage = Message::user('My name is revaz'); $instuctions = 'You are handfull assistant and you always use my name in the conversation';