-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): remove obsolete RatAgentChain fixture files 🗑️
- Deleted multiple obsolete fixture files under `tests/Fixtures/Saloon/AgentChains/`. - Cleaned up unnecessary test data and improved project organization.
- Loading branch information
1 parent
1290b94
commit b2ba6e7
Showing
47 changed files
with
488 additions
and
348 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
<message type="user"> | ||
## User input: {{ $question }} | ||
### Question: {{ $question }} | ||
|
||
## Response | ||
### Content | ||
{{ $answer }} | ||
|
||
## Instruction | ||
Summarize the content with a focus on the last sentences to create a concise search query for Bing. Use search syntax to make the query specific and relevant for content verification. | ||
### Instruction | ||
I want to verify the content correctness of the given question, especially the last sentences. | ||
Please summarize the content with the corresponding question. | ||
This summarization will be used as a query to search with Bing search engine. | ||
The query should be short but need to be specific to promise Bing can find related knowledge or pages. | ||
You can also use search syntax to make the query short and clear enough for the search engine to find relevant language data. | ||
Try to make the query as relevant as possible to the last few sentences in the content. | ||
|
||
@include('synapse::Parts.OutputSchema') | ||
</message> |
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,16 @@ | ||
<message type="user"> | ||
### Question: {{ $question }} | ||
|
||
### Answer: | ||
{{ $answer }} | ||
|
||
### Instruction | ||
Give a title for the answer of the question. | ||
And add a subtitle to each paragraph in the answer and output the final answer using markdown format. | ||
This will make the answer to this question look more structured for better understanding. | ||
|
||
**IMPORTANT** | ||
Try to keep the structure (multiple paragraphs with its subtitles) in the response and make it more structural for understanding. | ||
|
||
@include('synapse::Parts.OutputSchema') | ||
</message> |
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,25 @@ | ||
<message type="user"> | ||
### Existing Text in Wiki Web: | ||
``` | ||
{{ $content }} | ||
``` | ||
|
||
### Question: {{ $question }} | ||
|
||
### Answer: | ||
{{ $answer }} | ||
|
||
### Instruction | ||
I want to revise the answer according to retrieved related text of the question in WIKI pages. | ||
You need to check whether the answer is correct. | ||
If you find some errors in the answer, revise the answer to make it better. | ||
If you find some necessary details are ignored, add it to make the answer more plausible according to the related text. | ||
If you find the answer is right and do not need to add more details, just output the original answer directly. | ||
|
||
**IMPORTANT** | ||
Try to keep the structure (multiple paragraphs with its subtitles) in the revised answer and make it more structural for understanding. | ||
Add more details from retrieved text to the answer. | ||
Split the paragraphs with \n\n characters. | ||
|
||
@include('synapse::Parts.OutputSchema') | ||
</message> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UseTheFork\Synapse\AgentChains; | ||
|
||
use UseTheFork\Synapse\AgentChain; | ||
use UseTheFork\Synapse\Agents\Rat\GetQueryAgent; | ||
use UseTheFork\Synapse\Agents\Rat\RatDraftAgent; | ||
use UseTheFork\Synapse\Agents\Rat\RatSplitAnswerAgent; | ||
use UseTheFork\Synapse\Agents\Rat\ReflectAnswerAgent; | ||
use UseTheFork\Synapse\Agents\Rat\ReviseAnswerAgent; | ||
use UseTheFork\Synapse\Contracts\Tool\ScrapeTool; | ||
use UseTheFork\Synapse\Contracts\Tool\SearchTool; | ||
use UseTheFork\Synapse\ValueObject\Message; | ||
|
||
/* | ||
* See: https://github.com/CraftJarvis/RAT/tree/main | ||
*/ | ||
class RatAgentChain extends AgentChain | ||
{ | ||
protected ScrapeTool $scrapeTool; | ||
protected SearchTool $searchTool; | ||
|
||
public function __construct(SearchTool $searchTool, ScrapeTool $scrapeTool) | ||
{ | ||
$this->searchTool = $searchTool; | ||
$this->scrapeTool = $scrapeTool; | ||
} | ||
|
||
public function handle(?array $input, ?array $extraAgentArgs = []): Message | ||
{ | ||
|
||
$ratDraftAgent = new RatDraftAgent; | ||
$result = $ratDraftAgent->handle($input); | ||
|
||
$ratSplitAnswerAgent = new RatSplitAnswerAgent; | ||
$result = $ratSplitAnswerAgent->handle([ | ||
...$input, | ||
...$result->content() | ||
]); | ||
|
||
$answer = str(''); | ||
foreach ($result->content()['paragraphs'] as $value) { | ||
|
||
$answer = $answer->append("\n\n", $value); | ||
|
||
$getQueryAgent = new GetQueryAgent; | ||
$result = $getQueryAgent->handle([ | ||
...$input, | ||
'answer' => $answer->toString() | ||
]); | ||
|
||
$searchResult = $this->searchTool->handle($result->content()['query']); | ||
$searchResult = json_decode($searchResult, true); | ||
|
||
# Get the first Result scrape page and enhance | ||
if(!empty($searchResult[0])){ | ||
$scrapeResult = $this->scrapeTool->handle($searchResult[0]['link']); | ||
|
||
$getQueryAgent = new ReviseAnswerAgent; | ||
$result = $getQueryAgent->handle([ | ||
...$input, | ||
'content' => $scrapeResult, | ||
'answer' => $answer->toString() | ||
]); | ||
$answer = str($result->content()['answer']); | ||
} | ||
|
||
} | ||
|
||
$reflectAnswerAgent = new ReflectAnswerAgent; | ||
return $reflectAnswerAgent->handle([ | ||
...$input, | ||
'answer' => $answer->toString() | ||
]); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UseTheFork\Synapse\Agents\Rat; | ||
|
||
use UseTheFork\Synapse\Agent; | ||
use UseTheFork\Synapse\Traits\Agent\ValidatesOutputSchema; | ||
use UseTheFork\Synapse\ValueObject\SchemaRule; | ||
|
||
class ReflectAnswerAgent extends Agent | ||
{ | ||
use ValidatesOutputSchema; | ||
|
||
protected string $promptView = 'synapse::Prompts.Rat.ReflectAnswerPrompt'; | ||
|
||
public function resolveOutputSchema(): array | ||
{ | ||
return [ | ||
SchemaRule::make([ | ||
'name' => 'answer', | ||
'rules' => 'required|string', | ||
'description' => 'Your answer.', | ||
]), | ||
]; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UseTheFork\Synapse\Agents\Rat; | ||
|
||
use UseTheFork\Synapse\Agent; | ||
use UseTheFork\Synapse\Traits\Agent\ValidatesOutputSchema; | ||
use UseTheFork\Synapse\ValueObject\SchemaRule; | ||
|
||
class ReviseAnswerAgent extends Agent | ||
{ | ||
use ValidatesOutputSchema; | ||
|
||
protected string $promptView = 'synapse::Prompts.Rat.ReviseAnswerPrompt'; | ||
|
||
public function resolveOutputSchema(): array | ||
{ | ||
return [ | ||
SchemaRule::make([ | ||
'name' => 'answer', | ||
'rules' => 'required|string', | ||
'description' => 'Your answer.', | ||
]), | ||
]; | ||
} | ||
} |
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
Oops, something went wrong.