Download data/src/elevenlabs/conversational_ai/knowledge_base/documents/client.py from introvoyz045/elevenlabs-python: direct link, hf CLI and curl.
- Browser
- Download file 48.2 kB
-
https://huggingface.co/datasets/introvoyz045/elevenlabs-python/resolve/main/data/src/elevenlabs/conversational_ai/knowledge_base/documents/client.py
- Command line
-
hf download hf://datasets/introvoyz045/elevenlabs-python/data/src/elevenlabs/conversational_ai/knowledge_base/documents/client.py
-
curl -L -o client.py https://huggingface.co/datasets/introvoyz045/elevenlabs-python/resolve/main/data/src/elevenlabs/conversational_ai/knowledge_base/documents/client.py
48.2 kB
# This file was auto-generated by Fern from our API Definition.
from __future__ import annotations
import typing
from .... import core
from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ....core.request_options import RequestOptions
from ....types.add_knowledge_base_response_model import AddKnowledgeBaseResponseModel
from ....types.get_knowledge_base_dependent_agents_response_model import GetKnowledgeBaseDependentAgentsResponseModel
from ....types.knowledge_base_dependent_type import KnowledgeBaseDependentType
from ....types.knowledge_base_source_file_url_response_model import KnowledgeBaseSourceFileUrlResponseModel
from .raw_client import AsyncRawDocumentsClient, RawDocumentsClient
from .types.documents_bulk_delete_response_value import DocumentsBulkDeleteResponseValue
from .types.documents_get_response import DocumentsGetResponse
from .types.documents_update_response import DocumentsUpdateResponse
if typing.TYPE_CHECKING:
from .chunk.client import AsyncChunkClient, ChunkClient
from .chunks.client import AsyncChunksClient, ChunksClient
from .summaries.client import AsyncSummariesClient, SummariesClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class DocumentsClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawDocumentsClient(client_wrapper=client_wrapper)
self._client_wrapper = client_wrapper
self._summaries: typing.Optional[SummariesClient] = None
self._chunk: typing.Optional[ChunkClient] = None
self._chunks: typing.Optional[ChunksClient] = None
@property
def with_raw_response(self) -> RawDocumentsClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawDocumentsClient
"""
return self._raw_client
def create_from_url(
self,
*,
url: str,
name: typing.Optional[str] = OMIT,
parent_folder_id: typing.Optional[str] = OMIT,
enable_auto_sync: typing.Optional[bool] = OMIT,
auto_remove: typing.Optional[bool] = OMIT,
minimum_frequency_days: typing.Optional[int] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a knowledge base document generated by scraping the given webpage.
Parameters
----------
url : str
URL to a page of documentation that the agent will have access to in order to interact with users.
name : typing.Optional[str]
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
enable_auto_sync : typing.Optional[bool]
Whether to enable auto-sync for this URL document.
auto_remove : typing.Optional[bool]
Whether to automatically remove the document if the URL becomes unavailable. Only applicable when auto-sync is enabled.
minimum_frequency_days : typing.Optional[int]
Minimum frequency (in days) at which the document is refreshed. The actual interval may be shorter, never longer. Defaults to 7, tightened to the parent folder's frequency if that is stricter. Only applicable when auto-sync is enabled.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.create_from_url(
url="url",
)
"""
_response = self._raw_client.create_from_url(
url=url,
name=name,
parent_folder_id=parent_folder_id,
enable_auto_sync=enable_auto_sync,
auto_remove=auto_remove,
minimum_frequency_days=minimum_frequency_days,
request_options=request_options,
)
return _response.data
def create_from_file(
self,
*,
file: core.File,
name: typing.Optional[str] = OMIT,
parent_folder_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a knowledge base document generated form the uploaded file.
Parameters
----------
file : core.File
See core.File for more documentation
name : typing.Optional[str]
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.create_from_file()
"""
_response = self._raw_client.create_from_file(
file=file, name=name, parent_folder_id=parent_folder_id, request_options=request_options
)
return _response.data
def create_from_text(
self,
*,
text: str,
name: typing.Optional[str] = OMIT,
parent_folder_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a knowledge base document containing the provided text.
Parameters
----------
text : str
Text content to be added to the knowledge base.
name : typing.Optional[str]
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.create_from_text(
text="text",
)
"""
_response = self._raw_client.create_from_text(
text=text, name=name, parent_folder_id=parent_folder_id, request_options=request_options
)
return _response.data
def create_folder(
self,
*,
name: str,
parent_folder_id: typing.Optional[str] = OMIT,
enable_auto_sync: typing.Optional[bool] = OMIT,
auto_remove: typing.Optional[bool] = OMIT,
minimum_frequency_days: typing.Optional[int] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a folder used for grouping documents together.
Parameters
----------
name : str
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
enable_auto_sync : typing.Optional[bool]
Whether to enable auto-sync for this URL document.
auto_remove : typing.Optional[bool]
Whether to automatically remove the document if the URL becomes unavailable. Only applicable when auto-sync is enabled.
minimum_frequency_days : typing.Optional[int]
Minimum frequency (in days) at which the underlying eligible documents are refreshed. The actual interval may be shorter, never longer. Defaults to 7, tightened to the parent folder's frequency if that is stricter. Only applicable when auto-sync is enabled.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.create_folder(
name="name",
)
"""
_response = self._raw_client.create_folder(
name=name,
parent_folder_id=parent_folder_id,
enable_auto_sync=enable_auto_sync,
auto_remove=auto_remove,
minimum_frequency_days=minimum_frequency_days,
request_options=request_options,
)
return _response.data
def get(
self,
documentation_id: str,
*,
agent_id: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> DocumentsGetResponse:
"""
Get details about a specific documentation making up the agent's knowledge base
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
agent_id : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
DocumentsGetResponse
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.get(
documentation_id="21m00Tcm4TlvDq8ikWAM",
agent_id="agent_id",
)
"""
_response = self._raw_client.get(documentation_id, agent_id=agent_id, request_options=request_options)
return _response.data
def delete(
self,
documentation_id: str,
*,
force: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> typing.Any:
"""
Delete a document or folder from the knowledge base.
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
force : typing.Optional[bool]
If set to true, the document or folder will be deleted regardless of whether it is used by any agents and it will be removed from the dependent agents. For non-empty folders, this will also delete all child documents and folders.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.Any
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.delete(
documentation_id="21m00Tcm4TlvDq8ikWAM",
force=True,
)
"""
_response = self._raw_client.delete(documentation_id, force=force, request_options=request_options)
return _response.data
def update(
self,
documentation_id: str,
*,
name: typing.Optional[str] = OMIT,
content: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> DocumentsUpdateResponse:
"""
Update the name and/or content of a document.
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
name : typing.Optional[str]
A custom, human-readable name for the document.
content : typing.Optional[str]
Updated content for the document. Only supported for text documents, URL documents with auto-sync disabled, and file documents that are not synced from an external source.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
DocumentsUpdateResponse
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.update(
documentation_id="21m00Tcm4TlvDq8ikWAM",
)
"""
_response = self._raw_client.update(
documentation_id, name=name, content=content, request_options=request_options
)
return _response.data
def get_agents(
self,
documentation_id: str,
*,
dependent_type: typing.Optional[KnowledgeBaseDependentType] = None,
page_size: typing.Optional[int] = None,
cursor: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetKnowledgeBaseDependentAgentsResponseModel:
"""
Get a list of agents depending on this knowledge base document
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
dependent_type : typing.Optional[KnowledgeBaseDependentType]
Type of dependent agents to return.
page_size : typing.Optional[int]
How many documents to return at maximum. Can not exceed 100, defaults to 30.
cursor : typing.Optional[str]
Used for fetching next page. Cursor is returned in the response.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetKnowledgeBaseDependentAgentsResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.get_agents(
documentation_id="21m00Tcm4TlvDq8ikWAM",
dependent_type="direct",
page_size=1,
cursor="cursor",
)
"""
_response = self._raw_client.get_agents(
documentation_id,
dependent_type=dependent_type,
page_size=page_size,
cursor=cursor,
request_options=request_options,
)
return _response.data
def get_bulk_agents(
self,
*,
document_ids: typing.Sequence[str],
dependent_type: typing.Optional[KnowledgeBaseDependentType] = None,
page_size: typing.Optional[int] = None,
cursor: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetKnowledgeBaseDependentAgentsResponseModel:
"""
Get a list of agents depending on any of the given knowledge base documents.
Parameters
----------
document_ids : typing.Sequence[str]
The ids of documents or folders from the knowledge base.
dependent_type : typing.Optional[KnowledgeBaseDependentType]
Type of dependent agents to return.
page_size : typing.Optional[int]
How many documents to return at maximum. Can not exceed 100, defaults to 30.
cursor : typing.Optional[str]
Used for fetching next page. Cursor is returned in the response.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetKnowledgeBaseDependentAgentsResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.get_bulk_agents(
dependent_type="direct",
page_size=1,
cursor="cursor",
document_ids=["21m00Tcm4TlvDq8ikWAM", "31m00Tcm4TlvDq8ikWBM"],
)
"""
_response = self._raw_client.get_bulk_agents(
document_ids=document_ids,
dependent_type=dependent_type,
page_size=page_size,
cursor=cursor,
request_options=request_options,
)
return _response.data
def get_content(self, documentation_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> str:
"""
Get the entire content of a document from the knowledge base
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
str
Streaming document content
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.get_content(
documentation_id="documentation_id",
)
"""
_response = self._raw_client.get_content(documentation_id, request_options=request_options)
return _response.data
def get_source_file_url(
self, documentation_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> KnowledgeBaseSourceFileUrlResponseModel:
"""
Get a signed URL to download the original source file of a file-type document from the knowledge base
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
KnowledgeBaseSourceFileUrlResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.get_source_file_url(
documentation_id="21m00Tcm4TlvDq8ikWAM",
)
"""
_response = self._raw_client.get_source_file_url(documentation_id, request_options=request_options)
return _response.data
def move(
self,
document_id: str,
*,
move_to: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Moves the entity from one folder to another.
Parameters
----------
document_id : str
The id of a document from the knowledge base. This is returned on document addition.
move_to : typing.Optional[str]
The folder to move the entities to. If not set, the entities will be moved to the root folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.move(
document_id="21m00Tcm4TlvDq8ikWAM",
)
"""
_response = self._raw_client.move(document_id, move_to=move_to, request_options=request_options)
return _response.data
def bulk_move(
self,
*,
document_ids: typing.Sequence[str],
move_to: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Moves multiple entities from one folder to another.
Parameters
----------
document_ids : typing.Sequence[str]
The ids of documents or folders from the knowledge base.
move_to : typing.Optional[str]
The folder to move the entities to. If not set, the entities will be moved to the root folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.bulk_move(
document_ids=["21m00Tcm4TlvDq8ikWAM", "31m00Tcm4TlvDq8ikWBM"],
)
"""
_response = self._raw_client.bulk_move(
document_ids=document_ids, move_to=move_to, request_options=request_options
)
return _response.data
def bulk_delete(
self,
*,
document_ids: typing.Sequence[str],
force: typing.Optional[bool] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> typing.Dict[str, DocumentsBulkDeleteResponseValue]:
"""
Delete multiple documents or folders from the knowledge base. Each id succeeds or fails independently.
Parameters
----------
document_ids : typing.Sequence[str]
The ids of documents or folders from the knowledge base.
force : typing.Optional[bool]
If set to true, documents or folders will be deleted regardless of whether they are used by any agents and will be removed from the dependent agents. For non-empty folders, this will also delete all child documents and folders.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.Dict[str, DocumentsBulkDeleteResponseValue]
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.bulk_delete(
document_ids=["21m00Tcm4TlvDq8ikWAM", "31m00Tcm4TlvDq8ikWBM"],
)
"""
_response = self._raw_client.bulk_delete(
document_ids=document_ids, force=force, request_options=request_options
)
return _response.data
@property
def summaries(self):
if self._summaries is None:
from .summaries.client import SummariesClient # noqa: E402
self._summaries = SummariesClient(client_wrapper=self._client_wrapper)
return self._summaries
@property
def chunk(self):
if self._chunk is None:
from .chunk.client import ChunkClient # noqa: E402
self._chunk = ChunkClient(client_wrapper=self._client_wrapper)
return self._chunk
@property
def chunks(self):
if self._chunks is None:
from .chunks.client import ChunksClient # noqa: E402
self._chunks = ChunksClient(client_wrapper=self._client_wrapper)
return self._chunks
class AsyncDocumentsClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._raw_client = AsyncRawDocumentsClient(client_wrapper=client_wrapper)
self._client_wrapper = client_wrapper
self._summaries: typing.Optional[AsyncSummariesClient] = None
self._chunk: typing.Optional[AsyncChunkClient] = None
self._chunks: typing.Optional[AsyncChunksClient] = None
@property
def with_raw_response(self) -> AsyncRawDocumentsClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
AsyncRawDocumentsClient
"""
return self._raw_client
async def create_from_url(
self,
*,
url: str,
name: typing.Optional[str] = OMIT,
parent_folder_id: typing.Optional[str] = OMIT,
enable_auto_sync: typing.Optional[bool] = OMIT,
auto_remove: typing.Optional[bool] = OMIT,
minimum_frequency_days: typing.Optional[int] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a knowledge base document generated by scraping the given webpage.
Parameters
----------
url : str
URL to a page of documentation that the agent will have access to in order to interact with users.
name : typing.Optional[str]
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
enable_auto_sync : typing.Optional[bool]
Whether to enable auto-sync for this URL document.
auto_remove : typing.Optional[bool]
Whether to automatically remove the document if the URL becomes unavailable. Only applicable when auto-sync is enabled.
minimum_frequency_days : typing.Optional[int]
Minimum frequency (in days) at which the document is refreshed. The actual interval may be shorter, never longer. Defaults to 7, tightened to the parent folder's frequency if that is stricter. Only applicable when auto-sync is enabled.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.create_from_url(
url="url",
)
asyncio.run(main())
"""
_response = await self._raw_client.create_from_url(
url=url,
name=name,
parent_folder_id=parent_folder_id,
enable_auto_sync=enable_auto_sync,
auto_remove=auto_remove,
minimum_frequency_days=minimum_frequency_days,
request_options=request_options,
)
return _response.data
async def create_from_file(
self,
*,
file: core.File,
name: typing.Optional[str] = OMIT,
parent_folder_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a knowledge base document generated form the uploaded file.
Parameters
----------
file : core.File
See core.File for more documentation
name : typing.Optional[str]
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.create_from_file()
asyncio.run(main())
"""
_response = await self._raw_client.create_from_file(
file=file, name=name, parent_folder_id=parent_folder_id, request_options=request_options
)
return _response.data
async def create_from_text(
self,
*,
text: str,
name: typing.Optional[str] = OMIT,
parent_folder_id: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a knowledge base document containing the provided text.
Parameters
----------
text : str
Text content to be added to the knowledge base.
name : typing.Optional[str]
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.create_from_text(
text="text",
)
asyncio.run(main())
"""
_response = await self._raw_client.create_from_text(
text=text, name=name, parent_folder_id=parent_folder_id, request_options=request_options
)
return _response.data
async def create_folder(
self,
*,
name: str,
parent_folder_id: typing.Optional[str] = OMIT,
enable_auto_sync: typing.Optional[bool] = OMIT,
auto_remove: typing.Optional[bool] = OMIT,
minimum_frequency_days: typing.Optional[int] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a folder used for grouping documents together.
Parameters
----------
name : str
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
enable_auto_sync : typing.Optional[bool]
Whether to enable auto-sync for this URL document.
auto_remove : typing.Optional[bool]
Whether to automatically remove the document if the URL becomes unavailable. Only applicable when auto-sync is enabled.
minimum_frequency_days : typing.Optional[int]
Minimum frequency (in days) at which the underlying eligible documents are refreshed. The actual interval may be shorter, never longer. Defaults to 7, tightened to the parent folder's frequency if that is stricter. Only applicable when auto-sync is enabled.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.create_folder(
name="name",
)
asyncio.run(main())
"""
_response = await self._raw_client.create_folder(
name=name,
parent_folder_id=parent_folder_id,
enable_auto_sync=enable_auto_sync,
auto_remove=auto_remove,
minimum_frequency_days=minimum_frequency_days,
request_options=request_options,
)
return _response.data
async def get(
self,
documentation_id: str,
*,
agent_id: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> DocumentsGetResponse:
"""
Get details about a specific documentation making up the agent's knowledge base
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
agent_id : typing.Optional[str]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
DocumentsGetResponse
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.get(
documentation_id="21m00Tcm4TlvDq8ikWAM",
agent_id="agent_id",
)
asyncio.run(main())
"""
_response = await self._raw_client.get(documentation_id, agent_id=agent_id, request_options=request_options)
return _response.data
async def delete(
self,
documentation_id: str,
*,
force: typing.Optional[bool] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> typing.Any:
"""
Delete a document or folder from the knowledge base.
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
force : typing.Optional[bool]
If set to true, the document or folder will be deleted regardless of whether it is used by any agents and it will be removed from the dependent agents. For non-empty folders, this will also delete all child documents and folders.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.Any
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.delete(
documentation_id="21m00Tcm4TlvDq8ikWAM",
force=True,
)
asyncio.run(main())
"""
_response = await self._raw_client.delete(documentation_id, force=force, request_options=request_options)
return _response.data
async def update(
self,
documentation_id: str,
*,
name: typing.Optional[str] = OMIT,
content: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> DocumentsUpdateResponse:
"""
Update the name and/or content of a document.
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
name : typing.Optional[str]
A custom, human-readable name for the document.
content : typing.Optional[str]
Updated content for the document. Only supported for text documents, URL documents with auto-sync disabled, and file documents that are not synced from an external source.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
DocumentsUpdateResponse
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.update(
documentation_id="21m00Tcm4TlvDq8ikWAM",
)
asyncio.run(main())
"""
_response = await self._raw_client.update(
documentation_id, name=name, content=content, request_options=request_options
)
return _response.data
async def get_agents(
self,
documentation_id: str,
*,
dependent_type: typing.Optional[KnowledgeBaseDependentType] = None,
page_size: typing.Optional[int] = None,
cursor: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetKnowledgeBaseDependentAgentsResponseModel:
"""
Get a list of agents depending on this knowledge base document
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
dependent_type : typing.Optional[KnowledgeBaseDependentType]
Type of dependent agents to return.
page_size : typing.Optional[int]
How many documents to return at maximum. Can not exceed 100, defaults to 30.
cursor : typing.Optional[str]
Used for fetching next page. Cursor is returned in the response.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetKnowledgeBaseDependentAgentsResponseModel
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.get_agents(
documentation_id="21m00Tcm4TlvDq8ikWAM",
dependent_type="direct",
page_size=1,
cursor="cursor",
)
asyncio.run(main())
"""
_response = await self._raw_client.get_agents(
documentation_id,
dependent_type=dependent_type,
page_size=page_size,
cursor=cursor,
request_options=request_options,
)
return _response.data
async def get_bulk_agents(
self,
*,
document_ids: typing.Sequence[str],
dependent_type: typing.Optional[KnowledgeBaseDependentType] = None,
page_size: typing.Optional[int] = None,
cursor: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetKnowledgeBaseDependentAgentsResponseModel:
"""
Get a list of agents depending on any of the given knowledge base documents.
Parameters
----------
document_ids : typing.Sequence[str]
The ids of documents or folders from the knowledge base.
dependent_type : typing.Optional[KnowledgeBaseDependentType]
Type of dependent agents to return.
page_size : typing.Optional[int]
How many documents to return at maximum. Can not exceed 100, defaults to 30.
cursor : typing.Optional[str]
Used for fetching next page. Cursor is returned in the response.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetKnowledgeBaseDependentAgentsResponseModel
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.get_bulk_agents(
dependent_type="direct",
page_size=1,
cursor="cursor",
document_ids=["21m00Tcm4TlvDq8ikWAM", "31m00Tcm4TlvDq8ikWBM"],
)
asyncio.run(main())
"""
_response = await self._raw_client.get_bulk_agents(
document_ids=document_ids,
dependent_type=dependent_type,
page_size=page_size,
cursor=cursor,
request_options=request_options,
)
return _response.data
async def get_content(
self, documentation_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> str:
"""
Get the entire content of a document from the knowledge base
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
str
Streaming document content
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.get_content(
documentation_id="documentation_id",
)
asyncio.run(main())
"""
_response = await self._raw_client.get_content(documentation_id, request_options=request_options)
return _response.data
async def get_source_file_url(
self, documentation_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> KnowledgeBaseSourceFileUrlResponseModel:
"""
Get a signed URL to download the original source file of a file-type document from the knowledge base
Parameters
----------
documentation_id : str
The id of a document from the knowledge base. This is returned on document addition.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
KnowledgeBaseSourceFileUrlResponseModel
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.get_source_file_url(
documentation_id="21m00Tcm4TlvDq8ikWAM",
)
asyncio.run(main())
"""
_response = await self._raw_client.get_source_file_url(documentation_id, request_options=request_options)
return _response.data
async def move(
self,
document_id: str,
*,
move_to: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Moves the entity from one folder to another.
Parameters
----------
document_id : str
The id of a document from the knowledge base. This is returned on document addition.
move_to : typing.Optional[str]
The folder to move the entities to. If not set, the entities will be moved to the root folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.move(
document_id="21m00Tcm4TlvDq8ikWAM",
)
asyncio.run(main())
"""
_response = await self._raw_client.move(document_id, move_to=move_to, request_options=request_options)
return _response.data
async def bulk_move(
self,
*,
document_ids: typing.Sequence[str],
move_to: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> None:
"""
Moves multiple entities from one folder to another.
Parameters
----------
document_ids : typing.Sequence[str]
The ids of documents or folders from the knowledge base.
move_to : typing.Optional[str]
The folder to move the entities to. If not set, the entities will be moved to the root folder.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
None
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.bulk_move(
document_ids=["21m00Tcm4TlvDq8ikWAM", "31m00Tcm4TlvDq8ikWBM"],
)
asyncio.run(main())
"""
_response = await self._raw_client.bulk_move(
document_ids=document_ids, move_to=move_to, request_options=request_options
)
return _response.data
async def bulk_delete(
self,
*,
document_ids: typing.Sequence[str],
force: typing.Optional[bool] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> typing.Dict[str, DocumentsBulkDeleteResponseValue]:
"""
Delete multiple documents or folders from the knowledge base. Each id succeeds or fails independently.
Parameters
----------
document_ids : typing.Sequence[str]
The ids of documents or folders from the knowledge base.
force : typing.Optional[bool]
If set to true, documents or folders will be deleted regardless of whether they are used by any agents and will be removed from the dependent agents. For non-empty folders, this will also delete all child documents and folders.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
typing.Dict[str, DocumentsBulkDeleteResponseValue]
Successful Response
Examples
--------
import asyncio
from elevenlabs import AsyncElevenLabs
client = AsyncElevenLabs(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.conversational_ai.knowledge_base.documents.bulk_delete(
document_ids=["21m00Tcm4TlvDq8ikWAM", "31m00Tcm4TlvDq8ikWBM"],
)
asyncio.run(main())
"""
_response = await self._raw_client.bulk_delete(
document_ids=document_ids, force=force, request_options=request_options
)
return _response.data
@property
def summaries(self):
if self._summaries is None:
from .summaries.client import AsyncSummariesClient # noqa: E402
self._summaries = AsyncSummariesClient(client_wrapper=self._client_wrapper)
return self._summaries
@property
def chunk(self):
if self._chunk is None:
from .chunk.client import AsyncChunkClient # noqa: E402
self._chunk = AsyncChunkClient(client_wrapper=self._client_wrapper)
return self._chunk
@property
def chunks(self):
if self._chunks is None:
from .chunks.client import AsyncChunksClient # noqa: E402
self._chunks = AsyncChunksClient(client_wrapper=self._client_wrapper)
return self._chunks
# This file was auto-generated by Fern from our API Definition.
from __future__ import annotations
import typing
from .... import core
from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ....core.request_options import RequestOptions
from ....types.add_knowledge_base_response_model import AddKnowledgeBaseResponseModel
from ....types.get_knowledge_base_dependent_agents_response_model import GetKnowledgeBaseDependentAgentsResponseModel
from ....types.knowledge_base_dependent_type import KnowledgeBaseDependentType
from ....types.knowledge_base_source_file_url_response_model import KnowledgeBaseSourceFileUrlResponseModel
from .raw_client import AsyncRawDocumentsClient, RawDocumentsClient
from .types.documents_bulk_delete_response_value import DocumentsBulkDeleteResponseValue
from .types.documents_get_response import DocumentsGetResponse
from .types.documents_update_response import DocumentsUpdateResponse
if typing.TYPE_CHECKING:
from .chunk.client import AsyncChunkClient, ChunkClient
from .chunks.client import AsyncChunksClient, ChunksClient
from .summaries.client import AsyncSummariesClient, SummariesClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class DocumentsClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawDocumentsClient(client_wrapper=client_wrapper)
self._client_wrapper = client_wrapper
self._summaries: typing.Optional[SummariesClient] = None
self._chunk: typing.Optional[ChunkClient] = None
self._chunks: typing.Optional[ChunksClient] = None
def with_raw_response(self) -> RawDocumentsClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawDocumentsClient
"""
return self._raw_client
def create_from_url(
self,
*,
url: str,
name: typing.Optional[str] = OMIT,
parent_folder_id: typing.Optional[str] = OMIT,
enable_auto_sync: typing.Optional[bool] = OMIT,
auto_remove: typing.Optional[bool] = OMIT,
minimum_frequency_days: typing.Optional[int] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> AddKnowledgeBaseResponseModel:
"""
Create a knowledge base document generated by scraping the given webpage.
Parameters
----------
url : str
URL to a page of documentation that the agent will have access to in order to interact with users.
name : typing.Optional[str]
A custom, human-readable name for the document.
parent_folder_id : typing.Optional[str]
If set, the created document or folder will be placed inside the given folder.
enable_auto_sync : typing.Optional[bool]
Whether to enable auto-sync for this URL document.
auto_remove : typing.Optional[bool]
Whether to automatically remove the document if the URL becomes unavailable. Only applicable when auto-sync is enabled.
minimum_frequency_days : typing.Optional[int]
Minimum frequency (in days) at which the document is refreshed. The actual interval may be shorter, never longer. Defaults to 7, tightened to the parent folder's frequency if that is stricter. Only applicable when auto-sync is enabled.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
AddKnowledgeBaseResponseModel
Successful Response
Examples
--------
from elevenlabs import ElevenLabs
client = ElevenLabs(
api_key="YOUR_API_KEY",
)
client.conversational_ai.knowledge_base.documents.create_from_url(
url="url",
)
"""
_response = self._raw_client.create_from_url(
url=url,