diff --git a/CHANGELOG.md b/CHANGELOG.md index 49dba6bb5..42507c9c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add sql table length exceed limit and uuid truncation. - Add ci workflow to test templates - Add deploy flag in model. +- Modify the apply endpoint in the REST API to an asynchronous interface. #### Bug Fixes diff --git a/superduper/base/config_settings.py b/superduper/base/config_settings.py index 108510bf1..3bd8a78db 100644 --- a/superduper/base/config_settings.py +++ b/superduper/base/config_settings.py @@ -18,10 +18,7 @@ USER_CONFIG: str = ( str(Path(CONFIG_FILE).expanduser()) if CONFIG_FILE - else ( - f'{HOME}/.superduper/config.yaml' if HOME - else None - ) + else (f'{HOME}/.superduper/config.yaml' if HOME else None) ) PREFIX = 'SUPERDUPER_' ROOT = Path(__file__).parents[2] diff --git a/superduper/rest/build.py b/superduper/rest/build.py index 8c6029ff2..c1550bbbb 100644 --- a/superduper/rest/build.py +++ b/superduper/rest/build.py @@ -12,7 +12,7 @@ import magic except ImportError: magic = None -from fastapi import File, Response +from fastapi import BackgroundTasks, File, Response from fastapi.responses import JSONResponse from superduper import logging @@ -158,7 +158,10 @@ def test_log(): os.remove(log_file) return {'status': 'ok'} - def _process_db_apply(db, info): + def _process_db_apply(db, component): + db.apply(component, force=True) + + def _process_apply_info(db, info): if '_variables' in info: assert {'_variables', 'identifier'}.issubset(info.keys()) variables = info.pop('_variables') @@ -177,25 +180,28 @@ def _process_db_apply(db, info): db=db, **variables, ) - db.apply(component, force=True) - return {'status': 'ok'} + return component component = Document.decode(info, db=db).unpack() # TODO this shouldn't be necessary to do twice component.unpack() - db.apply(component, force=True) - return {'status': 'ok'} + return component @app.add('/db/apply', method='post') - def db_apply( - info: t.Dict, id: str | None = 'test', db: 'Datalayer' = DatalayerDependency() + async def db_apply( + info: t.Dict, + background_tasks: BackgroundTasks, + id: str | None = 'test', + db: 'Datalayer' = DatalayerDependency(), ): if id: log_file = f"/tmp/{id}.log" with redirect_stdout_to_file(log_file): - out = _process_db_apply(db, info) + component = _process_apply_info(db, info) + background_tasks.add_task(_process_db_apply, db, component) else: - out = _process_db_apply(db, info) - return out + component = _process_apply_info(db, info) + background_tasks.add_task(_process_db_apply, db, component) + return {'status': 'ok'} import subprocess import time diff --git a/templates/llm_finetuning/blobs/913bc7838286b1f1fa6f4f90969bd9acf4dc205f b/templates/llm_finetuning/blobs/913bc7838286b1f1fa6f4f90969bd9acf4dc205f deleted file mode 100644 index b67e3f6bc..000000000 Binary files a/templates/llm_finetuning/blobs/913bc7838286b1f1fa6f4f90969bd9acf4dc205f and /dev/null differ diff --git a/templates/llm_finetuning/blobs/9b3571624545e73567685b3cd0ce8b031dc784c7 b/templates/llm_finetuning/blobs/9b3571624545e73567685b3cd0ce8b031dc784c7 new file mode 100644 index 000000000..3d9b991af Binary files /dev/null and b/templates/llm_finetuning/blobs/9b3571624545e73567685b3cd0ce8b031dc784c7 differ diff --git a/templates/llm_finetuning/blobs/a026ecb590e04810d1e0f9d4ef7195e74c3614c3 b/templates/llm_finetuning/blobs/a026ecb590e04810d1e0f9d4ef7195e74c3614c3 new file mode 100644 index 000000000..d4fb309d5 Binary files /dev/null and b/templates/llm_finetuning/blobs/a026ecb590e04810d1e0f9d4ef7195e74c3614c3 differ diff --git a/templates/llm_finetuning/build.ipynb b/templates/llm_finetuning/build.ipynb index 365c581f7..6ecf06fd6 100644 --- a/templates/llm_finetuning/build.ipynb +++ b/templates/llm_finetuning/build.ipynb @@ -297,15 +297,17 @@ "metadata": {}, "outputs": [], "source": [ - "from superduper import Template, Table, Schema\n", + "from superduper import Template, Table, Schema, Application\n", "from superduper.components.dataset import RemoteData\n", "\n", "llm.trainer.use_lora = \"\"\n", "llm.trainer.num_train_epochs = \"\"\n", "\n", + "app = Application(identifier=\"llm\", components=[llm])\n", + "\n", "t = Template(\n", " 'llm-finetune',\n", - " template=llm,\n", + " template=app,\n", " substitutions={\n", " TABLE_NAME: 'table_name',\n", " model_name: 'model_name',\n", @@ -400,7 +402,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/templates/llm_finetuning/component.json b/templates/llm_finetuning/component.json index 84f07680b..f6afc5e94 100644 --- a/templates/llm_finetuning/component.json +++ b/templates/llm_finetuning/component.json @@ -24,11 +24,11 @@ "method": "dill", "encodable": "artifact" }, - "913bc7838286b1f1fa6f4f90969bd9acf4dc205f": { + "a026ecb590e04810d1e0f9d4ef7195e74c3614c3": { "_path": "superduper.components.datatype.Artifact", "datatype": "?datatype:dill", "uri": null, - "blob": "&:blob:913bc7838286b1f1fa6f4f90969bd9acf4dc205f" + "blob": "&:blob:a026ecb590e04810d1e0f9d4ef7195e74c3614c3" }, "dataset:llm_finetuning": { "_path": "superduper.components.dataset.RemoteData", @@ -36,7 +36,7 @@ "plugins": null, "cache": true, "status": null, - "getter": "?913bc7838286b1f1fa6f4f90969bd9acf4dc205f" + "getter": "?a026ecb590e04810d1e0f9d4ef7195e74c3614c3" }, "table:sample_llm_finetuning": { "_path": "superduper.components.table.Table", @@ -236,7 +236,7 @@ "uri": null, "blob": "&:blob:4a8dc14137b3a79a81256a795b266fe82bda52d9" }, - "llm": { + "model:llm": { "_path": "superduper_transformers.model.LLM", "upstream": null, "plugins": null, @@ -253,6 +253,7 @@ "num_workers": 0, "serve": false, "trainer": "?trainer:llm-finetune-trainer", + "deploy": false, "prompt": "{input}", "prompt_func": null, "max_batch_size": 4, @@ -261,6 +262,21 @@ "model_kwargs": "?4a8dc14137b3a79a81256a795b266fe82bda52d9", "tokenizer_kwargs": "?4a8dc14137b3a79a81256a795b266fe82bda52d9", "prompt_template": "{input}" + }, + "llm": { + "_path": "superduper.components.application.Application", + "upstream": null, + "plugins": null, + "cache": true, + "status": null, + "components": [ + "?model:llm" + ], + "namespace": null, + "link": null, + "_literals": [ + "template" + ] } } }, @@ -268,8 +284,7 @@ "table_name", "model_name", "use_lora", - "num_train_epochs", - "output_prefix" + "num_train_epochs" ], "types": { "collection": { diff --git a/templates/simple_rag/blobs/039aed30ddb0b6d251775302b5055579eec0c7f8 b/templates/simple_rag/blobs/039aed30ddb0b6d251775302b5055579eec0c7f8 new file mode 100644 index 000000000..d7fb17f0d Binary files /dev/null and b/templates/simple_rag/blobs/039aed30ddb0b6d251775302b5055579eec0c7f8 differ diff --git a/templates/simple_rag/blobs/3cf26512c472a982bfddddd931f59a82c03f74e9 b/templates/simple_rag/blobs/3cf26512c472a982bfddddd931f59a82c03f74e9 deleted file mode 100644 index 41a9d6880..000000000 Binary files a/templates/simple_rag/blobs/3cf26512c472a982bfddddd931f59a82c03f74e9 and /dev/null differ diff --git a/templates/simple_rag/blobs/60ca8cae14f69a82da08cb69135b087ad78d5203 b/templates/simple_rag/blobs/60ca8cae14f69a82da08cb69135b087ad78d5203 new file mode 100644 index 000000000..c1042289e Binary files /dev/null and b/templates/simple_rag/blobs/60ca8cae14f69a82da08cb69135b087ad78d5203 differ diff --git a/templates/simple_rag/blobs/adc059378de6bb27a2f6b02b8bf0e92f2c97e1e8 b/templates/simple_rag/blobs/adc059378de6bb27a2f6b02b8bf0e92f2c97e1e8 deleted file mode 100644 index 1f0e79be9..000000000 Binary files a/templates/simple_rag/blobs/adc059378de6bb27a2f6b02b8bf0e92f2c97e1e8 and /dev/null differ diff --git a/templates/simple_rag/build.ipynb b/templates/simple_rag/build.ipynb index 31b8a1cfb..b366c056e 100644 --- a/templates/simple_rag/build.ipynb +++ b/templates/simple_rag/build.ipynb @@ -527,7 +527,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/templates/simple_rag/component.json b/templates/simple_rag/component.json index 4048a3336..f64bb7b78 100644 --- a/templates/simple_rag/component.json +++ b/templates/simple_rag/component.json @@ -20,11 +20,11 @@ "method": "dill", "encodable": "artifact" }, - "3cf26512c472a982bfddddd931f59a82c03f74e9": { + "60ca8cae14f69a82da08cb69135b087ad78d5203": { "_path": "superduper.components.datatype.Artifact", "datatype": "?datatype:dill", "uri": null, - "blob": "&:blob:3cf26512c472a982bfddddd931f59a82c03f74e9" + "blob": "&:blob:60ca8cae14f69a82da08cb69135b087ad78d5203" }, "dataset:superduper-docs": { "_path": "superduper.components.dataset.RemoteData", @@ -32,7 +32,7 @@ "plugins": null, "cache": true, "status": null, - "getter": "?3cf26512c472a982bfddddd931f59a82c03f74e9" + "getter": "?60ca8cae14f69a82da08cb69135b087ad78d5203" }, "table:sample_simple_rag": { "_path": "superduper.components.table.Table", @@ -58,14 +58,14 @@ "method": "dill", "encodable": "artifact" }, - "adc059378de6bb27a2f6b02b8bf0e92f2c97e1e8": { + "039aed30ddb0b6d251775302b5055579eec0c7f8": { "_path": "superduper.components.datatype.Artifact", "datatype": "?datatype:dill", "uri": null, - "blob": "&:blob:adc059378de6bb27a2f6b02b8bf0e92f2c97e1e8" + "blob": "&:blob:039aed30ddb0b6d251775302b5055579eec0c7f8" }, "model:chunker": { - "_object": "?adc059378de6bb27a2f6b02b8bf0e92f2c97e1e8", + "_object": "?039aed30ddb0b6d251775302b5055579eec0c7f8", "upstream": null, "plugins": null, "cache": true, @@ -81,12 +81,13 @@ "num_workers": 0, "serve": false, "trainer": null, + "deploy": false, "chunk_size": 200 }, - "-select-id-x": { + "var-table-name-select-var-id-field-x": { "_path": "superduper_.query.parse_query", "documents": [], - "query": ".select(\"id\", \"x\")" + "query": ".select(\"\", \"x\")" }, "listener:chunker": { "_path": "superduper.components.listener.Listener", @@ -98,7 +99,7 @@ "key": "x", "model": "?model:chunker", "predict_kwargs": {}, - "select": "?-select-id-x", + "select": "?var-table-name-select-var-id-field-x", "flatten": true }, "datatype:sqlvector[1536]": { @@ -124,6 +125,7 @@ "num_workers": 0, "serve": false, "trainer": null, + "deploy": false, "model": "text-embedding-ada-002", "max_batch_size": 8, "openai_api_key": null, @@ -193,6 +195,7 @@ "num_workers": 0, "serve": false, "trainer": null, + "deploy": false, "model": "gpt-4-turbo", "max_batch_size": 8, "openai_api_key": null, @@ -218,6 +221,7 @@ "num_workers": 0, "serve": false, "trainer": null, + "deploy": false, "prompt_template": "Use the following context snippets, these snippets are not ordered!, Answer the question based on this context.\nThese snippets are samples from our internal data-repositories, and should be used exclusively and as a matter of priority to answer the question\n\n{context}\n\nHere's the question: {query}", "select": "?outputs-chunker-?(listener:chunker.uuid)-select-like-outputs-chunker-?(listener:chunker.uuid)-var-query-vector-index-vectorindex-n-5", "key": "chunker__?(listener:chunker.uuid)",