Skip to content

Commit

Permalink
Merge pull request #80 from tjmlabs/main-default-collection
Browse files Browse the repository at this point in the history
default collection -> default_collection
  • Loading branch information
Jonathan-Adly authored Nov 8, 2024
2 parents b4cf4e0 + 779498f commit 006a738
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ client = ColiVara(
base_url="https://api.colivara.com"
)

# Upload a document to the default collection
# Upload a document to the default_collection
document = client.upsert_document(
name="sample_document",
url="https://example.com/sample.pdf",
Expand Down
10 changes: 5 additions & 5 deletions web/api/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ async def test_create_document_pdf_url_await(async_client, user):
"metadata": {},
"url": "https://pdfobject.com/pdf/sample.pdf",
"num_pages": 1,
"collection_name": "default collection",
"collection_name": "default_collection",
"pages": None,
}

Expand Down Expand Up @@ -481,7 +481,7 @@ async def test_create_document_pdf_base64_await(async_client, user, collection):
assert response_data["name"] == "Test Document Fixture"
assert response_data["metadata"] == {}
assert response_data["num_pages"] == 1
assert response_data["collection_name"] == "default collection"
assert response_data["collection_name"] == "default_collection"
assert response_data["pages"] is None
await Document.objects.all().adelete()

Expand Down Expand Up @@ -688,7 +688,7 @@ async def test_get_document_by_name(async_client, user, collection, document):
async def test_get_document_by_name_multiple_documents(
async_client, user, collection, document
):
# first we create a new document with the same name under default collection
# first we create a new document with the same name under default_collection
response = await async_client.post(
"/documents/upsert-document/",
json={
Expand Down Expand Up @@ -784,7 +784,7 @@ async def test_patch_document_not_found(async_client, user, collection, document
async def test_patch_document_multiple_documents(
async_client, user, collection, document
):
# first we create a new document with the same name under default collection
# first we create a new document with the same name under default_collection
response = await async_client.post(
"/documents/upsert-document/",
json={
Expand Down Expand Up @@ -912,7 +912,7 @@ async def test_delete_document_not_found(async_client, user, collection, documen
async def test_delete_document_multiple_documents(
async_client, user, collection, document
):
# first we create a new document with the same name under default collection
# first we create a new document with the same name under default_collection
response = await async_client.post(
"/documents/upsert-document/",
json={
Expand Down
26 changes: 13 additions & 13 deletions web/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ class DocumentIn(Schema):
name: str
metadata: dict = Field(default_factory=dict)
collection_name: str = Field(
"default collection",
description="""The name of the collection to which the document belongs. If not provided, the document will be added to the default collection. Use 'all' to access all collections belonging to the user.""",
"default_collection",
description="""The name of the collection to which the document belongs. If not provided, the document will be added to the default_collection. Use 'all' to access all collections belonging to the user.""",
)
url: Optional[str] = None
base64: Optional[str] = None
Expand Down Expand Up @@ -349,8 +349,8 @@ class DocumentInPatch(Schema):
name: Optional[str] = None
metadata: Optional[dict] = Field(default_factory=dict)
collection_name: Optional[str] = Field(
"default collection",
description="""The name of the collection to which the document belongs. If not provided, the document will be added to the default collection. Use 'all' to access all collections belonging to the user.""",
"default_collection",
description="""The name of the collection to which the document belongs. If not provided, the document will be added to the default_collection. Use 'all' to access all collections belonging to the user.""",
)
url: Optional[str] = None
base64: Optional[str] = None
Expand Down Expand Up @@ -453,7 +453,7 @@ async def upsert_document(
This endpoint allows the user to create or update a document in a collection.
The document can be provided as a URL or a base64-encoded string.
if the collection is not provided, a collection named "default collection" will be used.
if the collection is not provided, a collection named "default_collection" will be used.
if the collection is provided, it will be created if it does not exist.
Args:
Expand All @@ -476,7 +476,7 @@ async def upsert_document(
"wait": true # optional, if true, the response will be sent after waiting for the document to be processed. Otherwise, it will be done asynchronously.
}
"""
# if the user didn't give a collection, payload.collection will be "default collection"
# if the user didn't give a collection, payload.collection will be "default_collection"
if payload.collection_name == "all":
return 400, GenericError(
detail="The collection name 'all' is not allowed when inserting or updating a document - only when retrieving. Please provide a valid collection name."
Expand All @@ -501,12 +501,12 @@ async def upsert_document(
async def get_document(
request: Request,
document_name: str,
collection_name: Optional[str] = "default collection",
collection_name: Optional[str] = "default_collection",
expand: Optional[str] = None,
) -> Tuple[int, DocumentOut] | Tuple[int, GenericError]:
"""
Retrieve a specific document from the user documents.
Default collection is "default collection".
Default collection is "default_collection".
To get all documents, use collection_name="all".
Args:
Expand Down Expand Up @@ -577,7 +577,7 @@ async def get_document(
)
async def list_documents(
request: Request,
collection_name: Optional[str] = "default collection",
collection_name: Optional[str] = "default_collection",
expand: Optional[str] = None,
) -> List[DocumentOut]:
"""
Expand All @@ -588,7 +588,7 @@ async def list_documents(
Args:
request (Request): The request object.
collection_name (Optional[str]): The name of the collection to fetch documents from. Defaults to "default collection". Use "all" to fetch documents from all collections.
collection_name (Optional[str]): The name of the collection to fetch documents from. Defaults to "default_collection". Use "all" to fetch documents from all collections.
expand (Optional[str]): A comma-separated string specifying additional fields to include in the response.
If "pages" is included, the pages of each document will be included.
Expand All @@ -599,7 +599,7 @@ async def list_documents(
HTTPException: If the collection or documents are not found.
Example:
GET /documents/?collection_name=default collection&expand=pages
GET /documents/?collection_name=default_collection&expand=pages
"""
expand_fields = expand.split(",") if expand else []

Expand Down Expand Up @@ -737,7 +737,7 @@ async def partial_update_document(
async def delete_document(
request: Request,
document_name: str,
collection_name: Optional[str] = "default collection",
collection_name: Optional[str] = "default_collection",
) -> Tuple[int, None] | Tuple[int, GenericError]:
"""
Delete a document by its Name.
Expand All @@ -747,7 +747,7 @@ async def delete_document(
Args:
request: The HTTP request object, which includes authentication information.
collection_name (name): The name of the collection containing the document. Defaults to "default collection". Use "all" to access all collections belonging to the user.
collection_name (name): The name of the collection containing the document. Defaults to "default_collection". Use "all" to access all collections belonging to the user.
document_name (int): The name of the document to be deleted.
Returns:
Expand Down

0 comments on commit 006a738

Please sign in to comment.