Skip to content

Commit

Permalink
this will add the ui to add sources
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed May 7, 2024
1 parent 7532eb7 commit aaf0f6a
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 208 deletions.
21 changes: 17 additions & 4 deletions app/Domains/Sources/WebSearchSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ public function handle(Source $source): void
$driver = data_get($meta_data, 'driver', 'mock');

$prompt = <<<PROMPT
The user is asking to search the web but I want you to review the query and clean it up so I can pass
it to an api to get results: Just return their content but with your rework so I can pass it right to the
search api. ONLY return the updated query I will pass this directly to the API via code:
The user is asking to search the web but I want you to review the query and clean it keeping it as
a string.
Here are some examples of how I want you to return the data:
### RETURN FORMAT
in: Search the web for PHP news and Laravle news
out: php news OR laravel news -filetype:pdf -intitle:pdf
in: current data on the llm industry
out: llm industry news OR llm industry updates -filetype:pdf -intitle:pdf
in: latest news on the laravel framework
out: laravel framework news OR laravel framework updates -filetype:pdf -intitle:pdf
### END RETURN FORMAT
### START USER QUERY
$search
### END USER QUERY
PROMPT;

Log::info('[LaraChain] Asking LLM to optimize search query');
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Domains\Documents\StatusEnum;
use App\Domains\Documents\TypesEnum;
use App\Http\Resources\ChatResource;
use App\Http\Resources\CollectionResource;
use App\Http\Resources\DocumentResource;
use App\Jobs\ProcessFileJob;
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

abstract class Controller
{

protected function getChatResource(Collection $collection) {
protected function getChatResource(Collection $collection)
{
$chatResource = $collection->chats()->where('user_id', auth()->user()->id)
->latest('id')
->first();
->latest('id')
->first();

if ($chatResource?->id) {
$chatResource = new ChatResource($chatResource);
Expand Down
12 changes: 9 additions & 3 deletions app/Http/Controllers/SourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace App\Http\Controllers;

use App\Http\Resources\ChatResource;
use App\Http\Resources\CollectionResource;
use App\Http\Resources\DocumentResource;
use App\Http\Resources\SourceResource;
use App\Models\Collection;
use App\Models\Document;
use Illuminate\Http\Request;
use App\Models\Source;

class SourceController extends Controller
{

public function index(Collection $collection)
{
$chatResource = $chatResource = $this->getChatResource($collection);
Expand All @@ -27,4 +25,12 @@ public function index(Collection $collection)
'sources' => SourceResource::collection($collection->sources()->paginate(10)),
]);
}

public function run(Source $source)
{
$source->run();
request()->session()->flash('flas.banner', 'Web source is running');

return back();
}
}
31 changes: 31 additions & 0 deletions app/Http/Controllers/WebSourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Http\Controllers;

use App\Domains\Sources\SourceTypeEnum;
use App\Http\Resources\CollectionResource;
use App\Http\Resources\SourceResource;
use App\Models\Collection;
use App\Models\Source;

class WebSourceController extends Controller
{
Expand All @@ -14,4 +17,32 @@ public function index(Collection $collection)
'sources' => SourceResource::collection($collection->sources()->paginate(10)),
]);
}

public function create(Collection $collection)
{
return inertia('Sources/WebSource/Create', [
'collection' => new CollectionResource($collection),
]);
}

public function store(Collection $collection)
{

$validated = request()->validate([
'title' => 'required|string',
'details' => 'required|string',
]);

Source::create([
'title' => $validated['title'],
'details' => $validated['details'],
'collection_id' => $collection->id,
'type' => SourceTypeEnum::WebSearchSource,
'meta_data' => [],
]);

request()->session()->flash('flas.banner', 'Web source added successfully');

return to_route('collections.sources.index', $collection);
}
}
7 changes: 6 additions & 1 deletion app/Http/Resources/SourceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class SourceResource extends JsonResource
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'type' => str($this->type->name)->headline()->toString(),
];
}
}
16 changes: 16 additions & 0 deletions resources/js/Components/Intro.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<h3 class="text-base font-semibold leading-6 text-gray-900">
<slot></slot>
</h3>

<div class="mt-2 max-w-4xl text-sm text-gray-500">
<slot name="description"></slot>
</div>
</template>

<script setup>
const props = defineProps({
collection: Object
})
</script>
158 changes: 158 additions & 0 deletions resources/js/Pages/Collection/Components/Documents.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<script setup>
import { ref } from 'vue';
import Tags from '@/Components/Tags.vue';
import ShowDocument from '@/Pages/Collection/Components/ShowDocument.vue';
const props = defineProps({
collection: {
type: Object,
required: true,
},
documents: {
type: Object,
}
});
const document = ref({})
const showDocumentSlideOut = ref(false)
const showDocumentButton = (documentToShow) => {
document.value = documentToShow;
showDocumentSlideOut.value = true;
};
const closeDocument = () => {
document.value = {};
showDocumentSlideOut.value = false;
};
</script>
<template>
<div class="px-5">
<h1 class="text-base font-semibold leading-6 text-gray-900">Related Documents</h1>
<p class="mt-2 text-sm text-gray-700">Thsee are a list of documents you uploaded or imported
into this
Collection and the status of their processing</p>
</div>

<div v-auto-animate>
<div class="px-4 sm:px-6 lg:px-8">
<div class="mt-8 flow-root">
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="inline-block min-w-full py-2 align-middle sm:px-6 lg:px-8">
<div v-if="documents.length === 0"
class="text-center text-sm font-medium text-gray-900 px-10 py-10">
No Documents uploaded yet please upload some documents to get started.
</div>
<table class="min-w-full divide-y divide-gray-300 mb-10 " v-else>
<thead>
<tr>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
ID
</th>

<th scope="col"
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-3">
Type</th>
<th scope="col"
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-3">
Name</th>
<th scope="col"
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-3">
Pages</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Status
</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
Actions
</th>
</tr>
</thead>
<tbody class="bg-white">
<template v-for="document in documents" :key="document.id">
<tr class="even:bg-gray-50">
<td
class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-3">
{{ document.id }}
</td>
<td
class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-3">
{{ document.type }}
</td>
<td
class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-3">

<a class="underline" target="_blank" :href="route('download.document', {
collection: collection.id,
document_name: document.file_path
})">{{ document.file_path }}</a>

</td>
<td
class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-3">
{{ document.document_chunks_count }}
</td>
<td
class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-3">
<span v-if="document.status !== 'Pending'"
class="inline-flex items-center rounded-md bg-blue-50 px-2 py-1 text-xs font-medium text-blue-700 ring-1 ring-inset ring-blue-700/10">
{{ document.status }}
</span>
<span v-else class="flex justify-left pl-6">
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-gray-400"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10"
stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
</span>
</td>
<td>
<ul>
<li>
<button type="button"
class="text-gray-500 text-sm flex justify-start gap-2 items-center flex justify-start gap-2 items-center"
@click="showDocumentButton(document)">
<span>view</span>

<svg xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"
class="w-4 h-4">
<path stroke-linecap="round" stroke-linejoin="round"
d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" />
<path stroke-linecap="round" stroke-linejoin="round"
d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
</svg>
</button>
</li>
<li>
<DocumentReset :collection="collection" :document="document"
@reset="reset" />
</li>
</ul>
</td>
</tr>
<tr class="justify-center gap-2 items-center">
<td colspan="6" class="w-full">
<Tags :document="document"></Tags>
</td>
</tr>
</template>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<Teleport to="body">

<ShowDocument :document="document" :open="showDocumentSlideOut"
@closing="closeDocument" />
</Teleport>

</template>
Loading

0 comments on commit aaf0f6a

Please sign in to comment.