Skip to content

Commit

Permalink
adding chat references
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 27, 2024
1 parent 3a8261d commit 66abf5c
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ memory_limit=-1
post_max_size = 100M
```

## Which Model????

Keep in mind the size of the model is not the only thing that matters. If you read over [https://ollama.com/library](https://ollama.com/library)
you will see some are better at chat, some at large context, some at code etc. LaraLamma can use multiple models for different jobs.

Looking in the `config/llmdriver.php` you can see the options in there.




## Road Map (still in motion)
Expand Down
1 change: 0 additions & 1 deletion app/Domains/Sources/WebSearch/Drivers/BaseSearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Domains\Sources\WebSearch\Drivers;

use App\Domains\Sources\WebSearch\Response\SearchResponseDto;
use PhpOffice\PhpSpreadsheet\Calculation\TextData\Search;

abstract class BaseSearchClient
{
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

public function chat_document_references(): HasMany
{
return $this->hasMany(ChatDocumentReference::class);
}
}
29 changes: 29 additions & 0 deletions app/Models/ChatDocumentReference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ChatDocumentReference extends Model
{
use HasFactory;

protected $guarded = [];

public function chat(): BelongsTo
{
return $this->belongsTo(Chat::class);
}

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

public function document_chunk(): BelongsTo
{
return $this->belongsTo(DocumentChunk::class);
}
}
1 change: 1 addition & 0 deletions config/llmdriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
//@see https://github.com/ollama/ollama/blob/main/docs/openai.md
'completion_model' => env('OLLAMA_COMPLETION_MODEL', 'llama3'),
'embedding_model' => env('OLLAMA_EMBEDDING_MODEL', 'mxbai-embed-large'),
'chat_output_model' => env('OLLAMA_COMPLETION_MODEL', 'llama3'), //this is good to use other systems for better repsonses to people in chat
],
],
],
Expand Down
29 changes: 29 additions & 0 deletions database/factories/ChatDocumentReferenceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Database\Factories;

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

/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ChatDocumentReference>
*/
class ChatDocumentReferenceFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'chat_id' => Chat::factory(),
'document_id' => Document::factory(),
'document_chunk_id' => DocumentChunk::factory(),
'reference' => fake()->text(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use App\Models\Chat;
use App\Models\Document;
use App\Models\DocumentChunk;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('chat_document_references', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Chat::class);
$table->foreignIdFor(Document::class);
$table->foreignIdFor(DocumentChunk::class);
$table->string('reference');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('chat_document_references');
}
};
23 changes: 23 additions & 0 deletions tests/Feature/Models/ChatDocumentReferenceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Feature\Models;

use App\Models\ChatDocumentReference;
use Tests\TestCase;

class ChatDocumentReferenceTest extends TestCase
{
/**
* A basic feature test example.
*/
public function test_factory(): void
{
$model = ChatDocumentReference::factory()->create();

$this->assertIsString($model->reference);
$this->assertNotNull($model->chat->id);
$this->assertNotNull($model->document->id);
$this->assertNotNull($model->document_chunk->id);
$this->assertNotNull($model->chat->chat_document_references()->first()->id);
}
}

0 comments on commit 66abf5c

Please sign in to comment.