|
10 | 10 | logger = logging.getLogger("uvicorn")
|
11 | 11 |
|
12 | 12 |
|
| 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 | + |
13 | 49 | @r.get("")
|
14 | 50 | async def chat_config() -> ChatConfig:
|
15 | 51 | starter_questions = None
|
16 | 52 | conversation_starters = os.getenv("CONVERSATION_STARTERS")
|
17 | 53 | if conversation_starters and conversation_starters.strip():
|
18 | 54 | starter_questions = conversation_starters.strip().split("\n")
|
19 | 55 | 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 |
|
0 commit comments