Skip to main content

CosmosHub client.

Project description

Delos CosmosHub

CosmosHub client for interacting with the CosmosHub API.

Installation

To install the package, use pip:

pip install delos-cosmoshub

Or if you are using poetry:

poetry add delos-cosmoshub

Client Initialization

You can create an API key to access all services through CosmosPlatform https://platform.cosmos-suite.ai/dashboard/keys.

To create a CosmosHub client instance, you need to initialize it with your API key, and optionally the server URL:

from delos_cosmoshub import CosmosHubClient

client = CosmosHubClient("your-api-key") # will be equivalent to:
client = CosmosHubClient("your-api-key", "https://platform.cosmos-suite.ai", debug_mode=False)

Endpoints

This delos-cosmoshub client provides access to the following endpoints:

Status Endpoints

  • status_health_request: Check the health of the server.

Translate Endpoints

  • translate_text_request: Translate text.
  • translate_file_request: Translate a file.

Web Endpoints

  • web_search_request: Perform a web search.

LLM Endpoints

  • chat: Chat with the LLM.
  • embed: Embed data into the LLM.

Files Endpoints

  • files_chunker_request: Chunk a file.
  • files_index_operation_request: Index group a set of files in order to be able to query them using natural language.
  • files_index_operation_request: Ask a question about the index documents (it requires that your index.status.vectorized is set to True).
  • files_index_operation_request: Embed data into an index.
  • files_index_operation_request: List all indexes.
  • files_index_operation_request: Get details of an index.

These endpoints are accessible through delos-cosmoshub client methods.

ℹ️ Info: For all the endpoints, there are specific models that structure the data to be sent to the API.

They may contain the text or files to operate with, the output_language for your result, the index_uuid that identifies the set of documents, the model to use for the LLM operations, etc.

You can find them in the delos_cosmoshub.models module.


Status Endpoints

Status Health Request

To check the health of the server and the validity of your API key:

response = client.status_health_request()
if response:
    print(f"Response: {response}")

Translate Endpoints

1. Translate Text Request

To translate text, you can use the translate_text_request method:

from delos_cosmoshub.models import TranslateTextData

translate_data = TranslateTextData(text="Hello, world!", target_language="fr")
response = client.translate_text_request(translate_data)
if response:
    print(f"Translated Text: {response}")

2. Translate File Request

To translate a file, use the translate_file_request method:

from delos_cosmoshub.models import TranslateFileData

translate_file_data = TranslateFileData(file=my_file, target_language="es")
response = client.translate_file_request(translate_file_data)
if response:
    print(f"Translated File Response: {response}")

Web Endpoints

Web Search Request

To perform a web search:

from delos_cosmoshub.models import SearchData

search_data = SearchData(query="CosmosHub")
response = client.web_search_request(search_data)
if response:
    print(f"Search Results: {response}")

LLM Endpoints

1. Chat Request

To chat with the LLM:

from delos_cosmoshub.models import ChatData

chat_data = ChatData(text="Hello, how are you?", model="gpt-4o-mini")
response = client.chat(chat_data)
if response:
    print(f"Chat Response: {response}")

2. Embed Request

To embed data using a LLM:

from delos_cosmoshub.models import EmbedData

embed_data = EmbedData(text="Hello, how are you?", model="ada-v2")
response = client.embed(embed_data)
if response:
    print(f"Embed Response: {response}")

Files Endpoints

Files Chunker Request

Universal reader and parser. To chunk a file:

from delos_cosmoshub.models import ChunkerData

chunker_data = ChunkerData(file=my_file)
response = client.files_chunker_request(chunker_data)
if response:
    print(f"Chunked File Response: {response}")

Files Index Operation Request

Index group a set of files in order to be able to query them using natural language. The following operations are available:

  • INDEX_CREATE: Create a new index and parse files.
  • INDEX_ADD_FILES: Add files to an existing index.
  • INDEX_DELETE_FILES: Delete files from an index.
  • INDEX_DELETE: Delete an index. Warning: This is a delayed (2h) operation, allowed to be reverted with INDEX_RESTORE. After 2h, the index will be deleted and not recoverable.
  • INDEX_RESTORE: Restore a deleted index (within the 2h after it was marked for deletion).
  • INDEX_EMBED: Embed data into an index.
  • INDEX_ASK: Ask a question to the index. It requires that INDEX_EMBED is performed to allow index contents querying.
  • INDEX_LIST: List all indexes.
  • INDEX_DETAILS: Get details of an index.

Examples

To create a new index and parse files:

from delos_cosmoshub.data import IndexOperationData, FileEndpoints

index_operation_data = IndexOperationData(files=[my_file], index_uuid="new-index-uuid")
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_CREATE)
if response:
    print(f"Index Create Response: {response}")

To add files to an existing index:

index_operation_data = IndexOperationData(files=[my_file], index_uuid="existing-index-uuid")
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_ADD_FILES)
if response:
    print(f"Add Files to Index Response: {response}")

To delete files from an existing index:

index_operation_data = IndexOperationData(files=[my_file], index_uuid="existing-index-uuid")
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_DELETE_FILES)
if response:
    print(f"Delete Files from Index Response: {response}")

To delete an index (it will be marked for deletion which will become effective after 2h):

index_operation_data = IndexOperationData(index_uuid="index-to-delete-uuid")
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_DELETE)
if response:
    print(f"Delete Index Response: {response}")

To restore an index marked for deletion (only possible during the 2h after the INDEX_DELETE was requested):

index_operation_data = IndexOperationData(index_uuid="index-to-restore-uuid")
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_RESTORE)
if response:
    print(f"Restore Index Response: {response}")

To embed or vectorize index contents in order to allow the query operations:

index_operation_data = IndexOperationData(index_uuid="index-uuid", data_to_embed=my_data)
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_EMBED)
if response:
    print(f"Embed Data Response: {response}")

To ask a question about the index documents (it requires that your index.status.vectorized is set to True):

index_operation_data = IndexOperationData(index_uuid="index-uuid", question="What is CosmosHub?")
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_ASK)
if response:
    print(f"Ask Index Response: {response}")

To list all indexes in your organization, files included and storage details:

response = client.files_index_operation_request(None, FileEndpoints.INDEX_LIST)
if response:
    print(f"List Indexes Response: {response}")

To get details of an index:

index_operation_data = IndexOperationData(index_uuid="index-uuid")
response = client.files_index_operation_request(index_operation_data, FileEndpoints.INDEX_DETAILS)
if response:
    print(f"Index Details Response: {response}")

Development

To contribute to the project, clone the repository and install the dependencies:

git clone https://github.com/yourusername/delos-cosmoshub.git
cd delos-cosmoshub
poetry install

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

For any inquiries, please contact the project maintainers at support@cosmos-suite.ai.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

delos_cosmoshub-0.1.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

delos_cosmoshub-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file delos_cosmoshub-0.1.1.tar.gz.

File metadata

  • Download URL: delos_cosmoshub-0.1.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.7

File hashes

Hashes for delos_cosmoshub-0.1.1.tar.gz
Algorithm Hash digest
SHA256 99fec8c4b541c4f07bd5d0fc0712e6842b6b494e1fccf702c3bd262b99dbb2ce
MD5 f82a9f60751b23eba7dbfdadfd1a49aa
BLAKE2b-256 d59604250162a92a5a60b39fd973f60eaa7d435a7d0fd7fb1c5b29fd4ef311b7

See more details on using hashes here.

File details

Details for the file delos_cosmoshub-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for delos_cosmoshub-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 249d333db816c9f2a66994c1edc8049c3ec86eb0cee3f4da730b6b71682cc9bb
MD5 6f0afc3b51e3a891eea2156492c5e7da
BLAKE2b-256 8d6bbf8a9715b63c38486df51eed1ac437455cad1b14561b6b4db7d06decbabe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page