From 7f4ac228eec1d205caf590d4c7db05d4164a604b Mon Sep 17 00:00:00 2001 From: Marcus Schiesser <mail@marcusschiesser.de> Date: Tue, 8 Oct 2024 16:56:12 +0700 Subject: [PATCH] Don't need to run generate script for LlamaCloud (#352) --- .changeset/polite-onions-return.md | 5 +++ .../ui/chat/widgets/LlamaCloudSelector.tsx | 34 +++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 .changeset/polite-onions-return.md diff --git a/.changeset/polite-onions-return.md b/.changeset/polite-onions-return.md new file mode 100644 index 00000000..f12ad89b --- /dev/null +++ b/.changeset/polite-onions-return.md @@ -0,0 +1,5 @@ +--- +"create-llama": patch +--- + +Don't need to run generate script for LlamaCloud diff --git a/templates/types/streaming/nextjs/app/components/ui/chat/widgets/LlamaCloudSelector.tsx b/templates/types/streaming/nextjs/app/components/ui/chat/widgets/LlamaCloudSelector.tsx index 49fff260..c9ed7ecb 100644 --- a/templates/types/streaming/nextjs/app/components/ui/chat/widgets/LlamaCloudSelector.tsx +++ b/templates/types/streaming/nextjs/app/components/ui/chat/widgets/LlamaCloudSelector.tsx @@ -45,7 +45,7 @@ export function LlamaCloudSelector({ setRequestData, onSelect, defaultPipeline, - shouldCheckValid = true, + shouldCheckValid = false, }: LlamaCloudSelectorProps) { const { backend } = useClientConfig(); const [config, setConfig] = useState<LlamaCloudConfig>(); @@ -95,7 +95,8 @@ export function LlamaCloudSelector({ </div> ); } - if (!isValid(config) && shouldCheckValid) { + + if (shouldCheckValid && !isValid(config.projects, config.pipeline)) { return ( <p className="text-red-500"> Invalid LlamaCloud configuration. Check console logs. @@ -107,7 +108,11 @@ export function LlamaCloudSelector({ return ( <Select onValueChange={handlePipelineSelect} - defaultValue={JSON.stringify(pipeline)} + defaultValue={ + isValid(projects, pipeline, false) + ? JSON.stringify(pipeline) + : undefined + } > <SelectTrigger className="w-[200px]"> <SelectValue placeholder="Select a pipeline" /> @@ -137,26 +142,33 @@ export function LlamaCloudSelector({ ); } -function isValid(config: LlamaCloudConfig): boolean { - const { projects, pipeline } = config; +function isValid( + projects: LLamaCloudProject[] | undefined, + pipeline: PipelineConfig | undefined, + logErrors: boolean = true, +): boolean { if (!projects?.length) return false; if (!pipeline) return false; const matchedProject = projects.find( (project: LLamaCloudProject) => project.name === pipeline.project, ); if (!matchedProject) { - console.error( - `LlamaCloud project ${pipeline.project} not found. Check LLAMA_CLOUD_PROJECT_NAME variable`, - ); + if (logErrors) { + console.error( + `LlamaCloud project ${pipeline.project} not found. Check LLAMA_CLOUD_PROJECT_NAME variable`, + ); + } return false; } const pipelineExists = matchedProject.pipelines.some( (p) => p.name === pipeline.pipeline, ); if (!pipelineExists) { - console.error( - `LlamaCloud pipeline ${pipeline.pipeline} not found. Check LLAMA_CLOUD_INDEX_NAME variable`, - ); + if (logErrors) { + console.error( + `LlamaCloud pipeline ${pipeline.pipeline} not found. Check LLAMA_CLOUD_INDEX_NAME variable`, + ); + } return false; } return true; -- GitLab