File: /var/www/html/laravel/database/migrations/2024_08_20_084452_prompts_table_examples_table.php
<?php
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('prompts', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->text('prompt');
});
$summaryJson = file_get_contents(base_path().'/../src/common/json-data/summary.json');
$summaryJson = str_replace("\n","", $summaryJson);
$summaryJson = $this->cleanSpaces($summaryJson);
DB::statement("INSERT INTO prompts (prompt) VALUES ('Дайте JSON, который уже содержит некоторые заполненые поля и получите структурированный JSON
Не используй markdown.
Пример максимально заполненного JSON с описанием полей в значении:\n$summaryJson')");
Schema::table('notams', function (Blueprint $table) {
$table->integer('prompt_id')->default(1);
$table->string('example_ids')->nullable();
});
Schema::create('notam_examples', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->text('input');
$table->text('output');
});
$examples = file_get_contents(base_path().'/../src/common/json-data/fine-tuning.jsonl');
$examples = explode("\n", $examples);
$examples = array_map('json_decode', $examples);
foreach ($examples as $example) {
if (!$example) continue;
$input = json_encode($example->input);
$output = json_encode($example->output);
DB::statement("INSERT INTO notam_examples (input,output) VALUES ('{$this->cleanSpaces($input)}', '{$this->cleanSpaces($output)}')");
}
}
public function cleanSpaces($string)
{
return str_replace(['{ ', ' }', ' {', ', ', ' ]', '[ '], ['{', '}', '{', ',', ']', '['], $string);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};