Skip to content

Commit

Permalink
Ok the controller and orchestrate v2 chat is working but that is the …
Browse files Browse the repository at this point in the history
…easy part now for the dynamic tools
  • Loading branch information
alnutile committed Aug 4, 2024
1 parent 12c9e31 commit 96d8e5c
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Modules/LlmDriver/app/OllamaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function chat(array $messages): CompletionResponse
}

put_fixture('ollama_chat_response.json', $response->json());

return OllamaChatCompletionResponse::from($response->json());
}

Expand Down Expand Up @@ -151,7 +152,7 @@ public function completionPool(array $prompts, int $temperature = 0): array

$payload = $this->modifyPayload($payload, true);

Log::info('Ollama Request index ' . $index);
Log::info('Ollama Request index '.$index);

$pool->withHeaders([
'content-type' => 'application/json',
Expand Down Expand Up @@ -282,7 +283,6 @@ public function remapMessages(array $messages): array
->toArray();
})->toArray();


return $messages;
}
}
4 changes: 2 additions & 2 deletions Modules/LlmDriver/tests/Feature/LlmDriverClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public function test_get_functions()
ToolTypes::Chat
)->getFunctions();

$this->assertCount(3, $function);
$this->assertCount(0, $function);
}

public function test_get_functions_for_ui()
{
$functions = LlmDriverFacade::getFunctionsForUi();

$this->assertCount(9, $functions);
$this->assertCount(8, $functions);

}
}
4 changes: 1 addition & 3 deletions app/Domains/Orchestration/OrchestrateVersionTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ protected function chatWithTools(Chat $chat, Message $message, CompletionRespons

protected function justChat(Chat $chat, Message $message, ToolTypes $toolType): void
{
Log::info('[LaraChain] - Just Chatting ' . $chat->getDriver());
Log::info('[LaraChain] - Just Chatting '.$chat->getDriver());

$messages = $chat->getChatResponse();

put_fixture('orchestrate_messages_first_send.json', $messages);

$response = LlmDriverFacade::driver($chat->getDriver())
->setToolType($toolType)
->chat($messages);
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/Http/Controllers/ChatControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Models\Message;
use App\Models\User;
use Facades\App\Domains\Agents\VerifyResponseAgent;
use Facades\LlmLaraHub\LlmDriver\Orchestrate;
use Facades\App\Domains\Orchestration\OrchestrateVersionTwo;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
use LlmLaraHub\LlmDriver\Responses\CompletionResponse;
use Tests\TestCase;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function test_will_verify_on_completion(): void
'user_id' => $user->id,
]);

Orchestrate::shouldReceive('handle')->never();
OrchestrateVersionTwo::shouldReceive('handle')->never();

$firstResponse = CompletionResponse::from([
'content' => 'test',
Expand Down Expand Up @@ -89,7 +89,7 @@ public function test_adds_meta_data_and_date_range()
'user_id' => $user->id,
]);

Orchestrate::shouldReceive('handle')->once()->andReturn('Yo');
OrchestrateVersionTwo::shouldReceive('handle')->once();

$this->assertDatabaseCount('messages', 0);
$this->actingAs($user)->post(route('chats.messages.create', [
Expand Down Expand Up @@ -117,7 +117,7 @@ public function test_adds_references_collection_id()
'user_id' => $user->id,
]);

Orchestrate::shouldReceive('handle')->once()->andReturn('Yo');
OrchestrateVersionTwo::shouldReceive('handle')->once();
$this->actingAs($user)->post(route('chats.messages.create', [
'chat' => $chat->id,
]),
Expand All @@ -142,7 +142,7 @@ public function test_a_function_based_chat()
'user_id' => $user->id,
]);

Orchestrate::shouldReceive('handle')->once()->andReturn('Yo');
OrchestrateVersionTwo::shouldReceive('handle')->once()->andReturn('Yo');

$this->assertDatabaseCount('messages', 0);
$this->actingAs($user)->post(route('chats.messages.create', [
Expand Down Expand Up @@ -179,7 +179,7 @@ public function test_kick_off_chat_makes_system()

public function test_standard_checker()
{
Orchestrate::shouldReceive('handle')->once()->andReturn('Yo');
OrchestrateVersionTwo::shouldReceive('handle')->once()->andReturn('Yo');

$user = User::factory()->create();
$collection = Collection::factory()->create();
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Http/Controllers/GoogleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class GoogleControllerTest extends TestCase
*/
public function test_saves_meta_data(): void
{
$this->markTestSkipped('@TODO need to come back to getting Google Auth working');
$user = User::factory()->create([
'meta_data' => [],
]);
Expand Down
12 changes: 5 additions & 7 deletions tests/Feature/Models/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Models\Message;
use App\Models\Report;
use App\Models\User;
use Facades\LlmLaraHub\LlmDriver\Orchestrate;
use Facades\App\Domains\Orchestration\OrchestrateVersionTwo;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
Expand Down Expand Up @@ -77,15 +77,13 @@ public function test_run(): void
'user_id' => $user->id,
]);

Orchestrate::shouldReceive('handle')->never();
OrchestrateVersionTwo::shouldReceive('handle')->once();

$firstResponse = CompletionResponse::from([
'content' => 'test',
'stop_reason' => 'stop',
]);

LlmDriverFacade::shouldReceive('driver->hasFunctions')->once()->andReturn(false);

$message = Message::factory()->user()->create([
'tool' => 'completion',
'meta_data' => MetaDataDto::from([]),
Expand All @@ -106,13 +104,13 @@ public function test_rerun(): void
'user_id' => $user->id,
]);

Orchestrate::shouldReceive('handle')->never();
OrchestrateVersionTwo::shouldReceive('handle')->once();

$firstResponse = CompletionResponse::from([
'content' => 'test',
]);

LlmDriverFacade::shouldReceive('driver->chat')->once()->andReturn($firstResponse);
LlmDriverFacade::shouldReceive('driver->chat')->never();

$message = Message::factory()->user()->create([
'chat_id' => $chat->id,
Expand All @@ -130,6 +128,6 @@ public function test_rerun(): void

$messageAssistant->reRun();

$this->assertDatabaseCount('messages', 2);
$this->assertDatabaseCount('messages', 1);
}
}
4 changes: 2 additions & 2 deletions tests/Feature/OrchestrateVersionTwoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Models\Message;
use Illuminate\Support\Facades\Bus;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
use LlmLaraHub\LlmDriver\Responses\OllamaCompletionResponse;
use LlmLaraHub\LlmDriver\Responses\OllamaChatCompletionResponse;
use Tests\TestCase;

class OrchestrateVersionTwoTest extends TestCase
Expand All @@ -22,7 +22,7 @@ public function test_batches(): void
$data = get_fixture('ollama_response_tools.json');

LlmDriverFacade::shouldReceive('driver->setToolType->chat')->once()->andReturn(
OllamaCompletionResponse::from($data)
OllamaChatCompletionResponse::from($data)
);

$prompt = <<<'PROMPT'
Expand Down
31 changes: 28 additions & 3 deletions tests/fixtures/claude_messages_after_remap.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
[
{
"role": "user",
"content": "using the follow requirements list what are some solutions we have in this collection.\nWhen you find them just share a 1 liner to explain what they are about and another as to why you chose it\n\n---- requirements below ---\n# Request for Proposal: Website Enhancement and API Integration\n## 1. Introduction\nOur company, TechInnovate Solutions, is seeking proposals from qualified web development\nagencies or freelance developers to enhance our existing website and resolve critical issues\nwith our API and frontend components. This project aims to improve our website's\nfunctionality, performance, and user experience.\n## 2. Company Background\nTechInnovate Solutions is a leading provider of cloud-based software solutions for small to\nmedium-sized businesses. Founded in 2015, we have grown to serve over 10,000 customers\nacross North America. Our flagship product, CloudManage Pro, helps businesses streamline\ntheir operations, manage customer relationships, and optimize their supply chain processes.\n## 3. Project Overview\nWe are looking to address two main issues with our current website:\n1. API Integration Problem: Our website's backend, built with Laravel, is experiencing issues\nwith API calls, affecting data retrieval and submission processes.\n2. Frontend Banner Quality: The VueJS-powered banner on our homepage is displaying low-\nquality images, impacting the overall user experience and brand perception.\n## 4. Scope of Work\n### 4.1 API Issue Resolution\n- Diagnose the current API integration problems\n- Implement necessary fixes to ensure smooth data flow between frontend and backend\n- Optimize API calls for improved performance\n- Ensure proper error handling and logging\n- Update API documentation as needed\n### 4.2 VueJS Banner Enhancement\n- Investigate the cause of low-quality images in the banner\n- Implement image optimization techniques\n- Ensure responsive design across various devices and screen sizes\n- Improve loading times for banner images\n- Implement lazy loading if appropriate\n### 4.3 General Improvements\n- Conduct a brief audit of the existing codebase\n- Suggest and implement any critical optimizations\n- Ensure cross-browser compatibility\n- Improve overall website performance\n## 5. Technical Requirements\n### 5.1 Backend\n- Laravel framework (version 8.0 or higher)\n- PHP 7.4 or higher\n- MySQL database\n- RESTful API architecture\n### 5.2 Frontend\n- VueJS framework (version 3.0 or higher)\n- HTML5, CSS3, JavaScript\n- Responsive design principles\n- Modern browser compatibility (Chrome, Firefox, Safari, Edge)\n## 6. Deliverables\n1. Fully functional API with resolved integration issues\n2. Optimized VueJS banner with high-quality images\n3. Updated codebase with implemented improvements\n4. Comprehensive documentation of changes and optimizations\n5. Knowledge transfer session with our in-house development team\n## 7. Timeline\nWe anticipate this project to be completed within 2-3 weeks from the start date. Here's a\nproposed timeline:\n- Week 1: API diagnosis and initial fixes\n- Week 2: VueJS banner optimization and general improvements\n- Week 3: Final testing, documentation, and knowledge transfer\n## 8. Budget\nWhile we value quality work, we also have budget constraints. We are looking for the most\ncost-effective solution that meets our requirements. Please provide a detailed breakdown of\nyour costs in your proposal.\n## 9. Proposal Requirements\nYour proposal should include:\n1. Company\/Individual overview and relevant experience\n2. Detailed approach to solving our issues\n3. Proposed timeline\n4. Cost breakdown\n5. Team structure (if applicable)\n6. At least two references from similar projects\n## 10. Evaluation Criteria\nProposals will be evaluated based on the following criteria:\n1. Technical expertise (40%)\n2. Proposed approach and methodology (25%)\n3. Cost effectiveness (20%)\n4. Timeline and ability to meet deadlines (10%)\n5. References and past performance (5%)\n## 11. Submission Guidelines\nPlease submit your proposal in PDF format to [email protected] by [Insert Date].\nThe subject line should read \"Proposal - Website Enhancement Project\".\n## 12. Contact Information\nFor any questions or clarifications regarding this RFP, please contact:\nJohn Doe\nProject Manager, TechInnovate Solutions\nEmail: [email protected]\nPhone: (555) 123-4567\nWe look forward to reviewing your proposals and potentially working with you to enhance our\nwebsite and improve our user experience."
"content": "test1"
},
{
"role": "assistant",
"content": "Based on the requirements and the solutions presented in our conversation, here are some relevant solutions from our collection:\n\n1. Experienced Laravel developer:\n One-liner: Developer with extensive Laravel experience, including 10 years as a lead contractor at Pfizer.\n Why chosen: Directly addresses the technical expertise requirement for Laravel backend development.\n\n2. Full-stack development capability:\n One-liner: Comprehensive development skills covering both backend (API) and frontend (VueJS) issues.\n Why chosen: Aligns with the project's need for both API resolution and frontend banner enhancement.\n\n3. Build-measure-learn philosophy:\n One-liner: Iterative development approach focusing on continuous improvement and optimization.\n Why chosen: Fits the project's timeline and scope, allowing for ongoing refinement of both API and frontend components.\n\n4. Filament for Laravel:\n One-liner: Powerful admin panel and application framework for Laravel.\n Why chosen: Can address API integration issues and provide an easy-to-use interface for managing backend operations.\n\n5. Inertia and Vue for the frontend:\n One-liner: Approach combining Inertia and Vue for seamless frontend development.\n Why chosen: Aligns with the VueJS requirements and can help resolve frontend banner quality issues.\n\n6. Agile development approach:\n One-liner: Iterative development with frequent feedback and adjustments.\n Why chosen: Matches the need for flexibility and rapid development within the tight project timeline.\n\n7. Performance optimization techniques:\n One-liner: Methods to enhance website speed and responsiveness.\n Why chosen: Directly addresses the requirement for improving loading times and overall website performance."
"content": "test2"
},
{
"role": "user",
"content": "can you tldr this thread for me"
"content": "Using the surrounding context to continue this response thread"
},
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "<thinking>test3<\/thinking>"
},
{
"type": "tool_use",
"id": "test_id",
"name": "test",
"input": []
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "test_id",
"content": "test3"
}
]
}
]
Loading

0 comments on commit 96d8e5c

Please sign in to comment.