HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
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
    {
        //
    }
};