Skip to content

Commit a8c819b

Browse files
committed
fix llamacloud log
1 parent af83b50 commit a8c819b

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

templates/types/streaming/fastapi/app/api/routers/chat_config.py

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,46 @@
1010
logger = logging.getLogger("uvicorn")
1111

1212

13+
def _is_llama_cloud_service_configured():
14+
try:
15+
from app.engine.service import LLamaCloudFileService # noqa
16+
17+
return True
18+
except ImportError:
19+
return False
20+
21+
22+
async def chat_llama_cloud_config():
23+
from app.engine.service import LLamaCloudFileService
24+
25+
if not os.getenv("LLAMA_CLOUD_API_KEY"):
26+
raise HTTPException(
27+
status_code=500, detail="LlamaCloud API KEY is not configured"
28+
)
29+
projects = LLamaCloudFileService.get_all_projects_with_pipelines()
30+
pipeline = os.getenv("LLAMA_CLOUD_INDEX_NAME")
31+
project = os.getenv("LLAMA_CLOUD_PROJECT_NAME")
32+
pipeline_config = None
33+
if pipeline and project:
34+
pipeline_config = {
35+
"pipeline": pipeline,
36+
"project": project,
37+
}
38+
return {
39+
"projects": projects,
40+
"pipeline": pipeline_config,
41+
}
42+
43+
44+
if _is_llama_cloud_service_configured():
45+
logger.info("LlamaCloud is configured. Adding /config/llamacloud route.")
46+
r.add_api_route("/llamacloud", chat_llama_cloud_config, methods=["GET"])
47+
48+
1349
@r.get("")
1450
async def chat_config() -> ChatConfig:
1551
starter_questions = None
1652
conversation_starters = os.getenv("CONVERSATION_STARTERS")
1753
if conversation_starters and conversation_starters.strip():
1854
starter_questions = conversation_starters.strip().split("\n")
1955
return ChatConfig(starter_questions=starter_questions)
20-
21-
22-
try:
23-
from app.engine.service import LLamaCloudFileService
24-
25-
print("LlamaCloud is configured. Adding /config/llamacloud route.")
26-
27-
@r.get("/llamacloud")
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-
)
33-
projects = LLamaCloudFileService.get_all_projects_with_pipelines()
34-
pipeline = os.getenv("LLAMA_CLOUD_INDEX_NAME")
35-
project = os.getenv("LLAMA_CLOUD_PROJECT_NAME")
36-
pipeline_config = None
37-
if pipeline and project:
38-
pipeline_config = {
39-
"pipeline": pipeline,
40-
"project": project,
41-
}
42-
return {
43-
"projects": projects,
44-
"pipeline": pipeline_config,
45-
}
46-
47-
except ImportError:
48-
print("LlamaCloud is not configured. Skipping adding /config/llamacloud route.")
49-
pass

templates/types/streaming/fastapi/app/api/routers/models.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ class AnnotationFileData(BaseModel):
2222
class Config:
2323
json_schema_extra = {
2424
"example": {
25-
"csvFiles": [
25+
"files": [
2626
{
27-
"content": "Name, Age\nAlice, 25\nBob, 30",
28-
"name": "example.csv",
29-
"size": 123,
30-
"id": "123",
31-
"type": "text/csv",
27+
"content": "data:text/plain;base64,aGVsbG8gd29ybGQK=",
28+
"name": "example.txt",
3229
}
3330
]
3431
}

0 commit comments

Comments
 (0)