From 85e992990636123ace3788323f182c53e58c4efd Mon Sep 17 00:00:00 2001 From: Hamada Salhab Date: Thu, 3 Oct 2024 17:21:50 +0300 Subject: [PATCH 1/4] feat(agents-api): Add embeddings to doc get/list response (#578) --- agents-api/agents_api/autogen/Docs.py | 7 +++++++ agents-api/agents_api/models/docs/get_doc.py | 4 +++- agents-api/agents_api/models/docs/list_docs.py | 4 +++- cozo.db | Bin 0 -> 12288 bytes typespec/docs/models.tsp | 4 ++++ 5 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 cozo.db diff --git a/agents-api/agents_api/autogen/Docs.py b/agents-api/agents_api/autogen/Docs.py index a7023ddfc..0c1524e48 100644 --- a/agents-api/agents_api/autogen/Docs.py +++ b/agents-api/agents_api/autogen/Docs.py @@ -57,6 +57,13 @@ class Doc(BaseModel): """ Contents of the document """ + embeddings: Annotated[ + list[float] | list[list[float]] | None, + Field(None, json_schema_extra={"readOnly": True}), + ] + """ + Embeddings for the document + """ class DocOwner(BaseModel): diff --git a/agents-api/agents_api/models/docs/get_doc.py b/agents-api/agents_api/models/docs/get_doc.py index 84cd181ec..4b3996c27 100644 --- a/agents-api/agents_api/models/docs/get_doc.py +++ b/agents-api/agents_api/models/docs/get_doc.py @@ -37,6 +37,7 @@ one=True, transform=lambda d: { "content": [s[1] for s in sorted(d["snippet_data"], key=lambda x: x[0])], + "embeddings": [s[2] for s in sorted(d["snippet_data"], key=lambda x: x[0])], **d, }, ) @@ -68,8 +69,9 @@ def get_doc( doc_id, index, content, + embedding, }, - snippet_data = [index, content] + snippet_data = [index, content, embedding] ?[ id, diff --git a/agents-api/agents_api/models/docs/list_docs.py b/agents-api/agents_api/models/docs/list_docs.py index afdf06c2d..3c095c2db 100644 --- a/agents-api/agents_api/models/docs/list_docs.py +++ b/agents-api/agents_api/models/docs/list_docs.py @@ -34,6 +34,7 @@ Doc, transform=lambda d: { "content": [s[1] for s in sorted(d["snippet_data"], key=lambda x: x[0])], + "embeddings": [s[2] for s in sorted(d["snippet_data"], key=lambda x: x[0])], **d, }, ) @@ -67,8 +68,9 @@ def list_docs( doc_id: id, index, content, + embedding, }}, - snippet_data = [index, content] + snippet_data = [index, content, embedding] ?[ owner_type, diff --git a/cozo.db b/cozo.db new file mode 100644 index 0000000000000000000000000000000000000000..b1bc4a7a55dbc3c8ce20447660fa024c727354b6 GIT binary patch literal 12288 zcmeI1&ubGw6vt(OKmZ5; z0U!VbfB+Bx0zd!=00AHX1pY??u5x5-bW~|v;p8@>mVeKeBQ;gZWz3vzX0nBxEf00e*l5C8%|00;m9AOHmZfWX5gb;x`)o@5Ni zZI|m*wnHM?F_(DTq(Va}e|_BYh)Z855lMj5R~=jFx|9=}aMEmv)-PIl5Qo1Mza=AW zOgMIy&JyO>4zG8;Dr2(k-0azOo>Upf73wwCGeN-W%~e0>7}s$j zUp8ALtVB=t2wfq}6bz#jD=T}HwotC!Ec}om{YB$e>|buIPx)TN8*4Sf8f(R>+gQtc z{GIxFpU}$sKHKVgzK3OTPj`wFWgjf4UFM-Ea8SFkA-NDJOH_t^)eW}Nyh24!!BP(2Z2iJj5>WRxozbqF95y+TBv2x literal 0 HcmV?d00001 diff --git a/typespec/docs/models.tsp b/typespec/docs/models.tsp index ee283fe02..f01b379c6 100644 --- a/typespec/docs/models.tsp +++ b/typespec/docs/models.tsp @@ -23,6 +23,10 @@ model Doc { /** Contents of the document */ content: string | string[]; + + /** Embeddings for the document */ + @visibility("read") + embeddings?: float32[] | float32[][]; } /** Payload for creating a doc */ From 3ad19260b4bb8da6b839243d3393030dcba405e3 Mon Sep 17 00:00:00 2001 From: Hamada Salhab Date: Thu, 3 Oct 2024 21:01:59 +0300 Subject: [PATCH 2/4] Delete cozo.db This was uploaded by mistake --- cozo.db | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 cozo.db diff --git a/cozo.db b/cozo.db deleted file mode 100644 index b1bc4a7a55dbc3c8ce20447660fa024c727354b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI1&ubGw6vt(OKmZ5; z0U!VbfB+Bx0zd!=00AHX1pY??u5x5-bW~|v;p8@>mVeKeBQ;gZWz3vzX0nBxEf00e*l5C8%|00;m9AOHmZfWX5gb;x`)o@5Ni zZI|m*wnHM?F_(DTq(Va}e|_BYh)Z855lMj5R~=jFx|9=}aMEmv)-PIl5Qo1Mza=AW zOgMIy&JyO>4zG8;Dr2(k-0azOo>Upf73wwCGeN-W%~e0>7}s$j zUp8ALtVB=t2wfq}6bz#jD=T}HwotC!Ec}om{YB$e>|buIPx)TN8*4Sf8f(R>+gQtc z{GIxFpU}$sKHKVgzK3OTPj`wFWgjf4UFM-Ea8SFkA-NDJOH_t^)eW}Nyh24!!BP(2Z2iJj5>WRxozbqF95y+TBv2x From 4992615da5d702956fc9dd8f29d90cf1f4bad96f Mon Sep 17 00:00:00 2001 From: Diwank Singh Tomer Date: Fri, 4 Oct 2024 05:31:42 +0530 Subject: [PATCH 3/4] Update lint-and-format.yml --- .github/workflows/lint-and-format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-format.yml b/.github/workflows/lint-and-format.yml index 65e4983c4..ab74c7e9b 100644 --- a/.github/workflows/lint-and-format.yml +++ b/.github/workflows/lint-and-format.yml @@ -37,7 +37,7 @@ jobs: uses: actions/cache@v4 with: path: agents-api/.pytype - key: ${{ runner.os }}-agents-api-pytype-${{ hashFiles('agents-api/**/*.py') }} + key: ${{ runner.os }}-agents-api-pytype- restore-keys: | ${{ runner.os }}-agents-api-pytype- From 9c38da1a42c29da7218dac9696b1d67d9ced2538 Mon Sep 17 00:00:00 2001 From: Vivek Gurudutt K <127002789+VivekGuruduttK28@users.noreply.github.com> Date: Fri, 4 Oct 2024 05:40:54 +0530 Subject: [PATCH 4/4] Enhanced the error messages (#575) This PR is to fix the issue mentioned in #572 I have made the required changes in the files create_agent.py, create_or_update_agent.py and delete_agent.py. I have added descriptions to QueryException, ValidationError and TypeError. ---- > [!IMPORTANT] > Enhanced error messages for exceptions in agent-related files to provide detailed guidance on potential issues. > > - **Error Messages**: > - Enhanced error messages for `QueryException`, `ValidationError`, and `TypeError` in `create_agent.py`, `create_or_update_agent.py`, and `delete_agent.py`. > - `QueryException`: Now includes a detailed message about potential causes related to database query failures. > - `ValidationError`: Provides guidance on checking input data for missing or incorrect fields. > - `TypeError`: Describes type mismatch issues and suggests reviewing input data types. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral) for 049d7eea196b74158e4fc4d83049656c7e7fa12e. It will automatically update as commits are pushed. Co-authored-by: Diwank Singh Tomer --- agents-api/agents_api/models/agent/create_agent.py | 6 +++--- .../agents_api/models/agent/create_or_update_agent.py | 6 +++--- agents-api/agents_api/models/agent/delete_agent.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/agents-api/agents_api/models/agent/create_agent.py b/agents-api/agents_api/models/agent/create_agent.py index 73be4ec77..546d0d441 100644 --- a/agents-api/agents_api/models/agent/create_agent.py +++ b/agents-api/agents_api/models/agent/create_agent.py @@ -32,9 +32,9 @@ in str(e): lambda *_: HTTPException( detail="developer not found", status_code=403 ), - QueryException: partialclass(HTTPException, status_code=400), - ValidationError: partialclass(HTTPException, status_code=400), - TypeError: partialclass(HTTPException, status_code=400), + QueryException: partialclass(HTTPException, status_code=400, detail="A database query failed to return the expected results. This might occur if the requested resource doesn't exist or your query parameters are incorrect."), + ValidationError: partialclass(HTTPException, status_code=400, detail="Input validation failed. Please check the provided data for missing or incorrect fields, and ensure it matches the required format."), + TypeError: partialclass(HTTPException, status_code=400, detail="A type mismatch occurred. This likely means the data provided is of an incorrect type (e.g., string instead of integer). Please review the input and try again."), } ) @wrap_in_class( diff --git a/agents-api/agents_api/models/agent/create_or_update_agent.py b/agents-api/agents_api/models/agent/create_or_update_agent.py index 156c8ae61..17e01fccb 100644 --- a/agents-api/agents_api/models/agent/create_or_update_agent.py +++ b/agents-api/agents_api/models/agent/create_or_update_agent.py @@ -27,9 +27,9 @@ @rewrap_exceptions( { - QueryException: partialclass(HTTPException, status_code=400), - ValidationError: partialclass(HTTPException, status_code=400), - TypeError: partialclass(HTTPException, status_code=400), + QueryException: partialclass(HTTPException, status_code=400,detail="A database query failed to return the expected results. This might occur if the requested resource doesn't exist or your query parameters are incorrect."), + ValidationError: partialclass(HTTPException, status_code=400,detail="Input validation failed. Please check the provided data for missing or incorrect fields, and ensure it matches the required format."), + TypeError: partialclass(HTTPException, status_code=400,detail="A type mismatch occurred. This likely means the data provided is of an incorrect type (e.g., string instead of integer). Please review the input and try again."), } ) @wrap_in_class( diff --git a/agents-api/agents_api/models/agent/delete_agent.py b/agents-api/agents_api/models/agent/delete_agent.py index 926007bdf..cb6b16718 100644 --- a/agents-api/agents_api/models/agent/delete_agent.py +++ b/agents-api/agents_api/models/agent/delete_agent.py @@ -32,9 +32,9 @@ in e.resp["display"]: lambda *_: HTTPException( detail="developer not found or doesnt own resource", status_code=404 ), - QueryException: partialclass(HTTPException, status_code=400), - ValidationError: partialclass(HTTPException, status_code=400), - TypeError: partialclass(HTTPException, status_code=400), + QueryException: partialclass(HTTPException, status_code=400,detail="A database query failed to return the expected results. This might occur if the requested resource doesn't exist or your query parameters are incorrect."), + ValidationError: partialclass(HTTPException, status_code=400,detail="Input validation failed. Please check the provided data for missing or incorrect fields, and ensure it matches the required format."), + TypeError: partialclass(HTTPException, status_code=400,detail="A type mismatch occurred. This likely means the data provided is of an incorrect type (e.g., string instead of integer). Please review the input and try again."), } ) @wrap_in_class(