diff --git a/poetry.lock b/poetry.lock index 6e391d0..6a8c4dd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -60,15 +60,18 @@ files = [ [[package]] name = "exceptiongroup" -version = "1.2.2" +version = "1.3.0" description = "Backport of PEP 654 (exception groups)" optional = false python-versions = ">=3.7" files = [ - {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"}, - {file = "exceptiongroup-1.2.2.tar.gz", hash = "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc"}, + {file = "exceptiongroup-1.3.0-py3-none-any.whl", hash = "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10"}, + {file = "exceptiongroup-1.3.0.tar.gz", hash = "sha256:b241f5885f560bc56a59ee63ca4c6a8bfa46ae4ad651af316d4e81817bb9fd88"}, ] +[package.dependencies] +typing-extensions = {version = ">=4.6.0", markers = "python_version < \"3.13\""} + [package.extras] test = ["pytest (>=6)"] diff --git a/pyproject.toml b/pyproject.toml index 9297bf3..b376130 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "credal" [tool.poetry] name = "credal" -version = "0.0.27" +version = "0.0.28" description = "" readme = "README.md" authors = [] diff --git a/reference.md b/reference.md index 4c8eb04..2d99608 100644 --- a/reference.md +++ b/reference.md @@ -29,8 +29,20 @@ Create a new agent. The API key used will be added to the agent for future Reque ```python from credal import CredalApi from credal.common import Collaborator -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.create_copilot(name='Customer Agent', description='This agent is used to answer customer requests based on internal documentation.', collaborators=[Collaborator(email='test@gmail.com', role="editor", )], ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.create_copilot( + name="Customer Agent", + description="This agent is used to answer customer requests based on internal documentation.", + collaborators=[ + Collaborator( + email="test@gmail.com", + role="editor", + ) + ], +) ``` @@ -109,10 +121,19 @@ OPTIONAL. Create a new conversation with the Agent. The conversation ID can be u
```python -from credal import CredalApi import uuid -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.create_conversation(agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), user_email='ravin@credal.ai', ) + +from credal import CredalApi + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.create_conversation( + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + user_email="ravin@credal.ai", +) ```
@@ -169,11 +190,28 @@ client.copilots.create_conversation(agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-
```python -from credal import CredalApi import uuid + +from credal import CredalApi from credal.copilots import MessageFeedback -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.provide_message_feedback(user_email='ravin@credal.ai', message_id=uuid.UUID("dd721cd8-4bf2-4b94-9869-258df3dab9dc", ), agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message_feedback=MessageFeedback(feedback="NEGATIVE", suggested_answer='Yes, Credal is SOC 2 compliant.', descriptive_feedback='The response should be extremely clear and concise.', ), ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.provide_message_feedback( + user_email="ravin@credal.ai", + message_id=uuid.UUID( + "dd721cd8-4bf2-4b94-9869-258df3dab9dc", + ), + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message_feedback=MessageFeedback( + feedback="NEGATIVE", + suggested_answer="Yes, Credal is SOC 2 compliant.", + descriptive_feedback="The response should be extremely clear and concise.", + ), +) ```
@@ -246,11 +284,42 @@ client.copilots.provide_message_feedback(user_email='ravin@credal.ai', message_i
```python -from credal import CredalApi import uuid + +from credal import CredalApi from credal.copilots import InputVariable -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.send_message(agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message='Is Credal SOC 2 compliant?', user_email='ravin@credal.ai', input_variables=[InputVariable(name='input1', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", )], ), InputVariable(name='input2', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c25", ), uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c26", )], )], ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.send_message( + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message="Is Credal SOC 2 compliant?", + user_email="ravin@credal.ai", + input_variables=[ + InputVariable( + name="input1", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ) + ], + ), + InputVariable( + name="input2", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c25", + ), + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c26", + ), + ], + ), + ], +) ```
@@ -345,11 +414,42 @@ This endpoint allows you to send a message to a specific agent and get the respo
```python -from credal import CredalApi import uuid + +from credal import CredalApi from credal.copilots import InputVariable -client = CredalApi(api_key="YOUR_API_KEY", ) -response = client.copilots.stream_message(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c25", ), message='Is Credal SOC 2 compliant?', email='ravin@credal.ai', input_variables=[InputVariable(name='input1', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", )], ), InputVariable(name='input2', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c25", ), uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c26", )], )], ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +response = client.copilots.stream_message( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c25", + ), + message="Is Credal SOC 2 compliant?", + email="ravin@credal.ai", + input_variables=[ + InputVariable( + name="input1", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ) + ], + ), + InputVariable( + name="input2", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c25", + ), + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c26", + ), + ], + ), + ], +) for chunk in response.data: yield chunk @@ -446,10 +546,21 @@ Link a collection with a agent. The API Key used must be added to both the colle
```python -from credal import CredalApi import uuid -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.add_collection_to_copilot(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), collection_id=uuid.UUID("def1055f-83c5-43d6-b558-f7a38e7b299e", ), ) + +from credal import CredalApi + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.add_collection_to_copilot( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + collection_id=uuid.UUID( + "def1055f-83c5-43d6-b558-f7a38e7b299e", + ), +) ```
@@ -520,10 +631,21 @@ Unlink a collection with a agent. The API Key used must be added to both the col
```python -from credal import CredalApi import uuid -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.remove_collection_from_copilot(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), collection_id=uuid.UUID("def1055f-83c5-43d6-b558-f7a38e7b299e", ), ) + +from credal import CredalApi + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.remove_collection_from_copilot( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + collection_id=uuid.UUID( + "def1055f-83c5-43d6-b558-f7a38e7b299e", + ), +) ```
@@ -594,12 +716,28 @@ Update the configuration for a agent
```python -from credal import CredalApi import uuid -from credal.copilots import Configuration -from credal.copilots import AiEndpointConfiguration -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.update_configuration(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), configuration=Configuration(name='Customer Agent', description='This agent is used to answer customer requests based on internal documentation.', prompt='You are a polite, helpful assistant used to answer customer requests.', ai_endpoint_configuration=AiEndpointConfiguration(base_url='https://api.openai.com/v1/', api_key='', ), ), ) + +from credal import CredalApi +from credal.copilots import AiEndpointConfiguration, Configuration + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.update_configuration( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + configuration=Configuration( + name="Customer Agent", + description="This agent is used to answer customer requests based on internal documentation.", + prompt="You are a polite, helpful assistant used to answer customer requests.", + ai_endpoint_configuration=AiEndpointConfiguration( + base_url="https://api.openai.com/v1/", + api_key="", + ), + ), +) ```
@@ -656,10 +794,18 @@ client.copilots.update_configuration(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8e
```python -from credal import CredalApi import uuid -client = CredalApi(api_key="YOUR_API_KEY", ) -client.copilots.delete_copilot(id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), ) + +from credal import CredalApi + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.copilots.delete_copilot( + id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), +) ```
@@ -710,8 +856,17 @@ client.copilots.delete_copilot(id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3 ```python from credal import CredalApi -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_catalog.upload_document_contents(document_name='My Document', document_contents='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', document_external_id='73eead26-d124-4940-b329-5f068a0a8db9', allowed_users_email_addresses=['jack@credal.ai', 'ravin@credal.ai'], upload_as_user_email='jack@credal.ai', ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_catalog.upload_document_contents( + document_name="My Document", + document_contents="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", + document_external_id="73eead26-d124-4940-b329-5f068a0a8db9", + allowed_users_email_addresses=["jack@credal.ai", "ravin@credal.ai"], + upload_as_user_email="jack@credal.ai", +) ``` @@ -847,8 +1002,14 @@ Sync a document from a source URL. Does not support recursive web search. Reach ```python from credal import CredalApi -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_catalog.sync_source_by_url(source_url='https://drive.google.com/file/d/123456/view', upload_as_user_email='ria@credal.ai', ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_catalog.sync_source_by_url( + source_url="https://drive.google.com/file/d/123456/view", + upload_as_user_email="ria@credal.ai", +) ``` @@ -920,12 +1081,31 @@ Bulk patch metadata for documents, synced natively by Credal or manual API uploa ```python from credal import CredalApi -from credal.document_catalog import DocumentMetadataPatch from credal.common import ResourceIdentifier_ExternalResourceId -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_catalog.metadata(sources=[DocumentMetadataPatch(metadata={'Department': 'HR', 'Country': 'United States'} -, resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ), DocumentMetadataPatch(metadata={'Department': 'Sales', 'Vertical': 'Healthcare'} -, resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='123456', resource_type="ZENDESK_TICKET", ), )], upload_as_user_email='ben@credal.ai', ) +from credal.document_catalog import DocumentMetadataPatch + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_catalog.metadata( + sources=[ + DocumentMetadataPatch( + metadata={"Department": "HR", "Country": "United States"}, + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ), + DocumentMetadataPatch( + metadata={"Department": "Sales", "Vertical": "Healthcare"}, + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="123456", + resource_type="ZENDESK_TICKET", + ), + ), + ], + upload_as_user_email="ben@credal.ai", +) ``` @@ -997,11 +1177,29 @@ Add documents to a document collection. Note that the documents must already exi
```python -from credal import CredalApi import uuid + +from credal import CredalApi from credal.common import ResourceIdentifier_ExternalResourceId -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_collections.add_documents_to_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), resource_identifiers=[ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ResourceIdentifier_ExternalResourceId(external_resource_id='398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923', resource_type="GOOGLE_DRIVE_ITEM", )], ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_collections.add_documents_to_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + resource_identifiers=[ + ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ], +) ```
@@ -1072,11 +1270,29 @@ Remove documents from a collection
```python -from credal import CredalApi import uuid + +from credal import CredalApi from credal.common import ResourceIdentifier_ExternalResourceId -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_collections.remove_documents_from_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), resource_identifiers=[ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ResourceIdentifier_ExternalResourceId(external_resource_id='398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923', resource_type="GOOGLE_DRIVE_ITEM", )], ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_collections.remove_documents_from_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + resource_identifiers=[ + ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ], +) ```
@@ -1149,8 +1365,20 @@ Create a new collection. The API key used will be added to the collection for fu ```python from credal import CredalApi from credal.common import Collaborator -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_collections.create_collection(name='Customer Collection', description='This collection is used to answer customer requests based on internal documentation.', collaborators=[Collaborator(email='test@gmail.com', role="editor", )], ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_collections.create_collection( + name="Customer Collection", + description="This collection is used to answer customer requests based on internal documentation.", + collaborators=[ + Collaborator( + email="test@gmail.com", + role="editor", + ) + ], +) ``` @@ -1229,10 +1457,18 @@ Delete the collection.
```python -from credal import CredalApi import uuid -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_collections.delete_collection(collection_id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), ) + +from credal import CredalApi + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_collections.delete_collection( + collection_id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), +) ```
@@ -1295,13 +1531,34 @@ Credal lets you easily sync your MongoDB data for use in Collections and Agents.
```python -from credal import CredalApi import uuid -from credal.document_collections import MongoCollectionSyncConfig -from credal.document_collections import MongoSourceFieldsConfig -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_collections.create_mongo_collection_sync(mongo_uri='mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority', collection_id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), config=MongoCollectionSyncConfig(sync_name='My sales transcripts', collection_name='myCollection', filter_expression={'status': {'$ne': 'disabled'}} -, source_fields=MongoSourceFieldsConfig(body='body', source_name='meetingName', source_system_updated='transcriptDatetime', source_url='link', ), ), ) + +from credal import CredalApi +from credal.document_collections import ( + MongoCollectionSyncConfig, + MongoSourceFieldsConfig, +) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_collections.create_mongo_collection_sync( + mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority", + collection_id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), + config=MongoCollectionSyncConfig( + sync_name="My sales transcripts", + collection_name="myCollection", + filter_expression={"status": {"$ne": "disabled"}}, + source_fields=MongoSourceFieldsConfig( + body="body", + source_name="meetingName", + source_system_updated="transcriptDatetime", + source_url="link", + ), + ), +) ```
@@ -1380,13 +1637,36 @@ Credal lets you easily sync your MongoDB data for use in Collections and Agents.
```python -from credal import CredalApi import uuid -from credal.document_collections import MongoCollectionSyncConfig -from credal.document_collections import MongoSourceFieldsConfig -client = CredalApi(api_key="YOUR_API_KEY", ) -client.document_collections.update_mongo_collection_sync(mongo_uri='mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority', mongo_credential_id=uuid.UUID("5988ed76-6ee1-11ef-97dd-1fca54b7c4bc", ), config=MongoCollectionSyncConfig(sync_name='My recent summarized sales transcripts', collection_name='myCollection', filter_expression={'transcriptDatetime': {'$gt': '2023-01-01T00:00:00.000Z'}} -, source_fields=MongoSourceFieldsConfig(body='transcriptSummary', source_name='meetingName', source_system_updated='transcriptDatetime', source_url='link', ), ), ) + +from credal import CredalApi +from credal.document_collections import ( + MongoCollectionSyncConfig, + MongoSourceFieldsConfig, +) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.document_collections.update_mongo_collection_sync( + mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority", + mongo_credential_id=uuid.UUID( + "5988ed76-6ee1-11ef-97dd-1fca54b7c4bc", + ), + config=MongoCollectionSyncConfig( + sync_name="My recent summarized sales transcripts", + collection_name="myCollection", + filter_expression={ + "transcriptDatetime": {"$gt": "2023-01-01T00:00:00.000Z"} + }, + source_fields=MongoSourceFieldsConfig( + body="transcriptSummary", + source_name="meetingName", + source_system_updated="transcriptDatetime", + source_url="link", + ), + ), +) ```
@@ -1468,8 +1748,17 @@ Admin endpoint to check whether the specified user is authorized to read the spe ```python from credal import CredalApi from credal.common import ResourceIdentifier_ExternalResourceId -client = CredalApi(api_key="YOUR_API_KEY", ) -client.permissions_service.check_resource_authorization_for_user(resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), user_email='john.smith@foo.com', ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.permissions_service.check_resource_authorization_for_user( + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + user_email="john.smith@foo.com", +) ``` @@ -1549,10 +1838,26 @@ Admin endpoint to check whether the specified user is authorized to read the spe ```python from credal import CredalApi -from credal.common import ResourceIdentifier_Url -from credal.common import ResourceIdentifier_ExternalResourceId -client = CredalApi(api_key="YOUR_API_KEY", ) -client.permissions_service.check_bulk_resources_authorization_for_user(resource_identifiers=[ResourceIdentifier_Url(url='https://docs.google.com/document/d/170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr/edit', ), ResourceIdentifier_ExternalResourceId(external_resource_id='sfsdfvr54UvyslPVWkQFOA0dfsdfsdflgNycFmdZJQr', resource_type="ZENDESK_TICKET", )], user_email='john.smith@foo.com', ) +from credal.common import ( + ResourceIdentifier_ExternalResourceId, + ResourceIdentifier_Url, +) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.permissions_service.check_bulk_resources_authorization_for_user( + resource_identifiers=[ + ResourceIdentifier_Url( + url="https://docs.google.com/document/d/170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr/edit", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="sfsdfvr54UvyslPVWkQFOA0dfsdfsdflgNycFmdZJQr", + resource_type="ZENDESK_TICKET", + ), + ], + user_email="john.smith@foo.com", +) ``` @@ -1632,8 +1937,13 @@ Admin endpoint to list all resources that the specified user is authorized to re ```python from credal import CredalApi -client = CredalApi(api_key="YOUR_API_KEY", ) -client.permissions_service.list_cached_authorized_resources_for_user(user_email='john.smith@foo.com', ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.permissions_service.list_cached_authorized_resources_for_user( + user_email="john.smith@foo.com", +) ``` @@ -1721,12 +2031,36 @@ Search across all documents in a document collection using the document metadata
```python -from credal import CredalApi import uuid -from credal.search import SingleFieldFilter -from credal.search import DocumentCollectionSearchOptions -client = CredalApi(api_key="YOUR_API_KEY", ) -client.search.search_document_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), search_query='ABC Corp', structured_query_filters=[SingleFieldFilter(field='status', operator="==", value='Open', )], user_email='jack@credal.ai', search_options=DocumentCollectionSearchOptions(max_chunks=10, merge_contents=True, threshold=0.8, enable_smart_filtering=True, enable_query_extraction=True, enable_reranking=True, ), ) + +from credal import CredalApi +from credal.search import DocumentCollectionSearchOptions, SingleFieldFilter + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.search.search_document_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + search_query="ABC Corp", + structured_query_filters=[ + SingleFieldFilter( + field="status", + operator="==", + value="Open", + ) + ], + user_email="jack@credal.ai", + search_options=DocumentCollectionSearchOptions( + max_chunks=10, + merge_contents=True, + threshold=0.8, + enable_smart_filtering=True, + enable_query_extraction=True, + enable_reranking=True, + ), +) ```
@@ -1832,10 +2166,22 @@ Bulk patch metadata for users ```python from credal import CredalApi from credal.users import UserMetadataPatch -client = CredalApi(api_key="YOUR_API_KEY", ) -client.users.metadata(request=[UserMetadataPatch(metadata={'State': 'NY', 'Job Role': 'CEO'} -, user_email='ravin@credal.ai', ), UserMetadataPatch(metadata={'State': 'NY', 'Department': 'Engineering'} -, user_email='jack@credal.ai', )], ) + +client = CredalApi( + api_key="YOUR_API_KEY", +) +client.users.metadata( + request=[ + UserMetadataPatch( + metadata={"State": "NY", "Job Role": "CEO"}, + user_email="ravin@credal.ai", + ), + UserMetadataPatch( + metadata={"State": "NY", "Department": "Engineering"}, + user_email="jack@credal.ai", + ), + ], +) ``` diff --git a/requirements.txt b/requirements.txt index 5f490a0..2154037 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ httpx>=0.21.2 httpx-sse==0.4.0 pydantic>= 1.9.2 -pydantic-core==^2.18.2 +pydantic-core==2.18.2 typing_extensions>= 4.0.0 diff --git a/src/credal/client.py b/src/credal/client.py index ecf29f9..532746a 100644 --- a/src/credal/client.py +++ b/src/credal/client.py @@ -27,6 +27,8 @@ class CredalApi: environment : CredalApiEnvironment The environment to use for requests from the client. from .environment import CredalApiEnvironment + + Defaults to CredalApiEnvironment.PRODUCTION @@ -44,7 +46,10 @@ class CredalApi: Examples -------- from credal import CredalApi - client = CredalApi(api_key="YOUR_API_KEY", ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) """ def __init__( @@ -94,6 +99,8 @@ class AsyncCredalApi: environment : CredalApiEnvironment The environment to use for requests from the client. from .environment import CredalApiEnvironment + + Defaults to CredalApiEnvironment.PRODUCTION @@ -111,7 +118,10 @@ class AsyncCredalApi: Examples -------- from credal import AsyncCredalApi - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) """ def __init__( diff --git a/src/credal/copilots/client.py b/src/credal/copilots/client.py index d30472b..a2de3a3 100644 --- a/src/credal/copilots/client.py +++ b/src/credal/copilots/client.py @@ -68,8 +68,20 @@ def create_copilot( -------- from credal import CredalApi from credal.common import Collaborator - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.create_copilot(name='Customer Agent', description='This agent is used to answer customer requests based on internal documentation.', collaborators=[Collaborator(email='test@gmail.com', role="editor", )], ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.create_copilot( + name="Customer Agent", + description="This agent is used to answer customer requests based on internal documentation.", + collaborators=[ + Collaborator( + email="test@gmail.com", + role="editor", + ) + ], + ) """ _response = self._raw_client.create_copilot( name=name, description=description, collaborators=collaborators, request_options=request_options @@ -99,10 +111,19 @@ def create_conversation( Examples -------- - from credal import CredalApi import uuid - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.create_conversation(agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), user_email='ravin@credal.ai', ) + + from credal import CredalApi + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.create_conversation( + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + user_email="ravin@credal.ai", + ) """ _response = self._raw_client.create_conversation( agent_id=agent_id, user_email=user_email, request_options=request_options @@ -142,11 +163,28 @@ def provide_message_feedback( Examples -------- - from credal import CredalApi import uuid + + from credal import CredalApi from credal.copilots import MessageFeedback - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.provide_message_feedback(user_email='ravin@credal.ai', message_id=uuid.UUID("dd721cd8-4bf2-4b94-9869-258df3dab9dc", ), agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message_feedback=MessageFeedback(feedback="NEGATIVE", suggested_answer='Yes, Credal is SOC 2 compliant.', descriptive_feedback='The response should be extremely clear and concise.', ), ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.provide_message_feedback( + user_email="ravin@credal.ai", + message_id=uuid.UUID( + "dd721cd8-4bf2-4b94-9869-258df3dab9dc", + ), + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message_feedback=MessageFeedback( + feedback="NEGATIVE", + suggested_answer="Yes, Credal is SOC 2 compliant.", + descriptive_feedback="The response should be extremely clear and concise.", + ), + ) """ _response = self._raw_client.provide_message_feedback( agent_id=agent_id, @@ -194,11 +232,42 @@ def send_message( Examples -------- - from credal import CredalApi import uuid + + from credal import CredalApi from credal.copilots import InputVariable - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.send_message(agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message='Is Credal SOC 2 compliant?', user_email='ravin@credal.ai', input_variables=[InputVariable(name='input1', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", )], ), InputVariable(name='input2', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c25", ), uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c26", )], )], ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.send_message( + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message="Is Credal SOC 2 compliant?", + user_email="ravin@credal.ai", + input_variables=[ + InputVariable( + name="input1", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ) + ], + ), + InputVariable( + name="input2", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c25", + ), + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c26", + ), + ], + ), + ], + ) """ _response = self._raw_client.send_message( agent_id=agent_id, @@ -250,11 +319,42 @@ def stream_message( Examples -------- - from credal import CredalApi import uuid + + from credal import CredalApi from credal.copilots import InputVariable - client = CredalApi(api_key="YOUR_API_KEY", ) - response = client.copilots.stream_message(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message='Is Credal SOC 2 compliant?', email='ravin@credal.ai', input_variables=[InputVariable(name='input1', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", )], ), InputVariable(name='input2', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c25", ), uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c26", )], )], ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + response = client.copilots.stream_message( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message="Is Credal SOC 2 compliant?", + email="ravin@credal.ai", + input_variables=[ + InputVariable( + name="input1", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ) + ], + ), + InputVariable( + name="input2", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c25", + ), + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c26", + ), + ], + ), + ], + ) for chunk in response: yield chunk """ @@ -295,10 +395,21 @@ def add_collection_to_copilot( Examples -------- - from credal import CredalApi import uuid - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.add_collection_to_copilot(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), collection_id=uuid.UUID("def1055f-83c5-43d6-b558-f7a38e7b299e", ), ) + + from credal import CredalApi + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.add_collection_to_copilot( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + collection_id=uuid.UUID( + "def1055f-83c5-43d6-b558-f7a38e7b299e", + ), + ) """ _response = self._raw_client.add_collection_to_copilot( copilot_id=copilot_id, collection_id=collection_id, request_options=request_options @@ -332,10 +443,21 @@ def remove_collection_from_copilot( Examples -------- - from credal import CredalApi import uuid - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.remove_collection_from_copilot(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), collection_id=uuid.UUID("def1055f-83c5-43d6-b558-f7a38e7b299e", ), ) + + from credal import CredalApi + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.remove_collection_from_copilot( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + collection_id=uuid.UUID( + "def1055f-83c5-43d6-b558-f7a38e7b299e", + ), + ) """ _response = self._raw_client.remove_collection_from_copilot( copilot_id=copilot_id, collection_id=collection_id, request_options=request_options @@ -368,12 +490,28 @@ def update_configuration( Examples -------- - from credal import CredalApi import uuid - from credal.copilots import Configuration - from credal.copilots import AiEndpointConfiguration - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.update_configuration(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), configuration=Configuration(name='Customer Agent', description='This agent is used to answer customer requests based on internal documentation.', prompt='You are a polite, helpful assistant used to answer customer requests.', ai_endpoint_configuration=AiEndpointConfiguration(base_url='https://api.openai.com/v1/', api_key='', ), ), ) + + from credal import CredalApi + from credal.copilots import AiEndpointConfiguration, Configuration + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.update_configuration( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + configuration=Configuration( + name="Customer Agent", + description="This agent is used to answer customer requests based on internal documentation.", + prompt="You are a polite, helpful assistant used to answer customer requests.", + ai_endpoint_configuration=AiEndpointConfiguration( + base_url="https://api.openai.com/v1/", + api_key="", + ), + ), + ) """ _response = self._raw_client.update_configuration( copilot_id=copilot_id, configuration=configuration, request_options=request_options @@ -398,10 +536,18 @@ def delete_copilot( Examples -------- - from credal import CredalApi import uuid - client = CredalApi(api_key="YOUR_API_KEY", ) - client.copilots.delete_copilot(id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), ) + + from credal import CredalApi + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.copilots.delete_copilot( + id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), + ) """ _response = self._raw_client.delete_copilot(id=id, request_options=request_options) return _response.data @@ -453,12 +599,29 @@ async def create_copilot( Examples -------- + import asyncio + from credal import AsyncCredalApi from credal.common import Collaborator - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.create_copilot(name='Customer Agent', description='This agent is used to answer customer requests based on internal documentation.', collaborators=[Collaborator(email='test@gmail.com', role="editor", )], ) + await client.copilots.create_copilot( + name="Customer Agent", + description="This agent is used to answer customer requests based on internal documentation.", + collaborators=[ + Collaborator( + email="test@gmail.com", + role="editor", + ) + ], + ) + + asyncio.run(main()) """ _response = await self._raw_client.create_copilot( @@ -489,12 +652,25 @@ async def create_conversation( Examples -------- - from credal import AsyncCredalApi - import uuid import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.create_conversation(agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), user_email='ravin@credal.ai', ) + await client.copilots.create_conversation( + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + user_email="ravin@credal.ai", + ) + + asyncio.run(main()) """ _response = await self._raw_client.create_conversation( @@ -535,13 +711,34 @@ async def provide_message_feedback( Examples -------- - from credal import AsyncCredalApi + import asyncio import uuid + + from credal import AsyncCredalApi from credal.copilots import MessageFeedback - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.provide_message_feedback(user_email='ravin@credal.ai', message_id=uuid.UUID("dd721cd8-4bf2-4b94-9869-258df3dab9dc", ), agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message_feedback=MessageFeedback(feedback="NEGATIVE", suggested_answer='Yes, Credal is SOC 2 compliant.', descriptive_feedback='The response should be extremely clear and concise.', ), ) + await client.copilots.provide_message_feedback( + user_email="ravin@credal.ai", + message_id=uuid.UUID( + "dd721cd8-4bf2-4b94-9869-258df3dab9dc", + ), + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message_feedback=MessageFeedback( + feedback="NEGATIVE", + suggested_answer="Yes, Credal is SOC 2 compliant.", + descriptive_feedback="The response should be extremely clear and concise.", + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.provide_message_feedback( @@ -590,13 +787,48 @@ async def send_message( Examples -------- - from credal import AsyncCredalApi + import asyncio import uuid + + from credal import AsyncCredalApi from credal.copilots import InputVariable - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.send_message(agent_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message='Is Credal SOC 2 compliant?', user_email='ravin@credal.ai', input_variables=[InputVariable(name='input1', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", )], ), InputVariable(name='input2', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c25", ), uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c26", )], )], ) + await client.copilots.send_message( + agent_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message="Is Credal SOC 2 compliant?", + user_email="ravin@credal.ai", + input_variables=[ + InputVariable( + name="input1", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ) + ], + ), + InputVariable( + name="input2", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c25", + ), + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c26", + ), + ], + ), + ], + ) + + asyncio.run(main()) """ _response = await self._raw_client.send_message( @@ -649,15 +881,50 @@ async def stream_message( Examples -------- - from credal import AsyncCredalApi + import asyncio import uuid + + from credal import AsyncCredalApi from credal.copilots import InputVariable - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - response = await client.copilots.stream_message(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), message='Is Credal SOC 2 compliant?', email='ravin@credal.ai', input_variables=[InputVariable(name='input1', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", )], ), InputVariable(name='input2', ids=[uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c25", ), uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c26", )], )], ) + response = await client.copilots.stream_message( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + message="Is Credal SOC 2 compliant?", + email="ravin@credal.ai", + input_variables=[ + InputVariable( + name="input1", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ) + ], + ), + InputVariable( + name="input2", + ids=[ + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c25", + ), + uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c26", + ), + ], + ), + ], + ) async for chunk in response: yield chunk + + asyncio.run(main()) """ async with self._raw_client.stream_message( @@ -668,8 +935,8 @@ async def main() -> None: input_variables=input_variables, request_options=request_options, ) as r: - async for data in r.data: - yield data + async for _chunk in r.data: + yield _chunk async def add_collection_to_copilot( self, @@ -698,12 +965,27 @@ async def add_collection_to_copilot( Examples -------- - from credal import AsyncCredalApi - import uuid import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.add_collection_to_copilot(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), collection_id=uuid.UUID("def1055f-83c5-43d6-b558-f7a38e7b299e", ), ) + await client.copilots.add_collection_to_copilot( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + collection_id=uuid.UUID( + "def1055f-83c5-43d6-b558-f7a38e7b299e", + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.add_collection_to_copilot( @@ -738,12 +1020,27 @@ async def remove_collection_from_copilot( Examples -------- - from credal import AsyncCredalApi - import uuid import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.remove_collection_from_copilot(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), collection_id=uuid.UUID("def1055f-83c5-43d6-b558-f7a38e7b299e", ), ) + await client.copilots.remove_collection_from_copilot( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + collection_id=uuid.UUID( + "def1055f-83c5-43d6-b558-f7a38e7b299e", + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.remove_collection_from_copilot( @@ -777,14 +1074,34 @@ async def update_configuration( Examples -------- - from credal import AsyncCredalApi - import uuid - from credal.copilots import Configuration - from credal.copilots import AiEndpointConfiguration import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + from credal.copilots import AiEndpointConfiguration, Configuration + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.update_configuration(copilot_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), configuration=Configuration(name='Customer Agent', description='This agent is used to answer customer requests based on internal documentation.', prompt='You are a polite, helpful assistant used to answer customer requests.', ai_endpoint_configuration=AiEndpointConfiguration(base_url='https://api.openai.com/v1/', api_key='', ), ), ) + await client.copilots.update_configuration( + copilot_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + configuration=Configuration( + name="Customer Agent", + description="This agent is used to answer customer requests based on internal documentation.", + prompt="You are a polite, helpful assistant used to answer customer requests.", + ai_endpoint_configuration=AiEndpointConfiguration( + base_url="https://api.openai.com/v1/", + api_key="", + ), + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.update_configuration( @@ -810,12 +1127,24 @@ async def delete_copilot( Examples -------- - from credal import AsyncCredalApi - import uuid import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.copilots.delete_copilot(id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), ) + await client.copilots.delete_copilot( + id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.delete_copilot(id=id, request_options=request_options) diff --git a/src/credal/copilots/raw_client.py b/src/credal/copilots/raw_client.py index c9cbb19..566f4fe 100644 --- a/src/credal/copilots/raw_client.py +++ b/src/credal/copilots/raw_client.py @@ -1,6 +1,7 @@ # This file was auto-generated by Fern from our API Definition. import contextlib +import json import typing import uuid from json.decoder import JSONDecodeError @@ -306,7 +307,7 @@ def stream_message( omit=OMIT, ) as _response: - def stream() -> HttpResponse[typing.Iterator[StreamingChunk]]: + def _stream() -> HttpResponse[typing.Iterator[StreamingChunk]]: try: if 200 <= _response.status_code < 300: @@ -316,7 +317,13 @@ def _iter(): if _sse.data == None: return try: - yield _sse.data + yield typing.cast( + StreamingChunk, + parse_obj_as( + type_=StreamingChunk, # type: ignore + object_=json.loads(_sse.data), + ), + ) except Exception: pass return @@ -330,7 +337,7 @@ def _iter(): ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - yield stream() + yield _stream() def add_collection_to_copilot( self, @@ -783,7 +790,7 @@ async def stream_message( omit=OMIT, ) as _response: - async def stream() -> AsyncHttpResponse[typing.AsyncIterator[StreamingChunk]]: + async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[StreamingChunk]]: try: if 200 <= _response.status_code < 300: @@ -793,7 +800,13 @@ async def _iter(): if _sse.data == None: return try: - yield _sse.data + yield typing.cast( + StreamingChunk, + parse_obj_as( + type_=StreamingChunk, # type: ignore + object_=json.loads(_sse.data), + ), + ) except Exception: pass return @@ -807,7 +820,7 @@ async def _iter(): ) raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) - yield await stream() + yield await _stream() async def add_collection_to_copilot( self, diff --git a/src/credal/core/client_wrapper.py b/src/credal/core/client_wrapper.py index a290d37..824324e 100644 --- a/src/credal/core/client_wrapper.py +++ b/src/credal/core/client_wrapper.py @@ -20,10 +20,10 @@ def __init__( def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { - "User-Agent": "credal/0.0.27", + "User-Agent": "credal/0.0.28", "X-Fern-Language": "Python", "X-Fern-SDK-Name": "credal", - "X-Fern-SDK-Version": "0.0.27", + "X-Fern-SDK-Version": "0.0.28", } headers["Authorization"] = f"Bearer {self._get_api_key()}" return headers diff --git a/src/credal/core/force_multipart.py b/src/credal/core/force_multipart.py new file mode 100644 index 0000000..ae24ccf --- /dev/null +++ b/src/credal/core/force_multipart.py @@ -0,0 +1,16 @@ +# This file was auto-generated by Fern from our API Definition. + + +class ForceMultipartDict(dict): + """ + A dictionary subclass that always evaluates to True in boolean contexts. + + This is used to force multipart/form-data encoding in HTTP requests even when + the dictionary is empty, which would normally evaluate to False. + """ + + def __bool__(self): + return True + + +FORCE_MULTIPART = ForceMultipartDict() diff --git a/src/credal/core/http_client.py b/src/credal/core/http_client.py index e7bd4f7..e4173f9 100644 --- a/src/credal/core/http_client.py +++ b/src/credal/core/http_client.py @@ -11,10 +11,12 @@ import httpx from .file import File, convert_file_dict_to_httpx_tuples +from .force_multipart import FORCE_MULTIPART from .jsonable_encoder import jsonable_encoder from .query_encoder import encode_query from .remove_none_from_dict import remove_none_from_dict from .request_options import RequestOptions +from httpx._types import RequestFiles INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 @@ -178,11 +180,17 @@ def request( json: typing.Optional[typing.Any] = None, data: typing.Optional[typing.Any] = None, content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, - files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None, + files: typing.Optional[ + typing.Union[ + typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]], + typing.List[typing.Tuple[str, File]], + ] + ] = None, headers: typing.Optional[typing.Dict[str, typing.Any]] = None, request_options: typing.Optional[RequestOptions] = None, retries: int = 2, omit: typing.Optional[typing.Any] = None, + force_multipart: typing.Optional[bool] = None, ) -> httpx.Response: base_url = self.get_base_url(base_url) timeout = ( @@ -193,6 +201,15 @@ def request( json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) + request_files: typing.Optional[RequestFiles] = ( + convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) + if (files is not None and files is not omit and isinstance(files, dict)) + else None + ) + + if (request_files is None or len(request_files) == 0) and force_multipart: + request_files = FORCE_MULTIPART + response = self.httpx_client.request( method=method, url=urllib.parse.urljoin(f"{base_url}/", path), @@ -225,11 +242,7 @@ def request( json=json_body, data=data_body, content=content, - files=( - convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) - if (files is not None and files is not omit) - else None - ), + files=request_files, timeout=timeout, ) @@ -264,11 +277,17 @@ def stream( json: typing.Optional[typing.Any] = None, data: typing.Optional[typing.Any] = None, content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, - files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None, + files: typing.Optional[ + typing.Union[ + typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]], + typing.List[typing.Tuple[str, File]], + ] + ] = None, headers: typing.Optional[typing.Dict[str, typing.Any]] = None, request_options: typing.Optional[RequestOptions] = None, retries: int = 2, omit: typing.Optional[typing.Any] = None, + force_multipart: typing.Optional[bool] = None, ) -> typing.Iterator[httpx.Response]: base_url = self.get_base_url(base_url) timeout = ( @@ -277,6 +296,15 @@ def stream( else self.base_timeout() ) + request_files: typing.Optional[RequestFiles] = ( + convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) + if (files is not None and files is not omit and isinstance(files, dict)) + else None + ) + + if (request_files is None or len(request_files) == 0) and force_multipart: + request_files = FORCE_MULTIPART + json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) with self.httpx_client.stream( @@ -311,11 +339,7 @@ def stream( json=json_body, data=data_body, content=content, - files=( - convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) - if (files is not None and files is not omit) - else None - ), + files=request_files, timeout=timeout, ) as stream: yield stream @@ -354,11 +378,17 @@ async def request( json: typing.Optional[typing.Any] = None, data: typing.Optional[typing.Any] = None, content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, - files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None, + files: typing.Optional[ + typing.Union[ + typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]], + typing.List[typing.Tuple[str, File]], + ] + ] = None, headers: typing.Optional[typing.Dict[str, typing.Any]] = None, request_options: typing.Optional[RequestOptions] = None, retries: int = 2, omit: typing.Optional[typing.Any] = None, + force_multipart: typing.Optional[bool] = None, ) -> httpx.Response: base_url = self.get_base_url(base_url) timeout = ( @@ -367,6 +397,15 @@ async def request( else self.base_timeout() ) + request_files: typing.Optional[RequestFiles] = ( + convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) + if (files is not None and files is not omit and isinstance(files, dict)) + else None + ) + + if (request_files is None or len(request_files) == 0) and force_multipart: + request_files = FORCE_MULTIPART + json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) # Add the input to each of these and do None-safety checks @@ -402,11 +441,7 @@ async def request( json=json_body, data=data_body, content=content, - files=( - convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) - if files is not None - else None - ), + files=request_files, timeout=timeout, ) @@ -440,11 +475,17 @@ async def stream( json: typing.Optional[typing.Any] = None, data: typing.Optional[typing.Any] = None, content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, - files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None, + files: typing.Optional[ + typing.Union[ + typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]], + typing.List[typing.Tuple[str, File]], + ] + ] = None, headers: typing.Optional[typing.Dict[str, typing.Any]] = None, request_options: typing.Optional[RequestOptions] = None, retries: int = 2, omit: typing.Optional[typing.Any] = None, + force_multipart: typing.Optional[bool] = None, ) -> typing.AsyncIterator[httpx.Response]: base_url = self.get_base_url(base_url) timeout = ( @@ -453,6 +494,15 @@ async def stream( else self.base_timeout() ) + request_files: typing.Optional[RequestFiles] = ( + convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) + if (files is not None and files is not omit and isinstance(files, dict)) + else None + ) + + if (request_files is None or len(request_files) == 0) and force_multipart: + request_files = FORCE_MULTIPART + json_body, data_body = get_request_body(json=json, data=data, request_options=request_options, omit=omit) async with self.httpx_client.stream( @@ -487,11 +537,7 @@ async def stream( json=json_body, data=data_body, content=content, - files=( - convert_file_dict_to_httpx_tuples(remove_omit_from_dict(remove_none_from_dict(files), omit)) - if files is not None - else None - ), + files=request_files, timeout=timeout, ) as stream: yield stream diff --git a/src/credal/core/pydantic_utilities.py b/src/credal/core/pydantic_utilities.py index 60a2c71..0360ef4 100644 --- a/src/credal/core/pydantic_utilities.py +++ b/src/credal/core/pydantic_utilities.py @@ -181,7 +181,7 @@ def deep_union_pydantic_dicts(source: Dict[str, Any], destination: Dict[str, Any if IS_PYDANTIC_V2: - class V2RootModel(UniversalBaseModel, pydantic.RootModel): # type: ignore[name-defined, type-arg] + class V2RootModel(UniversalBaseModel, pydantic.RootModel): # type: ignore[misc, name-defined, type-arg] pass UniversalRootModel: TypeAlias = V2RootModel # type: ignore[misc] diff --git a/src/credal/document_catalog/client.py b/src/credal/document_catalog/client.py index f24821c..549a7c7 100644 --- a/src/credal/document_catalog/client.py +++ b/src/credal/document_catalog/client.py @@ -86,8 +86,17 @@ def upload_document_contents( Examples -------- from credal import CredalApi - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_catalog.upload_document_contents(document_name='My Document', document_contents='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', document_external_id='73eead26-d124-4940-b329-5f068a0a8db9', allowed_users_email_addresses=['jack@credal.ai', 'ravin@credal.ai'], upload_as_user_email='jack@credal.ai', ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_catalog.upload_document_contents( + document_name="My Document", + document_contents="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", + document_external_id="73eead26-d124-4940-b329-5f068a0a8db9", + allowed_users_email_addresses=["jack@credal.ai", "ravin@credal.ai"], + upload_as_user_email="jack@credal.ai", + ) """ _response = self._raw_client.upload_document_contents( document_name=document_name, @@ -126,8 +135,14 @@ def sync_source_by_url( Examples -------- from credal import CredalApi - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_catalog.sync_source_by_url(source_url='https://drive.google.com/file/d/123456/view', upload_as_user_email='ria@credal.ai', ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_catalog.sync_source_by_url( + source_url="https://drive.google.com/file/d/123456/view", + upload_as_user_email="ria@credal.ai", + ) """ _response = self._raw_client.sync_source_by_url( upload_as_user_email=upload_as_user_email, source_url=source_url, request_options=request_options @@ -160,12 +175,31 @@ def metadata( Examples -------- from credal import CredalApi - from credal.document_catalog import DocumentMetadataPatch from credal.common import ResourceIdentifier_ExternalResourceId - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_catalog.metadata(sources=[DocumentMetadataPatch(metadata={'Department': 'HR', 'Country': 'United States'} - , resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ), DocumentMetadataPatch(metadata={'Department': 'Sales', 'Vertical': 'Healthcare'} - , resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='123456', resource_type="ZENDESK_TICKET", ), )], upload_as_user_email='ben@credal.ai', ) + from credal.document_catalog import DocumentMetadataPatch + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_catalog.metadata( + sources=[ + DocumentMetadataPatch( + metadata={"Department": "HR", "Country": "United States"}, + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ), + DocumentMetadataPatch( + metadata={"Department": "Sales", "Vertical": "Healthcare"}, + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="123456", + resource_type="ZENDESK_TICKET", + ), + ), + ], + upload_as_user_email="ben@credal.ai", + ) """ _response = self._raw_client.metadata( sources=sources, upload_as_user_email=upload_as_user_email, request_options=request_options @@ -245,11 +279,25 @@ async def upload_document_contents( Examples -------- - from credal import AsyncCredalApi import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_catalog.upload_document_contents(document_name='My Document', document_contents='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', document_external_id='73eead26-d124-4940-b329-5f068a0a8db9', allowed_users_email_addresses=['jack@credal.ai', 'ravin@credal.ai'], upload_as_user_email='jack@credal.ai', ) + await client.document_catalog.upload_document_contents( + document_name="My Document", + document_contents="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", + document_external_id="73eead26-d124-4940-b329-5f068a0a8db9", + allowed_users_email_addresses=["jack@credal.ai", "ravin@credal.ai"], + upload_as_user_email="jack@credal.ai", + ) + + asyncio.run(main()) """ _response = await self._raw_client.upload_document_contents( @@ -288,11 +336,22 @@ async def sync_source_by_url( Examples -------- - from credal import AsyncCredalApi import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_catalog.sync_source_by_url(source_url='https://drive.google.com/file/d/123456/view', upload_as_user_email='ria@credal.ai', ) + await client.document_catalog.sync_source_by_url( + source_url="https://drive.google.com/file/d/123456/view", + upload_as_user_email="ria@credal.ai", + ) + + asyncio.run(main()) """ _response = await self._raw_client.sync_source_by_url( @@ -325,15 +384,39 @@ async def metadata( Examples -------- + import asyncio + from credal import AsyncCredalApi - from credal.document_catalog import DocumentMetadataPatch from credal.common import ResourceIdentifier_ExternalResourceId - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + from credal.document_catalog import DocumentMetadataPatch + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_catalog.metadata(sources=[DocumentMetadataPatch(metadata={'Department': 'HR', 'Country': 'United States'} - , resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ), DocumentMetadataPatch(metadata={'Department': 'Sales', 'Vertical': 'Healthcare'} - , resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='123456', resource_type="ZENDESK_TICKET", ), )], upload_as_user_email='ben@credal.ai', ) + await client.document_catalog.metadata( + sources=[ + DocumentMetadataPatch( + metadata={"Department": "HR", "Country": "United States"}, + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ), + DocumentMetadataPatch( + metadata={"Department": "Sales", "Vertical": "Healthcare"}, + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="123456", + resource_type="ZENDESK_TICKET", + ), + ), + ], + upload_as_user_email="ben@credal.ai", + ) + + asyncio.run(main()) """ _response = await self._raw_client.metadata( diff --git a/src/credal/document_collections/client.py b/src/credal/document_collections/client.py index 247f18d..a16a6e7 100644 --- a/src/credal/document_collections/client.py +++ b/src/credal/document_collections/client.py @@ -59,11 +59,29 @@ def add_documents_to_collection( Examples -------- - from credal import CredalApi import uuid + + from credal import CredalApi from credal.common import ResourceIdentifier_ExternalResourceId - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_collections.add_documents_to_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), resource_identifiers=[ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ResourceIdentifier_ExternalResourceId(external_resource_id='398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923', resource_type="GOOGLE_DRIVE_ITEM", )], ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_collections.add_documents_to_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + resource_identifiers=[ + ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ], + ) """ _response = self._raw_client.add_documents_to_collection( collection_id=collection_id, resource_identifiers=resource_identifiers, request_options=request_options @@ -97,11 +115,29 @@ def remove_documents_from_collection( Examples -------- - from credal import CredalApi import uuid + + from credal import CredalApi from credal.common import ResourceIdentifier_ExternalResourceId - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_collections.remove_documents_from_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), resource_identifiers=[ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ResourceIdentifier_ExternalResourceId(external_resource_id='398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923', resource_type="GOOGLE_DRIVE_ITEM", )], ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_collections.remove_documents_from_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + resource_identifiers=[ + ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ], + ) """ _response = self._raw_client.remove_documents_from_collection( collection_id=collection_id, resource_identifiers=resource_identifiers, request_options=request_options @@ -141,8 +177,20 @@ def create_collection( -------- from credal import CredalApi from credal.common import Collaborator - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_collections.create_collection(name='Customer Collection', description='This collection is used to answer customer requests based on internal documentation.', collaborators=[Collaborator(email='test@gmail.com', role="editor", )], ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_collections.create_collection( + name="Customer Collection", + description="This collection is used to answer customer requests based on internal documentation.", + collaborators=[ + Collaborator( + email="test@gmail.com", + role="editor", + ) + ], + ) """ _response = self._raw_client.create_collection( name=name, description=description, collaborators=collaborators, request_options=request_options @@ -168,10 +216,18 @@ def delete_collection( Examples -------- - from credal import CredalApi import uuid - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_collections.delete_collection(collection_id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), ) + + from credal import CredalApi + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_collections.delete_collection( + collection_id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), + ) """ _response = self._raw_client.delete_collection(collection_id=collection_id, request_options=request_options) return _response.data @@ -204,13 +260,34 @@ def create_mongo_collection_sync( Examples -------- - from credal import CredalApi import uuid - from credal.document_collections import MongoCollectionSyncConfig - from credal.document_collections import MongoSourceFieldsConfig - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_collections.create_mongo_collection_sync(mongo_uri='mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority', collection_id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), config=MongoCollectionSyncConfig(sync_name='My sales transcripts', collection_name='myCollection', filter_expression={'status': {'$ne': 'disabled'}} - , source_fields=MongoSourceFieldsConfig(body='body', source_name='meetingName', source_system_updated='transcriptDatetime', source_url='link', ), ), ) + + from credal import CredalApi + from credal.document_collections import ( + MongoCollectionSyncConfig, + MongoSourceFieldsConfig, + ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_collections.create_mongo_collection_sync( + mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority", + collection_id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), + config=MongoCollectionSyncConfig( + sync_name="My sales transcripts", + collection_name="myCollection", + filter_expression={"status": {"$ne": "disabled"}}, + source_fields=MongoSourceFieldsConfig( + body="body", + source_name="meetingName", + source_system_updated="transcriptDatetime", + source_url="link", + ), + ), + ) """ _response = self._raw_client.create_mongo_collection_sync( collection_id=collection_id, mongo_uri=mongo_uri, config=config, request_options=request_options @@ -245,13 +322,36 @@ def update_mongo_collection_sync( Examples -------- - from credal import CredalApi import uuid - from credal.document_collections import MongoCollectionSyncConfig - from credal.document_collections import MongoSourceFieldsConfig - client = CredalApi(api_key="YOUR_API_KEY", ) - client.document_collections.update_mongo_collection_sync(mongo_uri='mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority', mongo_credential_id=uuid.UUID("5988ed76-6ee1-11ef-97dd-1fca54b7c4bc", ), config=MongoCollectionSyncConfig(sync_name='My recent summarized sales transcripts', collection_name='myCollection', filter_expression={'transcriptDatetime': {'$gt': '2023-01-01T00:00:00.000Z'}} - , source_fields=MongoSourceFieldsConfig(body='transcriptSummary', source_name='meetingName', source_system_updated='transcriptDatetime', source_url='link', ), ), ) + + from credal import CredalApi + from credal.document_collections import ( + MongoCollectionSyncConfig, + MongoSourceFieldsConfig, + ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.document_collections.update_mongo_collection_sync( + mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority", + mongo_credential_id=uuid.UUID( + "5988ed76-6ee1-11ef-97dd-1fca54b7c4bc", + ), + config=MongoCollectionSyncConfig( + sync_name="My recent summarized sales transcripts", + collection_name="myCollection", + filter_expression={ + "transcriptDatetime": {"$gt": "2023-01-01T00:00:00.000Z"} + }, + source_fields=MongoSourceFieldsConfig( + body="transcriptSummary", + source_name="meetingName", + source_system_updated="transcriptDatetime", + source_url="link", + ), + ), + ) """ _response = self._raw_client.update_mongo_collection_sync( mongo_credential_id=mongo_credential_id, mongo_uri=mongo_uri, config=config, request_options=request_options @@ -301,13 +401,35 @@ async def add_documents_to_collection( Examples -------- - from credal import AsyncCredalApi + import asyncio import uuid + + from credal import AsyncCredalApi from credal.common import ResourceIdentifier_ExternalResourceId - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_collections.add_documents_to_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), resource_identifiers=[ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ResourceIdentifier_ExternalResourceId(external_resource_id='398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923', resource_type="GOOGLE_DRIVE_ITEM", )], ) + await client.document_collections.add_documents_to_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + resource_identifiers=[ + ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ], + ) + + asyncio.run(main()) """ _response = await self._raw_client.add_documents_to_collection( @@ -342,13 +464,35 @@ async def remove_documents_from_collection( Examples -------- - from credal import AsyncCredalApi + import asyncio import uuid + + from credal import AsyncCredalApi from credal.common import ResourceIdentifier_ExternalResourceId - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_collections.remove_documents_from_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), resource_identifiers=[ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), ResourceIdentifier_ExternalResourceId(external_resource_id='398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923', resource_type="GOOGLE_DRIVE_ITEM", )], ) + await client.document_collections.remove_documents_from_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + resource_identifiers=[ + ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="398KAHdfkjsdf09r54UvyslPVWkQFOA0lOiu34in923", + resource_type="GOOGLE_DRIVE_ITEM", + ), + ], + ) + + asyncio.run(main()) """ _response = await self._raw_client.remove_documents_from_collection( @@ -387,12 +531,29 @@ async def create_collection( Examples -------- + import asyncio + from credal import AsyncCredalApi from credal.common import Collaborator - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_collections.create_collection(name='Customer Collection', description='This collection is used to answer customer requests based on internal documentation.', collaborators=[Collaborator(email='test@gmail.com', role="editor", )], ) + await client.document_collections.create_collection( + name="Customer Collection", + description="This collection is used to answer customer requests based on internal documentation.", + collaborators=[ + Collaborator( + email="test@gmail.com", + role="editor", + ) + ], + ) + + asyncio.run(main()) """ _response = await self._raw_client.create_collection( @@ -419,12 +580,24 @@ async def delete_collection( Examples -------- - from credal import AsyncCredalApi - import uuid import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_collections.delete_collection(collection_id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), ) + await client.document_collections.delete_collection( + collection_id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.delete_collection( @@ -460,15 +633,40 @@ async def create_mongo_collection_sync( Examples -------- - from credal import AsyncCredalApi - import uuid - from credal.document_collections import MongoCollectionSyncConfig - from credal.document_collections import MongoSourceFieldsConfig import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + from credal.document_collections import ( + MongoCollectionSyncConfig, + MongoSourceFieldsConfig, + ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_collections.create_mongo_collection_sync(mongo_uri='mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority', collection_id=uuid.UUID("ac20e6ba-0bae-11ef-b25a-efca73df4c3a", ), config=MongoCollectionSyncConfig(sync_name='My sales transcripts', collection_name='myCollection', filter_expression={'status': {'$ne': 'disabled'}} - , source_fields=MongoSourceFieldsConfig(body='body', source_name='meetingName', source_system_updated='transcriptDatetime', source_url='link', ), ), ) + await client.document_collections.create_mongo_collection_sync( + mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority", + collection_id=uuid.UUID( + "ac20e6ba-0bae-11ef-b25a-efca73df4c3a", + ), + config=MongoCollectionSyncConfig( + sync_name="My sales transcripts", + collection_name="myCollection", + filter_expression={"status": {"$ne": "disabled"}}, + source_fields=MongoSourceFieldsConfig( + body="body", + source_name="meetingName", + source_system_updated="transcriptDatetime", + source_url="link", + ), + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.create_mongo_collection_sync( @@ -504,15 +702,42 @@ async def update_mongo_collection_sync( Examples -------- - from credal import AsyncCredalApi - import uuid - from credal.document_collections import MongoCollectionSyncConfig - from credal.document_collections import MongoSourceFieldsConfig import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + from credal.document_collections import ( + MongoCollectionSyncConfig, + MongoSourceFieldsConfig, + ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.document_collections.update_mongo_collection_sync(mongo_uri='mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority', mongo_credential_id=uuid.UUID("5988ed76-6ee1-11ef-97dd-1fca54b7c4bc", ), config=MongoCollectionSyncConfig(sync_name='My recent summarized sales transcripts', collection_name='myCollection', filter_expression={'transcriptDatetime': {'$gt': '2023-01-01T00:00:00.000Z'}} - , source_fields=MongoSourceFieldsConfig(body='transcriptSummary', source_name='meetingName', source_system_updated='transcriptDatetime', source_url='link', ), ), ) + await client.document_collections.update_mongo_collection_sync( + mongo_uri="mongodb+srv://cluster0.hzwklqn.mongodb.net/Cluster0?retryWrites=true&w=majority", + mongo_credential_id=uuid.UUID( + "5988ed76-6ee1-11ef-97dd-1fca54b7c4bc", + ), + config=MongoCollectionSyncConfig( + sync_name="My recent summarized sales transcripts", + collection_name="myCollection", + filter_expression={ + "transcriptDatetime": {"$gt": "2023-01-01T00:00:00.000Z"} + }, + source_fields=MongoSourceFieldsConfig( + body="transcriptSummary", + source_name="meetingName", + source_system_updated="transcriptDatetime", + source_url="link", + ), + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.update_mongo_collection_sync( diff --git a/src/credal/permissions_service/client.py b/src/credal/permissions_service/client.py index b833055..15b0bd1 100644 --- a/src/credal/permissions_service/client.py +++ b/src/credal/permissions_service/client.py @@ -63,8 +63,17 @@ def check_resource_authorization_for_user( -------- from credal import CredalApi from credal.common import ResourceIdentifier_ExternalResourceId - client = CredalApi(api_key="YOUR_API_KEY", ) - client.permissions_service.check_resource_authorization_for_user(resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), user_email='john.smith@foo.com', ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.permissions_service.check_resource_authorization_for_user( + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + user_email="john.smith@foo.com", + ) """ _response = self._raw_client.check_resource_authorization_for_user( resource_identifier=resource_identifier, @@ -106,10 +115,26 @@ def check_bulk_resources_authorization_for_user( Examples -------- from credal import CredalApi - from credal.common import ResourceIdentifier_Url - from credal.common import ResourceIdentifier_ExternalResourceId - client = CredalApi(api_key="YOUR_API_KEY", ) - client.permissions_service.check_bulk_resources_authorization_for_user(resource_identifiers=[ResourceIdentifier_Url(url='https://docs.google.com/document/d/170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr/edit', ), ResourceIdentifier_ExternalResourceId(external_resource_id='sfsdfvr54UvyslPVWkQFOA0dfsdfsdflgNycFmdZJQr', resource_type="ZENDESK_TICKET", )], user_email='john.smith@foo.com', ) + from credal.common import ( + ResourceIdentifier_ExternalResourceId, + ResourceIdentifier_Url, + ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.permissions_service.check_bulk_resources_authorization_for_user( + resource_identifiers=[ + ResourceIdentifier_Url( + url="https://docs.google.com/document/d/170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr/edit", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="sfsdfvr54UvyslPVWkQFOA0dfsdfsdflgNycFmdZJQr", + resource_type="ZENDESK_TICKET", + ), + ], + user_email="john.smith@foo.com", + ) """ _response = self._raw_client.check_bulk_resources_authorization_for_user( resource_identifiers=resource_identifiers, @@ -155,8 +180,13 @@ def list_cached_authorized_resources_for_user( Examples -------- from credal import CredalApi - client = CredalApi(api_key="YOUR_API_KEY", ) - client.permissions_service.list_cached_authorized_resources_for_user(user_email='john.smith@foo.com', ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.permissions_service.list_cached_authorized_resources_for_user( + user_email="john.smith@foo.com", + ) """ _response = self._raw_client.list_cached_authorized_resources_for_user( user_email=user_email, @@ -214,12 +244,26 @@ async def check_resource_authorization_for_user( Examples -------- + import asyncio + from credal import AsyncCredalApi from credal.common import ResourceIdentifier_ExternalResourceId - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.permissions_service.check_resource_authorization_for_user(resource_identifier=ResourceIdentifier_ExternalResourceId(external_resource_id='170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr', resource_type="GOOGLE_DRIVE_ITEM", ), user_email='john.smith@foo.com', ) + await client.permissions_service.check_resource_authorization_for_user( + resource_identifier=ResourceIdentifier_ExternalResourceId( + external_resource_id="170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr", + resource_type="GOOGLE_DRIVE_ITEM", + ), + user_email="john.smith@foo.com", + ) + + asyncio.run(main()) """ _response = await self._raw_client.check_resource_authorization_for_user( @@ -261,13 +305,34 @@ async def check_bulk_resources_authorization_for_user( Examples -------- - from credal import AsyncCredalApi - from credal.common import ResourceIdentifier_Url - from credal.common import ResourceIdentifier_ExternalResourceId import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + from credal import AsyncCredalApi + from credal.common import ( + ResourceIdentifier_ExternalResourceId, + ResourceIdentifier_Url, + ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.permissions_service.check_bulk_resources_authorization_for_user(resource_identifiers=[ResourceIdentifier_Url(url='https://docs.google.com/document/d/170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr/edit', ), ResourceIdentifier_ExternalResourceId(external_resource_id='sfsdfvr54UvyslPVWkQFOA0dfsdfsdflgNycFmdZJQr', resource_type="ZENDESK_TICKET", )], user_email='john.smith@foo.com', ) + await client.permissions_service.check_bulk_resources_authorization_for_user( + resource_identifiers=[ + ResourceIdentifier_Url( + url="https://docs.google.com/document/d/170NrBm0Do7gdzvr54UvyslPVWkQFOA0lgNycFmdZJQr/edit", + ), + ResourceIdentifier_ExternalResourceId( + external_resource_id="sfsdfvr54UvyslPVWkQFOA0dfsdfsdflgNycFmdZJQr", + resource_type="ZENDESK_TICKET", + ), + ], + user_email="john.smith@foo.com", + ) + + asyncio.run(main()) """ _response = await self._raw_client.check_bulk_resources_authorization_for_user( @@ -313,11 +378,21 @@ async def list_cached_authorized_resources_for_user( Examples -------- - from credal import AsyncCredalApi import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + from credal import AsyncCredalApi + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.permissions_service.list_cached_authorized_resources_for_user(user_email='john.smith@foo.com', ) + await client.permissions_service.list_cached_authorized_resources_for_user( + user_email="john.smith@foo.com", + ) + + asyncio.run(main()) """ _response = await self._raw_client.list_cached_authorized_resources_for_user( diff --git a/src/credal/search/client.py b/src/credal/search/client.py index 9ca787d..7b7cb0e 100644 --- a/src/credal/search/client.py +++ b/src/credal/search/client.py @@ -69,12 +69,36 @@ def search_document_collection( Examples -------- - from credal import CredalApi import uuid - from credal.search import SingleFieldFilter - from credal.search import DocumentCollectionSearchOptions - client = CredalApi(api_key="YOUR_API_KEY", ) - client.search.search_document_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), search_query='ABC Corp', structured_query_filters=[SingleFieldFilter(field='status', operator="==", value='Open', )], user_email='jack@credal.ai', search_options=DocumentCollectionSearchOptions(max_chunks=10, merge_contents=True, threshold=0.8, enable_smart_filtering=True, enable_query_extraction=True, enable_reranking=True, ), ) + + from credal import CredalApi + from credal.search import DocumentCollectionSearchOptions, SingleFieldFilter + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.search.search_document_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + search_query="ABC Corp", + structured_query_filters=[ + SingleFieldFilter( + field="status", + operator="==", + value="Open", + ) + ], + user_email="jack@credal.ai", + search_options=DocumentCollectionSearchOptions( + max_chunks=10, + merge_contents=True, + threshold=0.8, + enable_smart_filtering=True, + enable_query_extraction=True, + enable_reranking=True, + ), + ) """ _response = self._raw_client.search_document_collection( collection_id=collection_id, @@ -143,14 +167,42 @@ async def search_document_collection( Examples -------- - from credal import AsyncCredalApi - import uuid - from credal.search import SingleFieldFilter - from credal.search import DocumentCollectionSearchOptions import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + import uuid + + from credal import AsyncCredalApi + from credal.search import DocumentCollectionSearchOptions, SingleFieldFilter + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.search.search_document_collection(collection_id=uuid.UUID("82e4b12a-6990-45d4-8ebd-85c00e030c24", ), search_query='ABC Corp', structured_query_filters=[SingleFieldFilter(field='status', operator="==", value='Open', )], user_email='jack@credal.ai', search_options=DocumentCollectionSearchOptions(max_chunks=10, merge_contents=True, threshold=0.8, enable_smart_filtering=True, enable_query_extraction=True, enable_reranking=True, ), ) + await client.search.search_document_collection( + collection_id=uuid.UUID( + "82e4b12a-6990-45d4-8ebd-85c00e030c24", + ), + search_query="ABC Corp", + structured_query_filters=[ + SingleFieldFilter( + field="status", + operator="==", + value="Open", + ) + ], + user_email="jack@credal.ai", + search_options=DocumentCollectionSearchOptions( + max_chunks=10, + merge_contents=True, + threshold=0.8, + enable_smart_filtering=True, + enable_query_extraction=True, + enable_reranking=True, + ), + ) + + asyncio.run(main()) """ _response = await self._raw_client.search_document_collection( diff --git a/src/credal/users/client.py b/src/credal/users/client.py index 77c1cee..55dab82 100644 --- a/src/credal/users/client.py +++ b/src/credal/users/client.py @@ -47,10 +47,22 @@ def metadata( -------- from credal import CredalApi from credal.users import UserMetadataPatch - client = CredalApi(api_key="YOUR_API_KEY", ) - client.users.metadata(request=[UserMetadataPatch(metadata={'State': 'NY', 'Job Role': 'CEO'} - , user_email='ravin@credal.ai', ), UserMetadataPatch(metadata={'State': 'NY', 'Department': 'Engineering'} - , user_email='jack@credal.ai', )], ) + + client = CredalApi( + api_key="YOUR_API_KEY", + ) + client.users.metadata( + request=[ + UserMetadataPatch( + metadata={"State": "NY", "Job Role": "CEO"}, + user_email="ravin@credal.ai", + ), + UserMetadataPatch( + metadata={"State": "NY", "Department": "Engineering"}, + user_email="jack@credal.ai", + ), + ], + ) """ _response = self._raw_client.metadata(request=request, request_options=request_options) return _response.data @@ -90,14 +102,31 @@ async def metadata( Examples -------- + import asyncio + from credal import AsyncCredalApi from credal.users import UserMetadataPatch - import asyncio - client = AsyncCredalApi(api_key="YOUR_API_KEY", ) + + client = AsyncCredalApi( + api_key="YOUR_API_KEY", + ) + + async def main() -> None: - await client.users.metadata(request=[UserMetadataPatch(metadata={'State': 'NY', 'Job Role': 'CEO'} - , user_email='ravin@credal.ai', ), UserMetadataPatch(metadata={'State': 'NY', 'Department': 'Engineering'} - , user_email='jack@credal.ai', )], ) + await client.users.metadata( + request=[ + UserMetadataPatch( + metadata={"State": "NY", "Job Role": "CEO"}, + user_email="ravin@credal.ai", + ), + UserMetadataPatch( + metadata={"State": "NY", "Department": "Engineering"}, + user_email="jack@credal.ai", + ), + ], + ) + + asyncio.run(main()) """ _response = await self._raw_client.metadata(request=request, request_options=request_options)