Skip to content

Commit

Permalink
add original content
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jun 19, 2023
1 parent ecccde4 commit 79994a9
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 27 deletions.
Expand Up @@ -18,25 +18,26 @@ public function create(Project $project)
'mappings' => [
'optional.path.to.store_one',
'optional.path.to.store_two',
]
]
],
],
]);

request()->session()->flash('flash.banner', 'Created, you can sort the order using drag and drop');

return to_route('transformers.json_transformer.edit',
[
'project' => $project->id,
'transformer' => $transformer->id
'transformer' => $transformer->id,
]
);
}

public function edit(Project $project, Transformer $transformer)
{
request()->session()->flash('flash.banner', 'There is no edit for this');

return to_route('projects.show', ['project' => $project->id]);
return inertia('Transformers/JsonTransformer/Edit', [
'details' => config('larachain.transformers.'.$transformer->type->value),
'transformer' => $transformer,
]);
}

public function store(Project $project)
Expand All @@ -46,6 +47,17 @@ public function store(Project $project)

public function update(Project $project, Transformer $transformer)
{
// TODO: Implement update() method.
$validate = request()->validate([
'mappings' => ['nullable'],
]);

$meta_data = $transformer->meta_data;
$meta_data['mappings'] = data_get($validate, 'mappings', []);
$transformer->meta_data = $meta_data;
$transformer->save();

return to_route('projects.show', [
'project' => $project->id,
]);
}
}
15 changes: 15 additions & 0 deletions app/Models/DocumentChunk.php
Expand Up @@ -7,6 +7,8 @@
use Pgvector\Laravel\Vector;

/**
* @property string $original_content;
* @property string $content;
* @property int $token_count
* @property array $embedding
*/
Expand All @@ -24,4 +26,17 @@ public function document()
{
return $this->belongsTo(Document::class);
}

/**
* The "booted" method of the model.
*
* @return void
*/
protected static function booted()
{
static::saved(function ($document_chunk) {
$document_chunk->original_content = $document_chunk->getOriginal('content');
$document_chunk->saveQuietly();
});
}
}
3 changes: 2 additions & 1 deletion app/Models/Transformer.php
Expand Up @@ -11,6 +11,7 @@
* @property int $id;
* @property int $order;
* @property int $project_id;
* @property array $meta_data;
* @property TransformerEnum $type;
* @property Project $project;
*
Expand All @@ -29,7 +30,7 @@ class Transformer extends BaseTypeModel
protected $casts = [
'prompt_token' => 'encrypted:array',
'type' => TransformerEnum::class,
'meta_data' => "encrypted:array"
'meta_data' => 'encrypted:array',
];

public function project()
Expand Down
2 changes: 1 addition & 1 deletion app/Source/Types/FileUploadSource.php
Expand Up @@ -25,7 +25,7 @@ public function handle(): Document
],
[
'status' => StatusEnum::Complete,
'type' => SourceEnum::FileUploadSource
'type' => SourceEnum::FileUploadSource,
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Source/Types/ScrapeWebPage.php
Expand Up @@ -33,7 +33,7 @@ public function handle(): Document
[
'status' => StatusEnum::Complete,
'content' => $fileContents,
'type' => SourceEnum::ScrapeWebPage
'type' => SourceEnum::ScrapeWebPage,
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Source/Types/WebFile.php
Expand Up @@ -37,7 +37,7 @@ public function handle(): Document
],
[
'status' => StatusEnum::Complete,
'type' => SourceEnum::WebFile
'type' => SourceEnum::WebFile,
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion config/larachain.php
Expand Up @@ -110,7 +110,7 @@
],
'json_transformer' => [
'name' => 'JsonTransformer',
'description' => 'Will take Json Documents and make chunks',
'description' => 'Will take Json Documents and make document chunks. You can use mapping to grab just some keys and data',
'class' => 'App\\Transformer\\Types\\JsonTransformer',
'background' => 'bg-blue-500',
'icon' => 'Bars3CenterLeftIcon',
Expand Down
1 change: 1 addition & 0 deletions database/factories/DocumentChunkFactory.php
Expand Up @@ -22,6 +22,7 @@ public function definition(): array
return [
'guid' => fake()->uuid(),
'content' => fake()->sentence(10),
'original_content' => fake()->sentence(10),
'token_count' => fake()->randomDigitNotZero(),
'document_id' => Document::factory(),
];
Expand Down
8 changes: 4 additions & 4 deletions database/factories/TransformerFactory.php
Expand Up @@ -27,8 +27,8 @@ public function definition(): array
'mappings' => [
'optional.path.to.store_one',
'optional.path.to.store_two',
]
]
],
],
];
}

Expand All @@ -50,8 +50,8 @@ public function json()
'mappings' => [
'optional.path.to.store_one',
'optional.path.to.store_two',
]
]
],
],
];
});
}
Expand Down
Expand Up @@ -13,7 +13,7 @@
public function up(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->string("type")->default(SourceEnum::WebFile->value)->change();
$table->string('type')->default(SourceEnum::WebFile->value)->change();
});
}

Expand Down
Expand Up @@ -12,7 +12,7 @@
public function up(): void
{
Schema::table('transformers', function (Blueprint $table) {
$table->longText("meta_data")->nullable();
$table->longText('meta_data')->nullable();
});
}

Expand Down
@@ -0,0 +1,28 @@
<?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::table('document_chunks', function (Blueprint $table) {
$table->longText('original_content')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('document_chunks', function (Blueprint $table) {
//
});
}
};
80 changes: 80 additions & 0 deletions resources/js/Pages/Transformers/JsonTransformer/Edit.vue
@@ -0,0 +1,80 @@
<template>
<AppLayout title="transformer Web File">
<template #header>
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
Web Site Document
</h2>
<div>
<div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
<FormWrapper @submitted="submit">
<div>
<div class="max-w-7xl mx-auto sm:py-10 sm:px-6 lg:px-8">
<FormSection>
<template #title>
{{ details.title }}
</template>
<template #description>
{{ details.description }}
</template>

<template #form>
<ResourceForm
@removedMapping="updateMappings"
@addedMapping="updateMappings"
v-model="form"/>
</template>

<template #actions>
<PrimaryButton @click="submit">Save</PrimaryButton>
</template>

</FormSection>
</div>
</div>
</FormWrapper>
</div>
</div>
</template>
</AppLayout>
</template>

<script setup>
import AppLayout from "@/Layouts/AppLayout.vue";
import FormWrapper from "@/Components/FormWrapper.vue";
import FormSection from "@/Components/FormSection.vue";
import PrimaryButton from '@/Components/PrimaryButton.vue';
import { useForm } from "@inertiajs/vue3";
import {useToast} from "vue-toastification";
import ResourceForm from "./Partials/ResourceForm.vue";
const toast = useToast();
const props = defineProps({
transformer: Object,
details: Object
})
const updateMappings = (mappings) => {
form.mappings = mappings;
}
const form = useForm({
mappings: props.transformer.meta_data?.mappings ?? []
})
const submit = () => {
form.put(route("transformers.json_transformer.update", {
project: props.transformer.project_id,
transformer: props.transformer.id
}), {
preserveScroll: true,
onError: params => {
toast.error("Check validation")
}
});
}
</script>
<style scoped>
</style>

0 comments on commit 79994a9

Please sign in to comment.