File tree 6 files changed +25
-18
lines changed
nextjs/app/components/ui/chat/widgets 6 files changed +25
-18
lines changed Original file line number Diff line number Diff line change 1
1
# flake8: noqa: E402
2
2
import os
3
+
3
4
from dotenv import load_dotenv
4
5
5
6
load_dotenv ()
6
7
7
- from llama_cloud import PipelineType
8
-
9
- from app .settings import init_settings
10
- from llama_index .core .settings import Settings
11
-
8
+ import logging
12
9
13
10
from app .engine .index import get_client , get_index
14
-
15
- import logging
16
- from llama_index .core .readers import SimpleDirectoryReader
17
11
from app .engine .service import LLamaCloudFileService
12
+ from app .settings import init_settings
13
+ from llama_cloud import PipelineType
14
+ from llama_index .core .readers import SimpleDirectoryReader
15
+ from llama_index .core .settings import Settings
18
16
19
17
logging .basicConfig (level = logging .INFO )
20
18
logger = logging .getLogger ()
@@ -83,10 +81,6 @@ def generate_datasource():
83
81
project_id ,
84
82
pipeline_id ,
85
83
f ,
86
- custom_metadata = {
87
- # Set private=false to mark the document as public (required for filtering)
88
- "private" : "false" ,
89
- },
90
84
)
91
85
92
86
logger .info ("Finished generating the index" )
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ def generate_filters(doc_ids):
5
5
"""
6
6
Generate public/private document filters based on the doc_ids and the vector store.
7
7
"""
8
- # Using "is_empty" filter to include the documents don't have the "private" key because they're uploaded in LlamaCloud UI
8
+ # public documents (ingested by "poetry run generate" or in the LlamaCloud UI) don't have the "private" field
9
9
public_doc_filter = MetadataFilter (
10
10
key = "private" ,
11
11
value = None ,
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ async function* walk(dir: string): AsyncGenerator<string> {
25
25
26
26
async function loadAndIndex ( ) {
27
27
const index = await getDataSource ( ) ;
28
+ // ensure the index is available or create a new one
29
+ await index . ensureIndex ( ) ;
28
30
const projectId = await index . getProjectId ( ) ;
29
31
const pipelineId = await index . getPipelineId ( ) ;
30
32
@@ -37,7 +39,6 @@ async function loadAndIndex() {
37
39
projectId ,
38
40
pipelineId ,
39
41
new File ( [ buffer ] , filename ) ,
40
- { private : "false" } ,
41
42
) ;
42
43
} catch ( error ) {
43
44
if (
Original file line number Diff line number Diff line change 1
1
import { CloudRetrieveParams , MetadataFilter } from "llamaindex" ;
2
2
3
3
export function generateFilters ( documentIds : string [ ] ) {
4
- // public documents don't have the "private" field or it's set to "false"
4
+ // public documents (ingested by "npm run generate" or in the LlamaCloud UI) don't have the "private" field
5
5
const publicDocumentsFilter : MetadataFilter = {
6
6
key : "private" ,
7
7
operator : "is_empty" ,
Original file line number Diff line number Diff line change 1
1
import logging
2
2
import os
3
3
4
- from fastapi import APIRouter
4
+ from fastapi import APIRouter , HTTPException
5
5
6
6
from app .api .routers .models import ChatConfig
7
7
8
-
9
8
config_router = r = APIRouter ()
10
9
11
10
logger = logging .getLogger ("uvicorn" )
@@ -27,6 +26,10 @@ async def chat_config() -> ChatConfig:
27
26
28
27
@r .get ("/llamacloud" )
29
28
async def chat_llama_cloud_config ():
29
+ if not os .getenv ("LLAMA_CLOUD_API_KEY" ):
30
+ raise HTTPException (
31
+ status_code = 500 , detail = "LlamaCloud API KEY is not configured"
32
+ )
30
33
projects = LLamaCloudFileService .get_all_projects_with_pipelines ()
31
34
pipeline = os .getenv ("LLAMA_CLOUD_INDEX_NAME" )
32
35
project = os .getenv ("LLAMA_CLOUD_PROJECT_NAME" )
Original file line number Diff line number Diff line change @@ -66,7 +66,16 @@ export function LlamaCloudSelector({
66
66
useEffect ( ( ) => {
67
67
if ( process . env . NEXT_PUBLIC_USE_LLAMACLOUD === "true" && ! config ) {
68
68
fetch ( `${ backend } /api/chat/config/llamacloud` )
69
- . then ( ( response ) => response . json ( ) )
69
+ . then ( ( response ) => {
70
+ if ( ! response . ok ) {
71
+ return response . json ( ) . then ( ( errorData ) => {
72
+ window . alert (
73
+ `Error: ${ JSON . stringify ( errorData ) || "Unknown error occurred" } ` ,
74
+ ) ;
75
+ } ) ;
76
+ }
77
+ return response . json ( ) ;
78
+ } )
70
79
. then ( ( data ) => {
71
80
const pipeline = defaultPipeline ?? data . pipeline ; // defaultPipeline will override pipeline in .env
72
81
setConfig ( { ...data , pipeline } ) ;
You can’t perform that action at this time.
0 commit comments