-
-
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.
Merge pull request #4 from use-the-fork/development
Development
- Loading branch information
Showing
118 changed files
with
2,842 additions
and
428 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
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,4 +1,10 @@ | ||
@isset($outputSchema) | ||
### You must respond using the following schema. Immediately return valid JSON formatted data: | ||
### Mandatory Response Format | ||
Return all responses exclusively in JSON format following this structure with out **ANY** surrounding text: | ||
{!! $outputSchema !!} | ||
|
||
Always ensure that the response adheres strictly to this format, as it will be used for API purposes. | ||
|
||
### Start Response ### | ||
```json | ||
@endisset |
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,10 @@ | ||
<message type="user"> | ||
### Instruction | ||
Try to answer this question/instruction with step-by-step thoughts and make the answer more structural. Split the answer into several paragraphs. | ||
{!! $question !!} | ||
|
||
@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,11 @@ | ||
<message type="user"> | ||
## User input: {{ $question }} | ||
|
||
## Response | ||
{{ $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. | ||
|
||
@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,12 @@ | ||
<message type="user"> | ||
## User input: {{ $question }} | ||
|
||
## Response | ||
{{ $answer }} | ||
|
||
## Instruction | ||
Split the answer of the question into multiple paragraphs with each paragraph containing a complete thought. | ||
The answer should be splited into less than {{ $number_of_paragraphs }} paragraphs. | ||
|
||
@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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
# Instruction | ||
Your final response did not adhere the required Schema. | ||
** DO NOT EXPLAIN. Only return your final response with the requested format.** | ||
|
||
## You must respond in this format: | ||
{!! $outputRules !!} | ||
|
||
@if(!empty($errors)) | ||
## The following error occurred in the last Rewrite: | ||
## The following error occurred in the last response: | ||
{!! $errors !!} | ||
@endif | ||
|
||
@if(!empty($lastResponse)) | ||
### Start Last Response ### | ||
{!! $lastResponse !!} | ||
### End Last Response ### | ||
@endif | ||
|
||
@include('synapse::Parts.OutputSchema') |
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,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UseTheFork\Synapse; | ||
|
||
use UseTheFork\Synapse\AgentTask\PendingAgentChain; | ||
use UseTheFork\Synapse\Traits\HasConfig; | ||
use UseTheFork\Synapse\Traits\Makeable; | ||
use UseTheFork\Synapse\ValueObject\Message; | ||
|
||
class AgentChain | ||
{ | ||
use Makeable; | ||
use HasConfig; | ||
|
||
protected PendingAgentChain $pendingAgentChain; | ||
protected $pipeline; | ||
|
||
public function __construct(array $agents) | ||
{ | ||
foreach ($agents as $agent) { | ||
if(! ($agent instanceof Agent)){ | ||
throw new \Exception("Agent must be an instance of Agent"); | ||
} | ||
} | ||
|
||
$this->config()->add('persistInputs', []); | ||
$this->config()->add('agents', collect($agents)); | ||
$this->pendingAgentChain = $this->createPendingAgentChain(); | ||
|
||
} | ||
|
||
/** | ||
* Create a new PendingAgentTask | ||
*/ | ||
public function createPendingAgentChain(): PendingAgentChain | ||
{ | ||
return new PendingAgentChain($this); | ||
} | ||
|
||
/** | ||
* Handles the user input and extra agent arguments to retrieve the response. | ||
* | ||
* @param array|null $input The input array. | ||
* @param array|null $extraAgentArgs The extra agent arguments array. | ||
* @return Message The final message from the agent. | ||
* | ||
* @throws Throwable | ||
*/ | ||
public function handle(?array $input): Message | ||
{ | ||
$this->config()->add('input', $input); | ||
$this->config()->get('agents')->each(function ($agent) use ($input) { | ||
$input = [ | ||
...$this->config()->get('input'), | ||
...$this->config()->get('persistInputs') | ||
]; | ||
$response = $agent->handle($input); | ||
$this->config()->add('input', $response->content()); | ||
}); | ||
|
||
return Message::make([ | ||
'role' => 'agent', | ||
'finish_reason' => 'stop', | ||
'content' => $this->config()->get('input') | ||
]); | ||
} | ||
|
||
public function persistInputs(array $inputs): static | ||
{ | ||
$this->config()->add('persistInputs', $inputs); | ||
|
||
return $this; | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace UseTheFork\Synapse\AgentTask; | ||
|
||
use UseTheFork\Synapse\AgentChain; | ||
use UseTheFork\Synapse\AgentTask\StartTasks\BootTraits; | ||
|
||
class PendingAgentChain | ||
{ | ||
|
||
protected AgentChain $agentChain; | ||
|
||
public function __construct(AgentChain $agentChain) | ||
{ | ||
$this->agentChain = $agentChain; | ||
|
||
$this | ||
->tap(new BootTraits); | ||
|
||
} | ||
|
||
/** | ||
* Tap into the agent chain | ||
* | ||
* @return $this | ||
*/ | ||
protected function tap(callable $callable): static | ||
{ | ||
$callable($this); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve the agent associated with the current task. | ||
* | ||
* @return AgentChain The current agent instance. | ||
*/ | ||
public function agent(): AgentChain | ||
{ | ||
return $this->agentChain; | ||
} | ||
|
||
} |
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.