Skip to content

Commit

Permalink
ready to deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Mar 28, 2024
1 parent a85169f commit 088b71e
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/Domains/Documents/Transformers/PdfTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Domains\Documents\Transformers;

use App\Domains\Collections\CollectionStatusEnum;
use App\Events\CollectionStatusEvent;
use App\Jobs\SummarizeDataJob;
use App\Jobs\SummarizeDocumentJob;
use App\Jobs\VectorlizeDataJob;
Expand Down Expand Up @@ -48,6 +50,8 @@ public function handle(Document $document): Document
new SummarizeDataJob($DocumentChunk),
//Tagging
];

CollectionStatusEvent::dispatch($document->collection, CollectionStatusEnum::PROCESSING);
}

$batch = Bus::batch($chunks)
Expand Down
44 changes: 44 additions & 0 deletions app/Events/ChatUpdatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Events;

use App\Models\Chat;
use App\Models\Collection;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ChatUpdatedEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(public Collection $collection, public Chat $chat)
{
//
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('collection.chat.'.$this->collection->id.'.'.$this->chat->id),
];
}

/**
* The event's broadcast name.
*/
public function broadcastAs(): string
{
return 'status';
}
}
3 changes: 3 additions & 0 deletions app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Events\ChatUpdatedEvent;
use App\Http\Resources\ChatResource;
use App\Http\Resources\CollectionResource;
use App\Http\Resources\MessageResource;
Expand Down Expand Up @@ -45,6 +46,8 @@ public function chat(Chat $chat)

$response = SearchOrSummarizeChatRepo::search($chat, $validated['input']);

ChatUpdatedEvent::dispatch($chat->chatable, $chat);

return response()->json(['message' => $response]);
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function store()
$validated = request()->validate([
'name' => 'required',
'description' => 'required',
'driver' => 'required',
]);

$validated['team_id'] = auth()->user()->current_team_id;
Expand Down
4 changes: 3 additions & 1 deletion resources/js/Pages/Chat/ChatInputThreaded.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ const getting_results = ref(false)
const save = () => {
getting_results.value = true
let message = form.input
form.reset();
axios.post(route('chats.messages.create', {
chat: props.chat.id
}), {
input: form.input
input: message
}).then(response => {
getting_results.value = false
console.log(response.data.message)
Expand Down
10 changes: 9 additions & 1 deletion resources/js/Pages/Collection/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ const props = defineProps({
provide('system_prompt', props.system_prompt);
onMounted(() => {
Echo.private(`collection.chat.${props.collection.data.id}.${props.chat.data.id}`)
.listen('.status', (e) => {
console.log(e);
router.reload({
preserveScroll: true,
})
});
});
</script>

<template>
Expand Down
62 changes: 62 additions & 0 deletions resources/js/Pages/Collection/Components/LlmType.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<template>
<Listbox as="div" v-model="selected">
<ListboxLabel class="sr-only">Choose LLM Drier</ListboxLabel>
<div class="relative">
<div class="inline-flex divide-x divide-indigo-700 rounded-md shadow-sm">
<div class="inline-flex items-center gap-x-1.5 rounded-l-md bg-indigo-600 px-3 py-2 text-white shadow-sm">
<CheckIcon class="-ml-0.5 h-5 w-5" aria-hidden="true" />
<p class="text-sm font-semibold">{{ selected.title }}</p>
</div>
<ListboxButton class="inline-flex items-center rounded-l-none rounded-r-md bg-indigo-600 p-2 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2 focus:ring-offset-gray-50">
<span class="sr-only">Change published status</span>
<ChevronDownIcon class="h-5 w-5 text-white" aria-hidden="true" />
</ListboxButton>
</div>

<transition leave-active-class="transition ease-in duration-100" leave-from-class="opacity-100" leave-to-class="opacity-0">
<ListboxOptions class="absolute right-0 z-10 mt-2 w-72 origin-top-right divide-y divide-gray-200 overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
<ListboxOption as="template" v-for="option in publishingOptions" :key="option.title" :value="option" v-slot="{ active, selected }">
<li :class="[active ? 'bg-indigo-600 text-white' : 'text-gray-900', 'cursor-default select-none p-4 text-sm']">
<div class="flex flex-col">
<div class="flex justify-between">
<p :class="selected ? 'font-semibold' : 'font-normal'">{{ option.title }}</p>
<span v-if="selected" :class="active ? 'text-white' : 'text-indigo-600'">
<CheckIcon class="h-5 w-5" aria-hidden="true" />
</span>
</div>
<p :class="[active ? 'text-indigo-200' : 'text-gray-500', 'mt-2']">{{ option.description }}</p>
</div>
</li>
</ListboxOption>
</ListboxOptions>
</transition>
</div>
</Listbox>
</template>

<script setup>
import { ref, watch } from 'vue'
import { Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions } from '@headlessui/vue'
import { CheckIcon, ChevronDownIcon } from '@heroicons/vue/20/solid'
const emit = defineEmits(['typeChosen'])
const publishingOptions = [
{ key: "mock", title: 'Mock LLM', description: 'This will mock all the LLM features great for local development', current: true },
{ key: "openai", title: 'OpenAi', description: 'This will work with the OpenAi Api', current: false },
{ key: "mock", title: 'OpenAi Azure', description: 'This will work with the Azure OpenAi Api', current: false },
{ key: "ollama", title: 'Ollama', description: 'This will work with the Ollam API', current: false },
{ key: "mock", title: 'Gemini', description: 'This will work with the Gemini Api', current: false },
{ key: "mock", title: 'Claude', description: 'This will work with the Claude Api', current: false },
]
const selected = ref(publishingOptions[0])
watch(selected, (value) => {
console.log("emit " , value)
emit('typeChosen', value.key)
})
</script>
10 changes: 9 additions & 1 deletion resources/js/Pages/Collection/Components/ResourceForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<TextArea v-model="modelValue.description" type="text" class="mt-1 block w-full" />
<InputError :message="modelValue.errors.description" class="mt-2" />
</div>

<div class="sm:col-span-3">
<LlmType @typeChosen="typeChosen" />
</div>
</div>
</template>

Expand All @@ -20,10 +22,16 @@ import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import TextInput from '@/Components/TextInput.vue';
import TextArea from '@/Components/TextArea.vue';
import LlmType from './LlmType.vue';
const props = defineProps({
modelValue: Object,
});
const typeChosen = (type) => {
console.log("TYPE " + type)
props.modelValue.driver = type;
}
</script>
2 changes: 2 additions & 0 deletions resources/js/Pages/Collection/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { XMarkIcon } from '@heroicons/vue/24/outline'
import { Head, Link, useForm } from '@inertiajs/vue3';
import ResourceForm from './Components/ResourceForm.vue';
const props = defineProps({
collection: Object,
open: Boolean,
Expand All @@ -76,6 +77,7 @@ const closeSlideOut = () => {
const form = useForm({
name: "",
driver: "mock",
description: "Some details about your collection that will help give the ai system some context."
})
Expand Down
16 changes: 13 additions & 3 deletions routes/channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@
return (int) $user->id === (int) $id;
});


Broadcast::channel('collection.{id}', function ($user, $id) {
Log::info("Connecting to channel collection." . $id);
Log::info('Connecting to channel collection.'.$id);

/**
* @TODO
* Must be on the team of the collection!
*/
return true;
});
});

Broadcast::channel('collection.chat.{id}.{chatId}', function ($user, $id, $chatId) {
Log::info('Connecting to channel collection.chat.'.$id.'.'.$chatId);

/**
* @TODO
* Must be on the team of the collection!
*/
return true;
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function test_store(): void
$this->assertDatabaseCount('collections', 0);
$response = $this->post(route('collections.store'), [
'name' => 'Test',
'driver' => 'mock',
'description' => 'Test Description',
])->assertStatus(302);
$this->assertDatabaseCount('collections', 1);
Expand Down

0 comments on commit 088b71e

Please sign in to comment.