Skip to content

Commit

Permalink
fix(tests): update assertions for messages and standalone_question
Browse files Browse the repository at this point in the history
- Adjusted `assertDatabaseCount` in `DatabaseMemoryTest.php` to expect 4 messages instead of 2.
- Modified `ChatRephraseAgentTest.php` to check for updated standalone question wording.
  • Loading branch information
use-the-fork committed Oct 11, 2024
1 parent 74e0a2a commit a2a8874
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
38 changes: 19 additions & 19 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ export default defineConfig({
{ text: 'Traits', link: '/agents/agent-traits' },
],
},
{
text: 'Prebuilt Agents',
items: [
{ text: 'Introduction', link: '/prebuilt-agents/' },
{
text: 'Multi Query Retriever',
link: '/prebuilt-agents/multi-query-retriever-agent',
},
{
text: 'Contextual Retrieval Preprocessing',
link: '/prebuilt-agents/contextual-retrieval-preprocessing-agent',
},
{
text: 'Chat Rephrase',
link: '/prebuilt-agents/chat-rephrase-agent',
},
],
},
{
text: 'Prompts',
items: [
Expand Down Expand Up @@ -72,25 +90,7 @@ export default defineConfig({
{ text: 'Logs', link: '/traits/log-trait' },
{ text: 'Hooks', link: '/traits/hook-trait' },
],
},
{
text: 'Prebuilt Agents',
items: [
{ text: 'Introduction', link: '/prebuilt-agents/' },
{
text: 'Multi Query Retriever',
link: '/prebuilt-agents/multi-query-retriever-agent',
},
{
text: 'Contextual Retrieval Preprocessing',
link: '/prebuilt-agents/contextual-retrieval-preprocessing-agent',
},
{
text: 'Chat Rephrase',
link: '/prebuilt-agents/chat-rephrase-agent',
},
],
},
}
],

socialLinks: [
Expand Down
34 changes: 17 additions & 17 deletions tests/Agents/ChatRephraseAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

declare(strict_types=1);

use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
use Saloon\Http\PendingRequest;
use UseTheFork\Synapse\Agents\ChatRephraseAgent;
use UseTheFork\Synapse\Constants\Role;
use UseTheFork\Synapse\Enums\FinishReason;
use UseTheFork\Synapse\Integrations\Connectors\OpenAI\Requests\ChatRequest;
use UseTheFork\Synapse\ValueObject\Message;
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
use Saloon\Http\PendingRequest;
use UseTheFork\Synapse\Agents\ChatRephraseAgent;
use UseTheFork\Synapse\Constants\Role;
use UseTheFork\Synapse\Enums\FinishReason;
use UseTheFork\Synapse\Integrations\Connectors\OpenAI\Requests\ChatRequest;
use UseTheFork\Synapse\ValueObject\Message;

it('can run the Chat Rephrase Agent.', function () {
it('can run the Chat Rephrase Agent.', function (): void {

MockClient::global([
ChatRequest::class => function (PendingRequest $pendingRequest): \Saloon\Http\Faking\Fixture {
$count = md5(json_encode($pendingRequest->body()->get('messages')));
ChatRequest::class => function (PendingRequest $pendingRequest): \Saloon\Http\Faking\Fixture {
$count = md5(json_encode($pendingRequest->body()->get('messages')));

return MockResponse::fixture("Agents/ChatRephraseAgent-{$count}");
},
]);
return MockResponse::fixture("Agents/ChatRephraseAgent-{$count}");
},
]);

$agent = new ChatRephraseAgent;
$agent->addMessageToMemory(Message::make([
Expand All @@ -33,10 +33,10 @@
'content' => 'For a balanced gym routine, I recommend incorporating a mix of cardio, strength training, and flexibility exercises. Start with 20-30 minutes of cardiovascular activities like running on the treadmill, cycling, or using the elliptical to improve heart health and endurance. Follow this with strength training exercises, such as weightlifting or bodyweight exercises like squats, deadlifts, bench presses, and pull-ups, to build muscle and enhance metabolism. Finish with 10-15 minutes of stretching or yoga to improve flexibility, reduce the risk of injury, and aid muscle recovery. This combination ensures a comprehensive workout that targets overall fitness, strength, and flexibility.',
]));

$agentResponse = $agent->handle(['input' => 'improve heart health?']);
$agentResponseArray = $agentResponse->toArray();
$message = $agent->handle(['input' => 'improve heart health?']);
$agentResponseArray = $message->toArray();

expect($agentResponseArray['content'])->toBeArray()
->and($agentResponseArray['content'])->toHaveKey('standalone_question')
->and($agentResponseArray['content']['standalone_question'] == 'How can I improve my heart health?')->toBeTrue();
->and($agentResponseArray['content']['standalone_question'] == 'How can one improve heart health?')->toBeTrue();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"statusCode": 200,
"headers": {
"Date": "Fri, 11 Oct 2024 22:52:21 GMT",
"Content-Type": "application\/json",
"Content-Length": "711",
"Connection": "keep-alive"
},
"data": "{\n \"id\": \"chatcmpl-AHImZj9bW9sqXPa4GJT48mugS5Pe8\",\n \"object\": \"chat.completion\",\n \"created\": 1728687139,\n \"model\": \"gpt-4-turbo-2024-04-09\",\n \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\": \"assistant\",\n \"content\": \"```json\\n{\\n \\\"standalone_question\\\": \\\"How can one improve heart health?\\\"\\n}\\n```\",\n \"refusal\": null\n },\n \"logprobs\": null,\n \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\": 237,\n \"completion_tokens\": 20,\n \"total_tokens\": 257,\n \"prompt_tokens_details\": {\n \"cached_tokens\": 0\n },\n \"completion_tokens_details\": {\n \"reasoning_tokens\": 0\n }\n },\n \"system_fingerprint\": \"fp_4dba7dd7b3\"\n}\n"
}
2 changes: 1 addition & 1 deletion tests/Memory/DatabaseMemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public function resolveMemory(): Memory
->and($followupResponseArray['content']['answer'])->toBe('.sdrawkcab yas tsuj I did tahw');

$this->assertDatabaseCount('agent_memories', 1);
$this->assertDatabaseCount('messages', 2);
$this->assertDatabaseCount('messages', 4);

});

0 comments on commit a2a8874

Please sign in to comment.