From fafbd8c9c7def367188e62d61feaf67280c56f9d Mon Sep 17 00:00:00 2001
From: "Huu Le (Lee)" <39040748+leehuwuj@users.noreply.github.com>
Date: Wed, 13 Mar 2024 09:08:53 +0700
Subject: [PATCH] fix: add missing env value; improve docs and error message
 (#638)

---
 .changeset/hot-windows-watch.md                             | 5 +++++
 packages/create-llama/create-app.ts                         | 4 ++--
 packages/create-llama/helpers/env-variables.ts              | 1 +
 packages/create-llama/index.ts                              | 2 +-
 .../templates/types/simple/fastapi/README-template.md       | 6 ++++--
 .../create-llama/templates/types/simple/fastapi/main.py     | 3 ++-
 .../templates/types/streaming/fastapi/README-template.md    | 6 ++++--
 .../create-llama/templates/types/streaming/fastapi/main.py  | 3 ++-
 8 files changed, 21 insertions(+), 9 deletions(-)
 create mode 100644 .changeset/hot-windows-watch.md

diff --git a/.changeset/hot-windows-watch.md b/.changeset/hot-windows-watch.md
new file mode 100644
index 000000000..0020daf70
--- /dev/null
+++ b/.changeset/hot-windows-watch.md
@@ -0,0 +1,5 @@
+---
+"create-llama": patch
+---
+
+fix missing .env value, improve docs and error message
diff --git a/packages/create-llama/create-app.ts b/packages/create-llama/create-app.ts
index f59a9e9a6..8d6ce9c50 100644
--- a/packages/create-llama/create-app.ts
+++ b/packages/create-llama/create-app.ts
@@ -116,14 +116,14 @@ export async function createApp({
     await installTemplate({ ...args, backend: true });
   }
 
+  await writeDevcontainer(root, templatesDir, framework, frontend);
+
   process.chdir(root);
   if (tryGitInit(root)) {
     console.log("Initialized a git repository.");
     console.log();
   }
 
-  await writeDevcontainer(root, templatesDir, framework, frontend);
-
   if (toolsRequireConfig(tools)) {
     console.log(
       yellow(
diff --git a/packages/create-llama/helpers/env-variables.ts b/packages/create-llama/helpers/env-variables.ts
index 20d4cb7d9..f9f6d370a 100644
--- a/packages/create-llama/helpers/env-variables.ts
+++ b/packages/create-llama/helpers/env-variables.ts
@@ -199,6 +199,7 @@ Given this information, please answer the question: {query_str}
               name: "NEXT_PUBLIC_MODEL",
               description:
                 "The LLM model to use (hardcode to front-end artifact).",
+              value: opts.model || "gpt-3.5-turbo",
             }
           : {},
       ],
diff --git a/packages/create-llama/index.ts b/packages/create-llama/index.ts
index 47e78c26a..131d6eba2 100644
--- a/packages/create-llama/index.ts
+++ b/packages/create-llama/index.ts
@@ -315,7 +315,7 @@ Got error: ${(error as Error).message}.\n`,
         ),
       );
       console.log(
-        `Make sure you have VSCode installed and added to your PATH. 
+        `Make sure you have VSCode installed and added to your PATH (shell alias will not work). 
 Please check ${cyan(
           terminalLink(
             "This documentation",
diff --git a/packages/create-llama/templates/types/simple/fastapi/README-template.md b/packages/create-llama/templates/types/simple/fastapi/README-template.md
index 38f3c4a3f..b1a35c42e 100644
--- a/packages/create-llama/templates/types/simple/fastapi/README-template.md
+++ b/packages/create-llama/templates/types/simple/fastapi/README-template.md
@@ -2,7 +2,9 @@ This is a [LlamaIndex](https://www.llamaindex.ai/) project using [FastAPI](https
 
 ## Getting Started
 
-First, setup the environment:
+First, setup the environment with poetry:
+
+> **_Note:_** This step is not needed if you are using the dev-container.
 
 ```
 poetry install
@@ -44,7 +46,7 @@ Open [http://localhost:8000/docs](http://localhost:8000/docs) with your browser
 The API allows CORS for all origins to simplify development. You can change this behavior by setting the `ENVIRONMENT` environment variable to `prod`:
 
 ```
-ENVIRONMENT=prod uvicorn main:app
+ENVIRONMENT=prod python main.py
 ```
 
 ## Learn More
diff --git a/packages/create-llama/templates/types/simple/fastapi/main.py b/packages/create-llama/templates/types/simple/fastapi/main.py
index 691f543d6..41721a8f2 100644
--- a/packages/create-llama/templates/types/simple/fastapi/main.py
+++ b/packages/create-llama/templates/types/simple/fastapi/main.py
@@ -34,5 +34,6 @@ app.include_router(chat_router, prefix="/api/chat")
 if __name__ == "__main__":
     app_host = os.getenv("APP_HOST", "0.0.0.0")
     app_port = int(os.getenv("APP_PORT", "8000"))
+    reload = True if environment == "dev" else False
 
-    uvicorn.run(app="main:app", host=app_host, port=app_port, reload=True)
+    uvicorn.run(app="main:app", host=app_host, port=app_port, reload=reload)
diff --git a/packages/create-llama/templates/types/streaming/fastapi/README-template.md b/packages/create-llama/templates/types/streaming/fastapi/README-template.md
index fdbb73a15..35ef1125a 100644
--- a/packages/create-llama/templates/types/streaming/fastapi/README-template.md
+++ b/packages/create-llama/templates/types/streaming/fastapi/README-template.md
@@ -2,7 +2,9 @@ This is a [LlamaIndex](https://www.llamaindex.ai/) project using [FastAPI](https
 
 ## Getting Started
 
-First, setup the environment:
+First, setup the environment with poetry:
+
+> **_Note:_** This step is not needed if you are using the dev-container.
 
 ```
 poetry install
@@ -44,7 +46,7 @@ Open [http://localhost:8000/docs](http://localhost:8000/docs) with your browser
 The API allows CORS for all origins to simplify development. You can change this behavior by setting the `ENVIRONMENT` environment variable to `prod`:
 
 ```
-ENVIRONMENT=prod uvicorn main:app
+ENVIRONMENT=prod python main.py
 ```
 
 ## Learn More
diff --git a/packages/create-llama/templates/types/streaming/fastapi/main.py b/packages/create-llama/templates/types/streaming/fastapi/main.py
index 7e7d42496..edba3d3a7 100644
--- a/packages/create-llama/templates/types/streaming/fastapi/main.py
+++ b/packages/create-llama/templates/types/streaming/fastapi/main.py
@@ -35,5 +35,6 @@ app.include_router(chat_router, prefix="/api/chat")
 if __name__ == "__main__":
     app_host = os.getenv("APP_HOST", "0.0.0.0")
     app_port = int(os.getenv("APP_PORT", "8000"))
+    reload = True if environment == "dev" else False
 
-    uvicorn.run(app="main:app", host=app_host, port=app_port, reload=True)
+    uvicorn.run(app="main:app", host=app_host, port=app_port, reload=reload)
-- 
GitLab