Skip to content

Commit

Permalink
source now working on the previous missing results
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jul 11, 2024
1 parent 44b2a7f commit 0e702a0
Show file tree
Hide file tree
Showing 20 changed files with 359 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Modules/LlmDriver/app/Functions/SearchAndSummarize.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function handle(
'collection_id' => $message->getChat()->getChatable()?->id,
]);

$this->saveDocumentReference($message, $documentChunkResults);
$this->saveDocumentReference($AssistantMessage, $documentChunkResults);

notify_ui_complete($message->getChat());

Expand Down
1 change: 1 addition & 0 deletions Modules/LlmDriver/app/Orchestrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function handle(
Log::info('[LaraChain] Orchestration Has Functions', $functions);

foreach ($functions as $function) {

$functionName = data_get($function, 'name', null);

if (is_null($functionName)) {
Expand Down
1 change: 0 additions & 1 deletion Modules/TagFunction/app/TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ public function handle(Document $document): void
$document->addTag($tag);
});

notify_collection_ui($document->collection, CollectionStatusEnum::PROCESSING, 'Tags added');
}
}
1 change: 1 addition & 0 deletions app/Domains/Documents/StatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ enum StatusEnum: string
case Complete = 'complete';
case Cancelled = 'Cancelled';
case Failed = 'failed';
case SummaryComplete = 'summary_complete';
}
13 changes: 13 additions & 0 deletions app/Http/Controllers/DeleteDocumentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Collection;
use App\Models\Document;
use Illuminate\Support\Facades\Log;

Expand Down Expand Up @@ -29,4 +30,16 @@ public function delete()

return back();
}

public function deleteAll(Collection $collection) {

foreach($collection->documents as $document) {
$document->document_chunks()->delete();
$document->tags()->delete();
$document->delete();
}

request()->session()->flash('flash.banner', 'Deleted all Documents');
return back();
}
}
34 changes: 34 additions & 0 deletions app/Http/Controllers/DocumentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\DocumentResource;
use App\Http\Resources\DocumentResourceWithPaginate;
use App\Models\Collection;
use Illuminate\Http\Request;

class DocumentController extends Controller
{
public function index(Collection $collection) {

$filter = request()->get('filter');

if ($filter) {
$documents = $collection->documents()
->where('status', '=', $filter)->paginate(100);
} else {
$documents = $collection->documents()->paginate(100);
}

return response()->json([
'documents' => new DocumentResourceWithPaginate($documents),
]);
}

public function status(Collection $collection) {

return response()->json([
'documents' => DocumentResource::collection($collection->documents),
]);
}
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/ReindexCollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use App\Domains\Collections\CollectionStatusEnum;
use App\Domains\Documents\StatusEnum;
use App\Events\CollectionStatusEvent;
use App\Jobs\DocumentProcessingCompleteJob;
use App\Jobs\SummarizeDataJob;
use App\Jobs\SummarizeDocumentJob;
use App\Jobs\VectorlizeDataJob;
use App\Models\Collection;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;
use LlmLaraHub\TagFunction\Jobs\TagDocumentJob;

class ReindexCollectionController extends Controller
{
Expand All @@ -34,6 +36,8 @@ public function reindex(Collection $collection)
->name("Reindexing - {$document->id}")
->finally(function (Batch $batch) use ($document) {
SummarizeDocumentJob::dispatch($document);
TagDocumentJob::dispatch($document);
DocumentProcessingCompleteJob::dispatch($document);
})
->allowFailures()
->dispatch();
Expand Down
39 changes: 39 additions & 0 deletions app/Http/Resources/DocumentResourceWithPaginate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

class DocumentResourceWithPaginate extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @return array<int|string, mixed>
*/
public function toArray(Request $request): array
{
return [
'data' => DocumentResource::collection($this),
'meta' => [
'current_page' => $this->currentPage(),
'from' => $this->firstItem(),
'last_page' => $this->lastPage(),
'per_page' => $this->perPage(),
'to' => $this->lastItem(),
'total' => $this->total(),
],
'links' => [
'first' => route('collections.documents.index', [
'collection' => request()->collection->id,
'filter' => request()->filter,
'page' => 1,
]),
'last' => $this->url($this->lastPage()),
'prev' => $this->previousPageUrl(),
'next' => $this->nextPageUrl(),
],
];
}
}
2 changes: 1 addition & 1 deletion app/Jobs/DocumentProcessingCompleteJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DocumentProcessingCompleteJob implements ShouldQueue
*/
public function __construct(public Document $document)
{
//
$this->onQueue("default");
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Jobs/GetWebContentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function handle(): void
new VectorlizeDataJob($DocumentChunk),
new SummarizeDocumentJob($document),
new TagDocumentJob($document),
new DocumentProcessingCompleteJob($document),
]);

$page_number++;
Expand Down
3 changes: 1 addition & 2 deletions app/Jobs/SummarizeDocumentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ public function handle(): void

$this->document->update([
'summary' => $this->results,
'status_summary' => StatusEnum::Complete,
'status_summary' => StatusEnum::SummaryComplete,
]);

DocumentProcessingCompleteJob::dispatch($this->document);
}
}
4 changes: 2 additions & 2 deletions resources/js/Pages/Batches/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const cancelAll = () => {
<th>Pending Jobs</th>
<th>Failed Jobs</th>
<th>
Created At\Cancelled At\Finished At
Created At\Finished At\Cancelled At
</th>
<th></th>
</tr>
Expand All @@ -113,7 +113,7 @@ const cancelAll = () => {
{{ batch.failed_jobs }}
</td>
<td>
{{ batch.created_at }} \ {{ batch.cancelled_at }} \ {{ batch.finished_at }}
{{ batch.created_at }} \ {{ batch.finished_at }} \ {{ batch.cancelled_at }}
</td>
<td>
<button type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const toast = useToast()
const emit = defineEmits(['deleted'])
const props = defineProps(
{
collection: Object,
documentIds: Array
}
)
Expand All @@ -21,6 +23,8 @@ const form = useForm({
documents: []
})
const deleteAllForm = useForm({})
const deleteDocs = () => {
toast.info("Deleting documents")
form
Expand All @@ -38,17 +42,61 @@ const deleteDocs = () => {
});
}
const deleteAll = () => {
toast.info("Deleting All Documents")
deleteAllForm
.delete(route('documents.delete_all', {
collection: props.collection.id
}), {
preserveScroll: true,
onSuccess: params => {
form.reset();
showConfirm.value = false;
emit('deletedAll')
}
});
}
const showConfirm = ref(false)
const showConfirmAll = ref(false)
const confirm = () => {
showConfirm.value = true;
}
const confirmAll = () => {
showConfirmAll.value = true;
}
</script>

<template>
<button @click="confirm" class="btn btn-neutral">
Delete {{documentIds.length}} Documents
</button>
<button @click="confirmAll" class="btn btn-warning">
Delete All Documents
</button>

<ConfirmationModal :show="showConfirmAll" @close="showConfirmAll = false">
<template #title>
Delete All Documents
</template>

<template #content>
This will delete All document for this collection
</template>

<template #footer>
<SecondaryButton @click.native="showConfirmAll = false">
Nevermind
</SecondaryButton>

<DangerButton class="ml-2" @click.native="deleteAll" :class="{ 'opacity-25': form.processing }" :disabled="form.processing">
Delete All Documents
</DangerButton>
</template>
</ConfirmationModal>

<ConfirmationModal :show="showConfirm" @close="showConfirm = false">
<template #title>
Expand All @@ -64,7 +112,7 @@ const confirm = () => {
Nevermind
</SecondaryButton>

<DangerButton class="ml-2" @click.native="deleteDocs" :class="{ 'opacity-25': form.processing }" :disabled="form.processing">
<DangerButton class="ml-2" @click.native="deleteDocs" :class="{ 'opacity-25': deleteAllForm.processing }" :disabled="form.processing">
Delete Documents
</DangerButton>
</template>
Expand Down
71 changes: 71 additions & 0 deletions resources/js/Pages/Collection/Components/DocumentStatus.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script setup>
import {computed, onMounted, onUnmounted, ref} from "vue";
import {router} from "@inertiajs/vue3";
const props = defineProps({
collection: Array
})
const notCompleteCount = computed(() => {
return documents.value.filter(document => document.status !== 'Complete').length;
})
const completeCount = computed(() => {
return documents.value.filter(document => document.status === 'Complete').length;
})
const totalCount = computed(() => {
return documents.value.length;
})
const percentComplete = computed(() => {
return Math.round((completeCount.value / totalCount.value) * 100);
})
const documents = ref([]);
const getDocuments = () => {
axios.get(route('collections.documents.status', {
collection: props.collection.id
})).then(response => {
documents.value = response.data.documents;
}).catch(error => {
console.log(error)
})
}
onUnmounted(() => {
Echo.leave(`collection.${props.collection.id}`);
});
onMounted(() => {
Echo.private(`collection.${props.collection.id}`)
.listen('.status', (e) => {
let message = e.message;
if (message === 'Document Processed' || message === 'processing') {
getDocuments();
}
});
getDocuments();
})
</script>

<template>

<div v-show="documents.length > 0" v-auto-animate>
<div class="flex justify-start gap-2 items-center text-sm border border-secondary p-2 rounded-md">
<div>Total: {{totalCount}}</div>
<div>Complete: {{completeCount}}</div>
<div>Not Complete: {{notCompleteCount}}</div>
<div class="radial-progress text-xs text-secondary"

:style="`--value:${percentComplete}; --size:3rem; `" role="progressbar">{{percentComplete}}%</div>
</div>
</div>

</template>

<style scoped>
</style>
Loading

0 comments on commit 0e702a0

Please sign in to comment.