Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MaestroError committed Jan 19, 2025
2 parents 95b4f60 + ecb24aa commit 27a51f2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Drivers/OpenAi/OpenAiDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ 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);
}, $this->lastResponse->choices[0]->message->toolCalls);

// Build tool calls message with needed structure
$message = $this->toolCallsToMessage($toolCalls);

return new ToolCallMessage($toolCalls, $message, $metaData);
}

Expand Down
3 changes: 2 additions & 1 deletion src/History/JsonChatHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -25,6 +25,7 @@ public function readFromMemory(): void
$file = $this->getFullPath();
if (file_exists($file) === false) {
$this->messages = [];

return;
}
// Read JSON
Expand Down
2 changes: 1 addition & 1 deletion src/LarAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 1 addition & 4 deletions test-json-history-2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(["api_key" => $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';

Expand Down
5 changes: 1 addition & 4 deletions test-json-history.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(["api_key" => $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';

Expand Down

0 comments on commit 27a51f2

Please sign in to comment.