diff --git a/app/Domains/Prompts/GoogleSheetSource.php b/app/Domains/Prompts/GoogleSheetSource.php new file mode 100644 index 00000000..690052f3 --- /dev/null +++ b/app/Domains/Prompts/GoogleSheetSource.php @@ -0,0 +1,30 @@ +meta_data['sheet_id'], $source->meta_data['sheet_name']); + + $collection = $source->collection; + + $name = sprintf('%s_%s.csv', + $source->meta_data['sheet_name'], + str($source->meta_data['sheet_id'])->limit(15, '')->toString() + ); + + Storage::disk('collections') + ->put($collection->id.'/'.$name, $content); + + $document = Document::updateOrCreate([ + 'collection_id' => $collection->id, + 'file_path' => $name, + 'type' => TypesEnum::CSV, + ]); + + Bus::batch([ + new ProcessCSVJob($document), + ]) + ->name('Process Google Sheet CSV Document - '.$document->id) + ->allowFailures() + ->dispatch(); + + Log::info('[LaraChain] - GoogleSheetSource sent work to ProcessCSVJob'); + + } +} diff --git a/app/Domains/Sources/GoogleSheetSource/GoogleSheetWrapper.php b/app/Domains/Sources/GoogleSheetSource/GoogleSheetWrapper.php new file mode 100644 index 00000000..7c924716 --- /dev/null +++ b/app/Domains/Sources/GoogleSheetSource/GoogleSheetWrapper.php @@ -0,0 +1,28 @@ +successful()) { + $csvData = $response->body(); + + return $csvData; + } + + return ''; + } +} diff --git a/app/Domains/Sources/SourceTypeEnum.php b/app/Domains/Sources/SourceTypeEnum.php index ab6d081e..fa2f53ae 100644 --- a/app/Domains/Sources/SourceTypeEnum.php +++ b/app/Domains/Sources/SourceTypeEnum.php @@ -18,6 +18,7 @@ enum SourceTypeEnum: string case FeedSource = 'feed_source'; case WebPageSource = 'web_page_source'; case SiteMapSource = 'site_map_source'; + case GoogleSheetSource = 'google_sheet_source'; //leave for scripting public static function ignore(): array diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 8b23aec0..d297022f 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -42,12 +42,14 @@ public function showCollectionChat(Collection $collection, Chat $chat) 'collection' => new CollectionResource($collection), 'reference_collections' => Collection::orderBy('name') ->get() - ->transform(function ($item) { - return [ - 'id' => $item->id, - 'name' => $item->name, - ]; - }), + ->transform( + /** @phpstan-ignore-next-line */ + function ($item) { + return [ + 'id' => $item->id, + 'name' => $item->name, + ]; + }), 'date_ranges' => DateRangesEnum::selectOptions(), 'chat' => new ChatResource($chat), 'chats' => ChatResource::collection($collection->chats()->latest()->paginate(20)), @@ -56,7 +58,7 @@ public function showCollectionChat(Collection $collection, Chat $chat) 'audiences' => AudienceResource::collection(Audience::all()), 'system_prompt' => $collection->systemPrompt(), 'settings' => [ - 'supports_functions' => LlmDriverFacade::driver($chat->getDriver())->hasFunctions(), + 'supports_functions' => LlmDriverFacade::driver($chat->getDriver())->hasFunctions(), ], 'messages' => MessageResource::collection($chat->latest_messages), ]); @@ -93,8 +95,6 @@ public function chat(Chat $chat) $input = $persona->wrapPromptInPersona($input); } - put_fixture('validated_chat_input.json', $validated); - $meta_data = MetaDataDto::from($validated); $message = $chat->addInput( diff --git a/app/Http/Controllers/Sources/GoogleSheetSourceController.php b/app/Http/Controllers/Sources/GoogleSheetSourceController.php new file mode 100644 index 00000000..13f4b48a --- /dev/null +++ b/app/Http/Controllers/Sources/GoogleSheetSourceController.php @@ -0,0 +1,77 @@ + GoogleSheetSource::prompt('[CONTEXT]'), + ]; + } + + protected function getValidationRules(): array + { + return [ + 'title' => 'required|string', + 'details' => 'required|string', + 'active' => ['boolean', 'required'], + 'recurring' => ['string', 'required'], + 'meta_data' => ['required', 'array'], + 'meta_data.sheet_id' => ['required', 'string'], + 'meta_data.sheet_name' => ['required', 'string'], + 'secrets' => ['nullable', 'array'], + ]; + + } + + protected function makeSource(array $validated, Collection $collection): void + { + Source::create([ + 'title' => $validated['title'], + 'details' => $validated['details'], + 'recurring' => $validated['recurring'], + 'active' => $validated['active'], + 'collection_id' => $collection->id, + 'type' => $this->sourceTypeEnum, + 'meta_data' => $validated['meta_data'], + ]); + } + + public function testFeed() + { + $validated = request()->validate([ + 'sheet_id' => ['required', 'string'], + 'sheet_name' => ['required', 'string'], + ]); + + $items = GoogleSheetWrapper::handle($validated['sheet_id'], $validated['sheet_name'], 'A1:Z10'); + + $rows = array_map('str_getcsv', explode("\n", $items)); + + return response()->json([ + 'count' => count($rows), + 'items' => $rows, + ]); + } +} diff --git a/resources/js/Pages/Sources/GoogleSheetSource/Components/Card.vue b/resources/js/Pages/Sources/GoogleSheetSource/Components/Card.vue new file mode 100644 index 00000000..251192c1 --- /dev/null +++ b/resources/js/Pages/Sources/GoogleSheetSource/Components/Card.vue @@ -0,0 +1,51 @@ + + + + + diff --git a/resources/js/Pages/Sources/GoogleSheetSource/Components/Resources.vue b/resources/js/Pages/Sources/GoogleSheetSource/Components/Resources.vue new file mode 100644 index 00000000..30d3b2c9 --- /dev/null +++ b/resources/js/Pages/Sources/GoogleSheetSource/Components/Resources.vue @@ -0,0 +1,143 @@ +