Skip to content

Commit

Permalink
feat: use poetry run generate (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcus Schiesser <[email protected]>
  • Loading branch information
thucpn and marcusschiesser authored Apr 9, 2024
1 parent 753229d commit 6acccd2
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-tools-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Use poetry run generate to generate embeddings for FastAPI
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Then re-start your app. Remember you'll need to re-run `generate` if you add new
If you're using the Python backend, you can trigger indexing of your data by calling:

```bash
poetry run python app/engine/generate.py
poetry run generate
```

## Want a front-end?
Expand Down
4 changes: 2 additions & 2 deletions helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function generateContextData(
if (packageManager) {
const runGenerate = `${cyan(
framework === "fastapi"
? "poetry run python app/engine/generate.py"
? "poetry run generate"
: `${packageManager} run generate`,
)}`;
const openAiKeyConfigured = openAiKey || process.env["OPENAI_API_KEY"];
Expand All @@ -46,7 +46,7 @@ async function generateContextData(
if (framework === "fastapi") {
if (isHavingPoetryLockFile()) {
console.log(`Running ${runGenerate} to generate the context data.`);
const result = tryPoetryRun("python app/engine/generate.py");
const result = tryPoetryRun("poetry run generate");
if (!result) {
console.log(`Failed to run ${runGenerate}.`);
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion helpers/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async function updatePackageJson({
packageJson.name = appName;
packageJson.version = "0.1.0";

if (dataSources.length > 0 && relativeEngineDestPath) {
if (relativeEngineDestPath) {
// TODO: move script to {root}/scripts for all frameworks
// add generate script if using context engine
packageJson.scripts = {
Expand Down
2 changes: 1 addition & 1 deletion templates/components/engines/python/chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_chat_engine():
index = get_index()
if index is None:
raise Exception(
"StorageContext is empty - call 'python app/engine/generate.py' to generate the storage first"
"StorageContext is empty - call 'poetry run generate' to generate the storage first"
)

return index.as_chat_engine(
Expand Down
2 changes: 1 addition & 1 deletion templates/components/vectordbs/python/astra/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


def generate_datasource():
init_settings()
logger.info("Creating new index")
documents = get_documents()
store = AstraDBVectorStore(
Expand All @@ -33,5 +34,4 @@ def generate_datasource():


if __name__ == "__main__":
init_settings()
generate_datasource()
2 changes: 1 addition & 1 deletion templates/components/vectordbs/python/milvus/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


def generate_datasource():
init_settings()
logger.info("Creating new index")
# load the documents and create the index
documents = get_documents()
Expand All @@ -35,5 +36,4 @@ def generate_datasource():


if __name__ == "__main__":
init_settings()
generate_datasource()
2 changes: 1 addition & 1 deletion templates/components/vectordbs/python/mongo/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


def generate_datasource():
init_settings()
logger.info("Creating new index")
# load the documents and create the index
documents = get_documents()
Expand All @@ -39,5 +40,4 @@ def generate_datasource():


if __name__ == "__main__":
init_settings()
generate_datasource()
2 changes: 1 addition & 1 deletion templates/components/vectordbs/python/none/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


def generate_datasource():
init_settings()
logger.info("Creating new index")
# load the documents and create the index
documents = get_documents()
Expand All @@ -28,5 +29,4 @@ def generate_datasource():


if __name__ == "__main__":
init_settings()
generate_datasource()
2 changes: 1 addition & 1 deletion templates/components/vectordbs/python/pg/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


def generate_datasource():
init_settings()
logger.info("Creating new index")
# load the documents and create the index
documents = get_documents()
Expand All @@ -31,5 +32,4 @@ def generate_datasource():


if __name__ == "__main__":
init_settings()
generate_datasource()
2 changes: 1 addition & 1 deletion templates/components/vectordbs/python/pinecone/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


def generate_datasource():
init_settings()
logger.info("Creating new index")
# load the documents and create the index
documents = get_documents()
Expand All @@ -35,5 +36,4 @@ def generate_datasource():


if __name__ == "__main__":
init_settings()
generate_datasource()
4 changes: 2 additions & 2 deletions templates/types/streaming/fastapi/README-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you are using any tools or data sources, you can update their config files in
Second, generate the embeddings of the documents in the `./data` directory (if this folder exists - otherwise, skip this step):

```
python app/engine/generate.py
poetry run generate
```

Third, run the development server:
Expand Down Expand Up @@ -84,7 +84,7 @@ docker run \
-v $(pwd)/data:/app/data \ # Use your local folder to read the data
-v $(pwd)/storage:/app/storage \ # Use your file system to store the vector database
<your_backend_image_name> \
python app/engine/generate.py
poetry run generate
```

3. Start the API:
Expand Down
3 changes: 3 additions & 0 deletions templates/types/streaming/fastapi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ description = ""
authors = ["Marcus Schiesser <[email protected]>"]
readme = "README.md"

[tool.poetry.scripts]
generate = "app.engine.generate:generate_datasource"

[tool.poetry.dependencies]
python = "^3.11,<3.12"
fastapi = "^0.109.1"
Expand Down

0 comments on commit 6acccd2

Please sign in to comment.