Skip to content

Commit

Permalink
add fake brave token
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed May 1, 2024
1 parent a3f87bc commit 28b840e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 45 deletions.
10 changes: 4 additions & 6 deletions app/Http/Controllers/SearchSourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
use App\Jobs\KickOffWebSearchCreationJob;
use App\Models\Collection;
use App\Models\Document;
use Illuminate\Http\Request;

class SearchSourceController extends Controller
{


public function store(Collection $collection) {
public function store(Collection $collection)
{
$validated = request()->validate([
'content' => 'required|string',
'name' => 'required|string',
Expand All @@ -30,9 +28,9 @@ public function store(Collection $collection) {
]);

KickOffWebSearchCreationJob::dispatch($document);

CollectionStatusEvent::dispatch($document->collection, CollectionStatusEnum::PROCESSING);

request()->session()->flash('flash.banner', 'Starting initial Search pages will show shortly');

return back();
Expand Down
6 changes: 2 additions & 4 deletions app/Jobs/GetWebContentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class GetWebContentJob implements ShouldQueue
public function __construct(
public Document $document,
public WebResponseDto $webResponseDto
)
{
) {
//
}

Expand All @@ -33,10 +32,9 @@ public function handle(): void
{
if ($this->batch()->cancelled()) {
// Determine if the batch has been cancelled...

return;
}


}
}
10 changes: 4 additions & 6 deletions app/Jobs/KickOffWebSearchCreationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Bus;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Search;

class KickOffWebSearchCreationJob implements ShouldQueue
{
Expand Down Expand Up @@ -43,29 +42,28 @@ public function handle(): void
### END USER QUERY
PROMPT;
PROMPT;

$response = LlmDriverFacade::driver($this->document->getDriver())
->completion($prompt);
->completion($prompt);

$search = $response->content;

$results = WebSearchFacade::search($search, [

Check failure on line 52 in app/Jobs/KickOffWebSearchCreationJob.php

View workflow job for this annotation

GitHub Actions / ci (8.2)

Call to an undefined static method App\Domains\Sources\WebSearch\WebSearchFacade::search().
'count' => 5
'count' => 5,
]);

$jobs = [];

foreach ($results->getWeb() as $web) {
$jobs[] = new GetWebContentJob($this->document, $web);
}

Bus::batch($jobs)
->name("Getting Web Content - {$this->document->id}")
->onQueue(LlmDriverFacade::driver($this->document->getDriver())->onQueue())
->allowFailures()
->dispatch();


}
}
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="PULSE_ENABLED" value="false"/>
<env name="BRAVE_API_TOKEN" value="FOOBAR"/>
<!-- this is a fake token! -->
<env name="OPENAI_API_KEY" value="sk-m8ox9NVgboSLRCr5VA5RT3BXbkFJzP1QGUedbQxGmmuAQWRT"/>
<env name="QUEUE_CONNECTION" value="sync"/>
Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/Http/Controllers/SearchSourceControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use App\Jobs\KickOffWebSearchCreationJob;
use App\Models\Collection;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;

Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/Jobs/GetWebContentJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Tests\Feature\Jobs;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class GetWebContentJobTest extends TestCase
Expand Down
44 changes: 19 additions & 25 deletions tests/Feature/Jobs/KickOffWebSearchCreationJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
use App\Domains\Sources\WebSearch\Response\SearchResponseDto;
use App\Domains\Sources\WebSearch\Response\WebResponseDto;
use App\Domains\Sources\WebSearch\WebSearchFacade;
use App\Jobs\GetWebContentJob;
use App\Jobs\KickOffWebSearchCreationJob;
use App\Models\Document;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Bus;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
use LlmLaraHub\LlmDriver\Responses\CompletionResponse;
Expand All @@ -28,37 +25,34 @@ public function test_builds_batch(): void
Bus::fake();

LlmDriverFacade::shouldReceive('driver->completion')
->once()->andReturn(CompletionResponse::from([
'content' => "updated query"
->once()->andReturn(CompletionResponse::from([
'content' => 'updated query',
]));

LlmDriverFacade::shouldReceive('driver->onQueue')
->once()->andReturn("ollam");


->once()->andReturn('ollam');

WebSearchFacade::shouldReceive('search')->with('updated query', [
'count' => 5
'count' => 5,
])->once()
->andReturn(
SearchResponseDto::from([
'web' => [
WebResponseDto::from([
'title' => 'title',
'description' => 'description',
'url' => 'url',
'images' => [],
'videos' => [],
'meta_data' => []
])
],
'videos' => []
])
);
->andReturn(
SearchResponseDto::from([
'web' => [
WebResponseDto::from([
'title' => 'title',
'description' => 'description',
'url' => 'url',
'images' => [],
'videos' => [],
'meta_data' => [],
]),
],
'videos' => [],
])
);

$job = new KickOffWebSearchCreationJob($document);


$job->handle();

Bus::assertBatchCount(1);
Expand Down

0 comments on commit 28b840e

Please sign in to comment.