Skip to content

Commit ac8fcc1

Browse files
authored
Merge pull request #2 from illegalstudio/database-prefix
Database prefix - Requests
2 parents 66334a8 + 99a52f4 commit ac8fcc1

29 files changed

+536
-92
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
.idea
1+
.idea
2+
build
3+
vendor
4+
composer.lock
5+
phpunit.xml
6+
.env
7+
.phpunit.result.cache
8+
.php-cs-fixer.cache

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Unreleased
2+
3+
# v0.1.3
4+
5+
**Release date**: 2023-04-30
6+
7+
- Added support for db prefix. **IMPORTANT**, if you come from a previous version, your setup is without prefix.
8+
Either rename all your table with the `ai-` prefix (or whatever you configure via the `.env` file) or setup an empty prefix
9+
in your `.env` file:
10+
11+
```dotenv
12+
AI_DB_PREFIX=
13+
```
14+
15+
- Added a new table `requests` to store all the requests made to the API. In the table are stored token usage - expect for image requests on the openai provider
16+
17+
18+
# v0.1.2
19+
20+
**Relase date**: 2023-04-02
21+
22+
Base version of the module, with basic functionality and support for Laravel 10

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"require": {
2424
"php": "^8.1",
2525
"guzzlehttp/guzzle": "^7.2",
26+
"illegal/laravel-utils": "^1.1",
2627
"laravel/framework": "^9.19|^10",
2728
"openai-php/client": "^0.3.5"
2829
},

config/laravel-ai.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

33
return [
4+
'db' => [
5+
'prefix' => env('AI_DB_PREFIX', 'ai_'),
6+
],
47
'openai' => [
58
'api_key' => env('AI_OPENAI_API_KEY', null),
69
'default_max_tokens' => env('AI_OPENAI_DEFAULT_MAX_TOKENS', 5),

database/migrations/2023_03_15_221528_create_models_table.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

3+
use Illegal\LaravelAI\Models\Model;
34
use Illuminate\Database\Migrations\Migration;
45
use Illuminate\Database\Schema\Blueprint;
56
use Illuminate\Support\Facades\Schema;
67

78
return new class extends Migration {
89
public function up(): void
910
{
10-
Schema::create('models', function (Blueprint $table) {
11+
Schema::create(Model::getTableName(), function (Blueprint $table) {
1112
$table->id();
1213
$table->boolean('is_active')->default(false);
1314
$table->string('provider');
@@ -19,6 +20,6 @@ public function up(): void
1920

2021
public function down(): void
2122
{
22-
Schema::dropIfExists('models');
23+
Schema::dropIfExists(Model::getTableName());
2324
}
2425
};
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Illegal\LaravelAI\Models\Chat;
34
use Illegal\LaravelAI\Models\Model;
45
use Illuminate\Database\Migrations\Migration;
56
use Illuminate\Database\Schema\Blueprint;
@@ -8,9 +9,9 @@
89
return new class extends Migration {
910
public function up(): void
1011
{
11-
Schema::create('chats', function (Blueprint $table) {
12+
Schema::create(Chat::getTableName(), function (Blueprint $table) {
1213
$table->id();
13-
$table->foreignIdFor(Model::class)->constrained();
14+
$table->foreignIdFor(Model::class)->constrained(Model::getTableName());
1415
$table->string('external_id')->nullable();
1516
$table->json('messages')->nullable();
1617
$table->timestamps();
@@ -19,6 +20,6 @@ public function up(): void
1920

2021
public function down(): void
2122
{
22-
Schema::dropIfExists('chats');
23+
Schema::dropIfExists(Chat::getTableName());
2324
}
2425
};
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Illegal\LaravelAI\Models\Completion;
34
use Illegal\LaravelAI\Models\Model;
45
use Illuminate\Database\Migrations\Migration;
56
use Illuminate\Database\Schema\Blueprint;
@@ -8,9 +9,9 @@
89
return new class extends Migration {
910
public function up(): void
1011
{
11-
Schema::create('completions', function (Blueprint $table) {
12+
Schema::create(Completion::getTableName(), function (Blueprint $table) {
1213
$table->id();
13-
$table->foreignIdFor(Model::class)->constrained();
14+
$table->foreignIdFor(Model::class)->constrained(Model::getTableName());
1415
$table->string('external_id')->nullable();
1516
$table->string('prompt');
1617
$table->string('answer');
@@ -20,6 +21,6 @@ public function up(): void
2021

2122
public function down(): void
2223
{
23-
Schema::dropIfExists('completions');
24+
Schema::dropIfExists(Completion::getTableName());
2425
}
2526
};

database/migrations/2023_03_20_232708_create_images_table.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Illegal\LaravelAI\Models\Image;
34
use Illegal\LaravelAI\Models\Model;
45
use Illuminate\Database\Migrations\Migration;
56
use Illuminate\Database\Schema\Blueprint;
@@ -8,9 +9,9 @@
89
return new class extends Migration {
910
public function up(): void
1011
{
11-
Schema::create('images', function (Blueprint $table) {
12+
Schema::create(Image::getTableName(), function (Blueprint $table) {
1213
$table->id();
13-
$table->foreignIdFor(Model::class)->nullable()->constrained();
14+
$table->foreignIdFor(Model::class)->nullable()->constrained(Model::getTableName());
1415
$table->string('external_id')->nullable();
1516
$table->string('prompt');
1617
$table->integer('width');
@@ -22,6 +23,6 @@ public function up(): void
2223

2324
public function down(): void
2425
{
25-
Schema::dropIfExists('images');
26+
Schema::dropIfExists(Image::getTableName());
2627
}
2728
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use Illegal\LaravelAI\Models\Completion;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
return new class extends Migration {
9+
public function up(): void
10+
{
11+
Schema::table(Completion::getTableName(), function (Blueprint $table) {
12+
$table->text('prompt')->change();
13+
$table->text('answer')->change();
14+
});
15+
}
16+
17+
public function down(): void
18+
{
19+
Schema::table(Completion::getTableName(), function (Blueprint $table) {
20+
$table->string('prompt')->change();
21+
$table->string('answer')->change();
22+
});
23+
}
24+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illegal\LaravelAI\Models\ApiRequest;
4+
use Illuminate\Database\Migrations\Migration;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
return new class extends Migration {
9+
public function up(): void
10+
{
11+
Schema::create(ApiRequest::getTableName(), function (Blueprint $table) {
12+
$table->id();
13+
$table->string('external_id')->nullable();
14+
$table->integer('prompt_tokens')->default(0);
15+
$table->integer('completion_tokens')->default(0);
16+
$table->integer('total_tokens')->default(0);
17+
$table->nullableMorphs('requestable');
18+
19+
$table->timestamps();
20+
});
21+
}
22+
23+
public function down(): void
24+
{
25+
Schema::dropIfExists(ApiRequest::getTableName());
26+
}
27+
};

0 commit comments

Comments
 (0)