Skip to content

Commit

Permalink
see if this passes on ci
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 14, 2024
1 parent 1700029 commit 9780677
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Modules/LlmDriver/app/Functions/SearchAndSummarize.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LlmLaraHub\LlmDriver\Functions;

use App\Models\Chat;
use LlmLaraHub\LlmDriver\HasDrivers;
use LlmLaraHub\LlmDriver\Responses\FunctionResponse;

Expand All @@ -19,6 +18,7 @@ public function handle(
{
/**
* @TODO
*
* @see https://github.com/orgs/LlmLaraHub/projects/1/views/1?pane=issue&itemId=59671259
*/
return FunctionResponse::from(
Expand Down
2 changes: 1 addition & 1 deletion Modules/LlmDriver/app/Functions/SummarizeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function handle(

/**
* @TODO
* We assume chat model
* We assume chat model
*/
$model->addInput(
message: $results->content,
Expand Down
6 changes: 3 additions & 3 deletions Modules/LlmDriver/app/HasDrivers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public function getDriver(): string;

public function getEmbeddingDriver(): string;

public function getSummary() : string;
public function getSummary(): string;

public function getId() : int;
public function getId(): int;

public function getType() : string;
public function getType(): string;
}
9 changes: 5 additions & 4 deletions Modules/TagFunction/app/Contracts/TaggableContract.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
<?php

namespace LlmLaraHub\TagFunction\Contracts;

use Illuminate\Database\Eloquent\Relations\MorphToMany;

interface TaggableContract
{
public function tags() : MorphToMany;
public function addTag(string $tag) : void;
}
public function tags(): MorphToMany;

public function addTag(string $tag): void;
}
13 changes: 7 additions & 6 deletions Modules/TagFunction/app/Functions/TaggingFunction.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
<?php

namespace LlmLaraHub\TagFunction\Functions;

use Illuminate\Support\Facades\Log;
use LlmLaraHub\LlmDriver\Functions\FunctionCallDto;
use LlmLaraHub\LlmDriver\Functions\FunctionContract;
Expand All @@ -14,7 +15,7 @@
class TaggingFunction extends FunctionContract
{
protected string $name = 'tagging_function';

protected string $description = 'Used to tag a user input with a tag or tags.';

public function handle(
Expand All @@ -26,7 +27,7 @@ public function handle(

$summary = $model->getSummary();

$tags = data_get($functionCallDto->arguments, 'tags', "no limit");
$tags = data_get($functionCallDto->arguments, 'tags', 'no limit');

$prompt = <<<EOD
This content needs tagging. Please return a list of tags that would apply to this content as JSON array like: ["tag1", "tag2", "tag3"]
Expand All @@ -38,7 +39,7 @@ public function handle(
$summary
### END CONTENT
EOD;
$messagesArray = []; //just to reset it
$messagesArray = []; //just to reset it
$messagesArray[] = MessageInDto::from([
'content' => $prompt,
'role' => 'user',
Expand All @@ -48,7 +49,7 @@ public function handle(

$tags = json_decode($results->content, true);

foreach($tags as $tag) {
foreach ($tags as $tag) {
$model->addTag($tag);
}

Expand All @@ -73,4 +74,4 @@ protected function getProperties(): array
),
];
}
}
}
13 changes: 5 additions & 8 deletions Modules/TagFunction/app/Helpers/Taggable.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<?php
<?php

namespace LlmLaraHub\TagFunction\Helpers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use LlmLaraHub\TagFunction\Models\Tag;

trait Taggable {

public function tags() : MorphToMany
trait Taggable
{
public function tags(): MorphToMany
{
return $this->morphToMany(Tag::class, 'taggable');
}

public function addTag(string $tag) : void
public function addTag(string $tag): void
{
$tag = Tag::firstOrCreate(['name' => $tag]);
$this->tags()->attach($tag->id);
}
}

5 changes: 1 addition & 4 deletions Modules/TagFunction/app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
use App\Models\Collection;
use App\Models\Document;
use App\Models\DocumentChunk;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use LlmLaraHub\TagFunction\Database\Factories\TagFactory;

Expand All @@ -27,7 +26,6 @@ public function document_chunks(): MorphToMany
return $this->morphedByMany(DocumentChunk::class, 'taggable');
}


public function documents(): MorphToMany
{
return $this->morphedByMany(Document::class, 'taggable');
Expand All @@ -37,5 +35,4 @@ public function collections(): MorphToMany
{
return $this->morphedByMany(Collection::class, 'taggable');
}

}
4 changes: 1 addition & 3 deletions Modules/TagFunction/database/factories/TagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LlmLaraHub\TagFunction\Database\Factories;

use App\Models\DocumentChunk;
use Illuminate\Database\Eloquent\Factories\Factory;

class TagFactory extends Factory
Expand All @@ -22,7 +21,7 @@ public function definition(): array
];
}

/**
/**
* Associate the tag with a taggable model.
*/
public function taggable($modelType, $modelId)
Expand All @@ -35,4 +34,3 @@ public function taggable($modelType, $modelId)
});
}
}

8 changes: 4 additions & 4 deletions Modules/TagFunction/tests/Feature/TagFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class TagFunctionTest extends TestCase
*/
public function test_talks_to_llm(): void
{
$tags = get_fixture("taggings_results_from_llm.json");
$tags = get_fixture('taggings_results_from_llm.json');
LlmDriverFacade::shouldReceive('driver->chat')->once()->andReturn(
CompletionResponse::from([
'content' => $tags,
])
);
$content = <<<EOT
$content = <<<'EOT'
61Accelerate: State of DevOps 2019 | How Do We Improve Productivity?
We wondered if the amount of juggling work would be
significantly different among our highest and lowest
Expand Down Expand Up @@ -76,8 +76,8 @@ public function test_talks_to_llm(): void
[],
$documentChunk,
FunctionCallDto::from([
"function_name" => "tagging_function",
"arguments" => "[]"
'function_name' => 'tagging_function',
'arguments' => '[]',
])
);

Expand Down
14 changes: 7 additions & 7 deletions Modules/TagFunction/tests/Feature/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
namespace LlmLaraHub\TagFunction\tests\Feature;

use App\Models\Document;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use LlmLaraHub\TagFunction\Models\Tag;
use Tests\TestCase;

class TagTest extends TestCase
{
Expand All @@ -16,7 +14,7 @@ class TagTest extends TestCase
public function test_tag_model(): void
{
$document = Document::factory()
->has(Tag::factory(), 'tags')->create();
->has(Tag::factory(), 'tags')->create();

$this->assertNotEmpty($document->tags);

Expand All @@ -28,7 +26,8 @@ public function test_tag_model(): void
);
}

public function test_add_tag_new() {
public function test_add_tag_new()
{
$document = Document::factory()->create();
$tag = Tag::factory()->create();

Expand All @@ -40,11 +39,12 @@ public function test_add_tag_new() {

}

public function test_add_tag_existing() {
public function test_add_tag_existing()
{
$document = Document::factory()->create();

$this->assertDatabaseCount('tags', 0);
$document->addTag("foobar");
$document->addTag('foobar');

$this->assertNotEmpty($document->tags);
$this->assertDatabaseCount('tags', 1);
Expand Down
1 change: 0 additions & 1 deletion app/Models/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function getDriver(): string
return $this->chatable->getDriver();
}


public function getSummary(): string
{
return $this->chatable->description;
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Illuminate\Database\Eloquent\Relations\MorphMany;
use LlmLaraHub\LlmDriver\DriversEnum;
use LlmLaraHub\LlmDriver\HasDrivers;
use LlmLaraHub\TagFunction\Helpers\Taggable;
use LlmLaraHub\TagFunction\Contracts\TaggableContract;
use LlmLaraHub\TagFunction\Helpers\Taggable;

/**
* Class Project
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use LlmLaraHub\LlmDriver\HasDrivers;
use LlmLaraHub\TagFunction\Helpers\Taggable;
use LlmLaraHub\TagFunction\Contracts\TaggableContract;
use LlmLaraHub\TagFunction\Helpers\Taggable;

/**
* Class Document
Expand Down
3 changes: 1 addition & 2 deletions app/Models/DocumentChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use LlmLaraHub\LlmDriver\HasDrivers;
use LlmLaraHub\TagFunction\Helpers\Taggable;
use LlmLaraHub\TagFunction\Contracts\TaggableContract;
use LlmLaraHub\TagFunction\Helpers\Taggable;
use Pgvector\Laravel\Vector;

/**
Expand Down Expand Up @@ -79,5 +79,4 @@ public function getSummary(): string
{
return $this->summary;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function test_reindex(): void
]);
Document::factory()
->has(DocumentChunk::factory(), 'document_chunks')->create([
'collection_id' => $collection->id,
]);
'collection_id' => $collection->id,
]);
/**
* @TODO Policy in place by now
*/
Expand Down

0 comments on commit 9780677

Please sign in to comment.