It is possible to migrate from database driven chat/completion behavior to assistants api methods. I will not lost my data from conversation und also I will use the optimization functions from assistants api.
I use open AI php client in Laravel for the beta assistants api. Currently I have this solution:
$messages = Message::where(user_id, Auth::id())->orderBy('created_at', 'asc') -> select(['role', 'content']);
$chatMessages = $messages->map(function ($item) {
return ['role' => $item->role, 'content' => $item->content];
});
$chat_instruction = 'this is a super bot';
$message_instruction = ['role' => 'assistant', 'content' => $chat_instruction];
$chatMessages->prepend($message_instruction);
$response = $client->chat()->create([
'model' => 'gpt-4-1106-preview',
'messages' => $chatMessages,
'temperature' => 0,
'tools' => $tools,
]);