PHP code example of nomanur / laravel-markdown-rag
1. Go to this page and download the library: Download nomanur/laravel-markdown-rag library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Nomanur\Ai\Agents\KnowledgeAgent;
use Nomanur\Models\History;
use Laravel\Ai\Messages\Message;
KnowledgeAgent::resolveMessagesUsing(function ($agent) {
return History::where('user_id', $agent->user->id)
->where('agent', 'knowledge')
->latest()
->skip(1) // Your custom skip logic
->when(config('laravel-markdown-rag.markdown_chat_rate_limit'), fn($query, $limit) => $query->limit($limit))
->get()
->reverse()
->map(fn($message) => new Message($message->role, $message->content))
->all();
});
use Nomanur\Ai\Agents\KnowledgeAgent;
use Nomanur\Models\History;
use Laravel\Ai\Messages\Message;
class ExtendedKnowledgeAgent extends KnowledgeAgent
{
public function messages(): iterable
{
// Custom implementation with skip(1)
return History::where('user_id', $this->user->id)
->where('agent', 'knowledge')
->latest()
->skip(1)
->when(config('laravel-markdown-rag.markdown_chat_rate_limit'), fn($query, $limit) => $query->limit($limit))
->get()
->reverse()
->map(fn($message) => new Message($message->role, $message->content))
->all();
}
}
use Nomanur\Ai\Agents\KnowledgeAgent;
KnowledgeAgent::resolveInstructionsUsing(function (KnowledgeAgent $agent) {
if ($agent->document) {
return "You are an expert on {$agent->document->name}. Answer questions strictly based on it.";
}
return "You are a helpful AI assistant.";
});
use Nomanur\Ai\Agents\KnowledgeAgent;
use Stringable;
class ExtendedKnowledgeAgent extends KnowledgeAgent
{
public function instructions(): Stringable|string
{
return "You are a highly capable and friendly assistant.";
}
}
use Nomanur\Ai\Tools\KnowledgeSearchTool;
KnowledgeSearchTool::resolveDescriptionUsing(function (KnowledgeSearchTool $tool) {
return "Search the internal knowledge base for company policies and HR documents only.";
});