Open dekdynamics opened 1 month ago
To implement reading AI prompts from a file, follow these steps:
Modify SimpleInferencer.php
:
inference
method to read the contents of KB.md
or KB.txt
and include it in the systemPrompt
.
public function inference(string $prompt, string $model, Thread $thread, callable $streamFunction, string $systemPrompt = ''): array
{
$kbFilePath = 'path/to/knowledge-files/KB.txt';
if (file_exists($kbFilePath)) {
$systemPrompt = file_get_contents($kbFilePath);
}
// existing code...
}
Update AI Gateway Classes:
OpenAIGateway.php
, AnthropicAIGateway.php
) correctly handles the updated systemPrompt
.OpenAIGateway.php
:
public function inference(array $params): array
{
$model = $params['model'];
$messages = $params['messages'];
$streamFunction = $params['stream_function'];
$systemPrompt = $params['system_prompt'] ?? 'You are a helpful assistant.';
// existing code...
}
Update Livewire Components:
create.blade.php
and edit.blade.php
to include a file upload field for the knowledge base file.
<x-filepond wire:model="kbFile" />
public $kbFile;
public function submit() { if ($this->kbFile) { $this->kbFile->storeAs('knowledge-files', 'KB.txt'); } // existing code... }
Update SimpleInferencer.php
to Pass systemPrompt
:
systemPrompt
is passed to the gateway classes.
$params = [
'model' => $model,
'messages' => $messages,
'max_tokens' => $this->remainingTokens,
'stream_function' => $streamFunction,
'system_prompt' => $systemPrompt,
];
/app/AI/SimpleInferencer.php /app/AI/GatewayInterface.php /app/AI/OpenAIGateway.php /app/AI/AnthropicAIGateway.php /app/AI/CohereAIGateway.php /app/AI/GeminiAIGateway.php /app/AI/GreptileGateway.php /app/AI/GroqAIGateway.php /app/AI/HuggingfaceAIGateway.php /app/AI/MistralAIGateway.php /app/AI /resources/views/livewire/agents /resources/views/livewire/agents/create.blade.php /resources/views/livewire/agents/edit.blade.php
Hi,
This is a request for an enhancement to the AI agent behaviour.
My ideal scenario is that I would have a file called KB.md or (.txt), which serves as the extended agent prompt.
In this file, I would explain details of what the agent should do, how it should respond, explanations of the files in its repository, and minutiae regarding the topics it should know.
Here is an example of the syntax I started with, but I am open to anything: