From a2a88749287309f7188bc314962cdc0f402d4c71 Mon Sep 17 00:00:00 2001 From: use-the-fork Date: Fri, 11 Oct 2024 18:53:48 -0400 Subject: [PATCH] fix(tests): update assertions for messages and standalone_question - Adjusted `assertDatabaseCount` in `DatabaseMemoryTest.php` to expect 4 messages instead of 2. - Modified `ChatRephraseAgentTest.php` to check for updated standalone question wording. --- docs/.vitepress/config.mjs | 38 +++++++++---------- tests/Agents/ChatRephraseAgentTest.php | 34 ++++++++--------- ...gent-a4f1718f3bd597aaa73aabb90ccb115b.json | 10 +++++ tests/Memory/DatabaseMemoryTest.php | 2 +- 4 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 tests/Fixtures/Saloon/Agents/ChatRephraseAgent-a4f1718f3bd597aaa73aabb90ccb115b.json diff --git a/docs/.vitepress/config.mjs b/docs/.vitepress/config.mjs index cfa7be8..e5ac1c5 100644 --- a/docs/.vitepress/config.mjs +++ b/docs/.vitepress/config.mjs @@ -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: [ @@ -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: [ diff --git a/tests/Agents/ChatRephraseAgentTest.php b/tests/Agents/ChatRephraseAgentTest.php index e23e33c..5041931 100644 --- a/tests/Agents/ChatRephraseAgentTest.php +++ b/tests/Agents/ChatRephraseAgentTest.php @@ -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([ @@ -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(); }); diff --git a/tests/Fixtures/Saloon/Agents/ChatRephraseAgent-a4f1718f3bd597aaa73aabb90ccb115b.json b/tests/Fixtures/Saloon/Agents/ChatRephraseAgent-a4f1718f3bd597aaa73aabb90ccb115b.json new file mode 100644 index 0000000..50e3c43 --- /dev/null +++ b/tests/Fixtures/Saloon/Agents/ChatRephraseAgent-a4f1718f3bd597aaa73aabb90ccb115b.json @@ -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" +} diff --git a/tests/Memory/DatabaseMemoryTest.php b/tests/Memory/DatabaseMemoryTest.php index e6b3eef..b5f67dc 100644 --- a/tests/Memory/DatabaseMemoryTest.php +++ b/tests/Memory/DatabaseMemoryTest.php @@ -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); });