-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
594173e
commit 70a9427
Showing
6 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
docs/pages/docs/features/ai/prompt-subject-responders/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
collections: | ||
- documents | ||
layout: dm:document | ||
parent: docs/features/ai/index | ||
title: Prompt Subject Responders | ||
description: > | ||
Handle HTTP requests with asynchronous HTTP Responders. | ||
--- | ||
|
||
# Prompt Subject Responders | ||
|
||
:::note | ||
At the moment this feature requires {{docs/features/ai/server/llama-cpp/index}}. | ||
|
||
In the future releases we plan to support [Ollama](https://ollama.com/). | ||
::: | ||
|
||
This feature allows to implement a convenient LLM Chat Controllers that can | ||
provide responses to LLM prompts on specific topics. | ||
|
||
It automatically prepares both the system prompt and | ||
[Backus–Naur form](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) | ||
grammar that are forwarded to the LLM through | ||
{{docs/features/ai/server/llama-cpp/index}}. | ||
|
||
# Usage | ||
|
||
Let's define the following LLM prompt controller: | ||
|
||
```php | ||
<?php | ||
|
||
namespace App\PromptSubjectResponder; | ||
|
||
use Distantmagic\Resonance\Attribute\RespondsToPromptSubject; | ||
use Distantmagic\Resonance\Attribute\Singleton; | ||
use Distantmagic\Resonance\PromptSubjectRequest; | ||
use Distantmagic\Resonance\PromptSubjectResponderInterface; | ||
use Distantmagic\Resonance\PromptSubjectResponse; | ||
use Distantmagic\Resonance\SingletonCollection; | ||
|
||
#[RespondsToPromptSubject( | ||
action: 'adopt', | ||
subject: 'cat', | ||
)] | ||
#[Singleton(collection: SingletonCollection::PromptSubjectResponder)] | ||
readonly class CatAdopt implements PromptSubjectResponderInterface | ||
{ | ||
public function respondToPromptSubject(PromptSubjectRequest $request, PromptSubjectResponse $response): void | ||
{ | ||
$response->write("Here you go:\n\n"); | ||
$response->write(" |\_._/|\n"); | ||
$response->write(" | o o |\n"); | ||
$response->write(" ( T )\n"); | ||
$response->write(" .^`-^-`^.\n"); | ||
$response->write(" `. ; .`\n"); | ||
$response->write(" | | | | |\n"); | ||
$response->write(" ((_((|))_))\n"); | ||
$response->end(); | ||
} | ||
} | ||
``` | ||
|
||
Each time user mentions something like: | ||
- `I want to adopt a cat` | ||
- `Give me some kittens please` | ||
- etc | ||
|
||
That questions will be forwarded to the above controller. All you need to do is | ||
to specify the `action` and `subject` parameters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters