Skip to content

Commit

Permalink
add document chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed May 8, 2023
1 parent 5967f14 commit d54c9e5
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 35 deletions.
5 changes: 2 additions & 3 deletions app/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use App\Ingress\StatusEnum;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Pgvector\Laravel\Vector;

/**
Expand Down Expand Up @@ -49,7 +47,8 @@ public function project()
);
}

public function document_chunks() {
public function document_chunks()
{
return $this->hasMany(DocumentChunk::class);
}
}
5 changes: 2 additions & 3 deletions app/Models/DocumentChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class DocumentChunk extends Model

protected $guarded = [];

public function document() {
public function document()
{
return $this->belongsTo(Document::class);
}


}
7 changes: 1 addition & 6 deletions app/Transformers/BaseTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

namespace App\Transformers;

use App\LLMModels\OpenAi\EmbeddingsResponseDto;
use App\Models\Document;
use Facades\App\LLMModels\OpenAi\ClientWrapper;

abstract class BaseTransformer
{

public function __construct(public Document $document)
{
}


abstract public function handle() : Document;

abstract public function handle(): Document;
}
3 changes: 0 additions & 3 deletions app/Transformers/Types/PdfTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

namespace App\Transformers\Types;

use App\LLMModels\OpenAi\EmbeddingsResponseDto;
use App\Models\Document;
use App\Transformers\BaseTransformer;
use Facades\App\LLMModels\OpenAi\ClientWrapper;

class PdfTransformer extends BaseTransformer
{

public function handle(): Document
{
//find the source
Expand Down
2 changes: 0 additions & 2 deletions database/factories/DocumentChunkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Database\Factories;

use App\Ingress\StatusEnum;
use App\Models\Document;
use App\Models\Source;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function up(): void
Schema::create('document_chunks', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Document::class);
$table->string("guid"); //page number or other
$table->longText("content")->nullable();
$table->string('guid'); //page number or other
$table->longText('content')->nullable();
$table->vector('embedding', 1536)->nullable();
$table->timestamps();
});
Expand Down
4 changes: 0 additions & 4 deletions tests/Feature/Models/DocumentChunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
namespace Tests\Feature\Models;

use App\Models\DocumentChunk;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class DocumentChunkTest extends TestCase
{


public function test_dc_factory()
{
$model = DocumentChunk::factory()->create();
Expand Down
20 changes: 8 additions & 12 deletions tests/Feature/PdfTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,32 @@
use App\Models\Document;
use App\Models\Source;
use App\Transformers\Types\PdfTransformer;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class PdfTransformerTest extends TestCase
{
public function test_gets_data_from_pdf()
{

public function test_gets_data_from_pdf() {

$this->markTestSkipped("Need to do document chunks first");
$this->markTestSkipped('Need to do document chunks first');

$source = Source::factory()
->webFileMetaData()
->create();

Storage::disk("projects")->copy(
base_path("tests/fixtures/example.pdf"),
sprintf(storage_path("app/projects/%d/sources/%d/example.pdf",
Storage::disk('projects')->copy(
base_path('tests/fixtures/example.pdf'),
sprintf(storage_path('app/projects/%d/sources/%d/example.pdf',
$source->project_id, $source->id))
);

$document = Document::factory()->create([
"source_id" => $source->id,
"guid" => "example.pdf"
'source_id' => $source->id,
'guid' => 'example.pdf',
]);

$trasformer = new PdfTransformer($document);



}
}

0 comments on commit d54c9e5

Please sign in to comment.