### Add and Run Python Example Script Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Add a new Python script to the examples directory and make it executable. Then, run the example against your API. ```bash # add an example to examples/.py #!/usr/bin/env -S rye run python … ``` ```bash chmod +x examples/.py # run the example against your api ./examples/.py ``` -------------------------------- ### Install Package from Wheel File Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Install the krutrim-cloud-python package efficiently using the generated wheel file. ```bash pip install ./path-to-wheel-file.whl ``` -------------------------------- ### Install Package from Git Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Install the krutrim-cloud-python package directly from its Git repository using pip. ```bash pip install git+ssh://git@github.com/ola-krutrim/krutrim-cloud-python.git ``` -------------------------------- ### Install FFmpeg on Ubuntu Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md Install FFmpeg on Ubuntu systems using apt-get. This is a manual dependency for certain SDK features. ```sh sudo apt-get update sudo apt-get install ffmpeg ``` -------------------------------- ### Install Krutrim Cloud SDK Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/bring_your_own_model/bring_your_own_model.ipynb Installs the Krutrim Cloud SDK using pip. This is the first step to using the Krutrim Cloud Python library. ```python %pip install krutrim-cloud ``` -------------------------------- ### Set up Mock Server with Prism Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Set up a mock server using Prism against the OpenAPI spec to run tests. Requires npm to be installed. ```bash # you will need npm installed npx prism mock path/to/your/openapi.yml ``` -------------------------------- ### Summarization API Request Example Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md This example demonstrates how to construct a request to the Summarization API. Ensure you provide the required 'text', 'input_language', and 'summary_size' parameters. ```python from krutrim_cloud.types.summarization_response import SummarizationResponse # Example parameters for the summarization request params = { "text": "Krutrim, a part of the Ola group, is working on creating the AI computing stack of the future.\n We endeavor to deliver a state-of-the-art AI computing stack that encompasses the AI computing infrastructure,\n AI Cloud, foundational models, and AI-powered end applications for the Indian market. Our envisioned AI computing\n stack can empower consumers, startups, enterprises and scientists across India and the world to build their end\n AI applications or AI models. While we are building foundational models across text, voice, and vision relevant to\n our focus markets, we are also developing AI training and inference platforms that enable AI research and development\n across industry domains. The platforms being built by Krutrim have the potential to impact millions of lives in India,\n across income and education strata, and across languages. The team at Krutrim represents a convergence of talent across\n AI research, Applied AI, Cloud Engineering, and semiconductor design. Our teams operate from three locations: Bangalore,\n Singapore & San Francisco.", "input_language": "eng", "summary_size": 10 } ``` -------------------------------- ### Install Krutrim Cloud Python Library Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md Install the krutrim-cloud package using pip. This command handles Python dependencies. ```sh pip install krutrim-cloud ``` -------------------------------- ### Speech-to-Speech Translation Example Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md This Python script demonstrates how to use the speech_to_speech_translation API. It requires the krutrim_cloud library and specifies the audio file, source language, and target language for translation. ```python from krutrim_cloud.types.sts_trans_upload_response import StsTransUploadResponse ``` ```text file=@"", src_lang_code="eng", tgt_lang_code="hin" input_speaker="male ``` -------------------------------- ### Chat Completion Request Parameters Example Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Example of a messages list for chat completion requests. ```python [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Hello!" } ] ``` -------------------------------- ### Install Dev Dependencies with Pip Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Install development dependencies using pip if you are not using Rye. Ensure the Python version in .python-version is met and a virtual environment is created. ```sh $ pip install -r requirements-dev.lock ``` -------------------------------- ### Translation API Request Parameters Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Example demonstrating the required and optional parameters for the translation API's `run` method. Ensure correct language codes and text are provided. ```python from krutrim_cloud.types.translation_response import TranslationResponse ``` ```json { "text": "Krutrim, a part of the Ola group, is working on creating the AI computing stack of the future. We endeavor to deliver a state-of-the-art AI computing stack that encompasses the AI computing infrastructure, AI Cloud, foundational models, and AI-powered end applications for the Indian market.", "src_language": "eng_Latn", "tgt_language": "hin_Deva", "model": "krutrim-translate-v1.0" } ``` -------------------------------- ### Generate Image using Stable Diffusion Model Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md This example demonstrates how to call the `diffusion` method to generate an image. Ensure the `model_name` is set to 'diffusion1XL'. ```python client.images.generations.diffusion( model_name="diffusion1XL", prompt="A majestic lion in a savanna at sunset", image_height=1024, image_width=1024, num_output_images=1, guidance_scale=7.5, num_inference_steps=50, seed=12345 ) ``` -------------------------------- ### List Supported Fine-Tuning Models Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Retrieves and prints a list of all models available for fine-tuning. Ensure the client is initialized before use. ```python # List all the supported models try: supported_model_list = client.fine_tuning.models.list() print(supported_model_list) except Exception as e: print(f"An error occurred while listing supported models: {e}") ``` -------------------------------- ### Initialize Krutrim Cloud Client Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/bring_your_own_model/bring_your_own_model.ipynb Creates an instance of the KrutrimCloud client. This client is used to interact with the Krutrim Cloud API for model registry and deployment operations. ```python # Initialize KrutrimCloud client client = KrutrimCloud() ``` -------------------------------- ### Get Inference Task Information Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves detailed information about a specific inference task using its filename. ```APIDOC ## GET /api/v1/fine_tuning/tasks ### Description Retrieves information about a specific inference task. ### Method GET ### Endpoint /api/v1/fine_tuning/tasks ### Parameters #### Query Parameters - **filename** (str) - Required - Filename of the checkpoint. ### Response #### Success Response (200) - **ctime** (Optional[str]) - Description: Create time. - **dataset** (Optional[str]) - Description: Dataset used for training. - **epoch** (Optional[str]) - Description: Epoch number. - **mode** (Optional[str]) - Description: Mode of the task. - **model** (Optional[str]) - Description: Model name. - **mtime** (Optional[str]) - Description: Last modified time. - **name** (Optional[str]) - Description: Checkpoint name. - **status** (Optional[str]) - Description: Status of the checkpoint. - **steps** (Optional[str]) - Description: Number of steps. - **test_dataset** (Optional[str]) - Description: Test dataset used for training. ``` -------------------------------- ### Create Dataset from Local File Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Uploads a local dataset file for fine-tuning. Ensure the file path is correct and accessible. ```python # Create Datasets try: dataset_path = "/Users/harsha.s1/Downloads/ft-alpaca-tiny.json" with open(dataset_path, 'rb') as file: create_dataset = client.fine_tuning.datasets.create(file=file) except FileNotFoundError: print(f"Dataset file not found at path: {dataset_path}") except Exception as e: print(f"An error occurred while creating the dataset: {e}") ``` -------------------------------- ### Build Wheel File Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Build a distributable wheel file for the library using Rye or Python's build module. This creates .tar.gz and .whl files in the dist/ directory. ```bash rye build # or python -m build ``` -------------------------------- ### List Inference Tasks Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all inference tasks. This is useful for getting an overview of active or completed tasks. ```python from krutrim_cloud.types.inference import TaskListResponse ``` -------------------------------- ### Get Inference Task Information Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/inference/inference.ipynb Retrieves detailed information for a specific inference task using its filename. Includes validation and error handling. ```python try: filename = fine_tuning_checkpoints[0].name # Get Inference Task Information inference_task_info = client.inference.checkpoints.retrieve(filename=filename) print(inference_task_info) # Print or process the retrieved inference task information except Exception as e: # Handle any exceptions that occur during the API call print(f"An error occurred while fetching the inference task information: {e}") ``` -------------------------------- ### Asynchronous Image Generation with Krutrim Cloud SDK Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md This snippet demonstrates asynchronous image generation using AsyncKrutrimCloud. It requires importing asyncio and AsyncKrutrimCloud, and using `await` for API calls. ```python import asyncio from krutrim_cloud import AsyncKrutrimCloud client = AsyncKrutrimCloud() async def main() -> None: stable_diffusion_response = await client.images.generations.diffusion( model_name="diffusion1XL", image_height=1024, image_width=1024, prompt="Dog with hat on beach" ) print(stable_diffusion_response.created) asyncio.run(main()) ``` -------------------------------- ### List All Deployment Tasks Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/bring_your_own_model/bring_your_own_model.ipynb Lists all tasks associated with Krutrim Cloud deployments and prints their IDs, statuses, and model names. This provides an overview of all ongoing or completed tasks. Includes error handling. ```python try: # List all tasks and print their IDs and statuses task_list = client.deploy.tasks.list().task_list for task in task_list: print(f"Task ID: {task['id']} | Status: {task['status']} | Model Name: {task['name']}") except Exception as exc: # Print the exception if something goes wrong print(f"Exception: {exc}") ``` -------------------------------- ### Configure HTTP Client with Proxies and Transports Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md Customize the underlying httpx client by providing proxies and custom transports during KrutrimCloud client initialization. ```python from krutrim_cloud import KrutrimCloud, DefaultHttpxClient import httpx client = KrutrimCloud( # Or use the `KRUTRIM_CLOUD_BASE_URL` env var base_url="http://my.test.server.example.com:8083", http_client=DefaultHttpxClient( proxies="http://my.test.proxy.example.com", transport=httpx.HTTPTransport(local_address="0.0.0.0"), ), ) ``` -------------------------------- ### Get Inference Task Information Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves detailed information about a specific inference task. Use this to monitor the status and configuration of an ongoing or completed task. ```python from krutrim_cloud.types.inference import CheckpointRetrieveResponse ``` -------------------------------- ### Get Status of a Request Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves the status and details of a submitted request using its unique identifier. This includes processing status, file information, and download links for the output. ```APIDOC ## GET /status/{request_id} ### Description Retrieves the status and details of a submitted request using its unique identifier. This includes processing status, file information, and download links for the output. ### Method GET ### Endpoint /status/{request_id} ### Parameters #### Path Parameters - **request_id** (string) - Required - A unique identifier for the request. ### Response #### Success Response (200) - **status** (string) - Indicates the status of the API call (e.g., "success" or "failure"). - **data** (object) - Contains the output data. - **request_id** (string) - A unique identifier for the request. - **file_name** (string) - The name of the audio file that was processed. - **file_size_mb** (number) - The size of the file in megabytes. - **service_type** (string) - The type of service used for processing (e.g., "stttransservice"). - **status** (string) - The current status of the request (e.g., "SUCCESS", "QUEUED"). - **output_file** (string) - A link to download the output file. - **created_at** (string) - The timestamp when the request was created. - **updated_at** (string) - The timestamp when the request was last updated. #### Response Example { "status": "success", "data": { "request_id": "req_12345", "file_name": "audio.wav", "file_size_mb": 10.5, "service_type": "stttransservice", "status": "SUCCESS", "output_file": "http://example.com/output/req_12345.txt", "created_at": "2023-10-27T10:00:00Z", "updated_at": "2023-10-27T10:05:00Z" } } ``` -------------------------------- ### Run Linting Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Execute the linting process for the repository using the configured tools (ruff). ```bash rye run lint ``` -------------------------------- ### Transcribe Large Audio File Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Example of how to call the transcribe_lf API for long duration audio files. Ensure to replace placeholders with actual file paths and language codes. ```python file=@"", 'lang_code="eng"' ``` -------------------------------- ### Create a Fine-Tuning Task Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb This snippet demonstrates how to create a new fine-tuning task with various parameters such as engine, model, dataset, and training configurations. Error handling is included. ```python # Create finetuning task try: create_finetuning_task = client.fine_tuning.tasks.create( engine="torchtune", task_name="ft_task_1", namespace="gpu-scheduler", priority=0, model="Meta-Llama-3-8B-instruct", mode="lora", dataset="ft-alpaca-tiny.json", test_dataset="", ngpu=1, lora_rank=0, lora_alpha=0, batch=4, lr=1, epoch=1, seed=0, version="v1", total_checkpoint=1 ) print(create_finetuning_task) except Exception as e: print(f"An error occurred while creating the fine-tuning task: {e}") ``` -------------------------------- ### List All Supported Models Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all models supported for fine-tuning on Krutrim Cloud. ```APIDOC ## GET /api/v1/fine_tuning/models ### Description Retrieves a list of all models supported for fine-tuning. ### Method GET ### Endpoint /api/v1/fine_tuning/models ### Response #### Success Response (200) - **list** (str): A list of supported models. ``` -------------------------------- ### Upload File to S3 and Copy Dataset Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Uploads a local file to an S3 bucket and then copies it to the fine-tuning service. Requires S3 credentials and region to be set as environment variables. ```python try: local_directory = "/Users/harsha.s1/Downloads/ft-alpaca-tiny_sample3.json" bucket_name = "dvc-model-catalogue" s3_data = client.fine_tuning.upload_files_to_s3( local_dir_path=local_directory, bucket_name=bucket_name ) dataset_info = client.fine_tuning.datasets.copy(filename=s3_data["filename"], path=s3_data["s3-path"], s3_region=os.getenv("KRUTRIM_CLOUD_S3_REGION"), s3_access_key=os.getenv("KRUTRIM_CLOUD_S3_PUBLIC_KEY"), s3_endpoint=os.getenv("KRUTRIM_CLOUD_S3_BUCKET_ENDPOINT"), s3_secret=os.getenv("KRUTRIM_CLOUD_S3_SECRET_KEY") ) print(f"Dataset successfully copied: {dataset_info.name}") except Exception as exc: print(f"Exception while uploading data: {exc}") ``` -------------------------------- ### Deploy Model to Krutrim Cloud Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/bring_your_own_model/bring_your_own_model.ipynb Deploys a specified model version to Krutrim Cloud using the initialized client. It retrieves S3 configuration from environment variables and prints the deployment task details, including the model name and task ID. Includes error handling for the deployment process. ```python try: # Deploy the model using the KrutrimCloud client deploy_response = client.deploy.tasks.create( bucket_name=bucket_name, version=version, model=model_name, s3_endpoint=os.environ.get("KRUTRIM_CLOUD_S3_BUCKET_ENDPOINT"), # type: ignore s3_access_key=os.environ.get("KRUTRIM_CLOUD_S3_PUBLIC_KEY"), # type: ignore s3_secret=os.environ.get("KRUTRIM_CLOUD_S3_SECRET_KEY"), # type: ignore s3_region=os.environ.get("KRUTRIM_CLOUD_S3_REGION") # S3 region # type: ignore ) # Extract model name and task ID from the response deploy_model_name = deploy_response.name deploy_task_id = deploy_response.id # Print deployed model details print(f"Deployed Model Name: {deploy_model_name}") print(f"Deploy Task ID: {deploy_task_id}") except Exception as exc: # Print the exception if something goes wrong print(f"Exception: {exc}") ``` -------------------------------- ### List All Supported Engines Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all engines supported for fine-tuning on Krutrim Cloud. ```APIDOC ## GET /api/v1/fine_tuning/engines ### Description Retrieves a list of all engines supported for fine-tuning. ### Method GET ### Endpoint /api/v1/fine_tuning/engines ### Response #### Success Response (200) - **list** (str): A list of supported engines. ``` -------------------------------- ### List All Deployment Tasks Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all deployment tasks. You can use limit and offset parameters to paginate through the results. ```python from krutrim_cloud.types.deploy import TaskListResponse client.deploy.tasks.list(limit=params["limit"], offset=params["offset"]) ``` -------------------------------- ### Language Detection API Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md This script demonstrates the implementation of the Language Detection API. It requires the 'krutrim_cloud' library. ```python from krutrim_cloud.types.language_detection_response import LanguageDetectionResponse ``` ```text "Hey there, welcome to Language Labs" ``` -------------------------------- ### Import Libraries and Load Environment Variables Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/bring_your_own_model/bring_your_own_model.ipynb Imports necessary libraries including KrutrimCloud and dotenv, and loads environment variables from a .env file. Ensure your .env file contains API keys and S3 credentials. ```python # Import necessary libraries from krutrim_cloud import KrutrimCloud from dotenv import load_dotenv import os # Load environment variables from .env file load_dotenv() ``` -------------------------------- ### List All Datasets Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Use this to list all available datasets. It returns a DatasetListResponse object. ```python from krutrim_cloud.types.fine_tuning import DatasetListResponse ``` -------------------------------- ### Text-to-Speech Translation Implementation Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md This Python script demonstrates the implementation of the text_to_speech_translation API. It requires the krutrim_cloud library and specific types for request parameters and responses. ```python from krutrim_cloud.types.tts_trans_run_response import TTSTransRunResponse ``` ```python "input_text": "Who are you and how are you doing?", "src_lang_code": "eng", "tgt_lang_code": "hin", "input_speaker": "male" ``` -------------------------------- ### List All Fine-Tuning Tasks Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb This snippet shows how to retrieve and display a list of all fine-tuning tasks. It iterates through the tasks and prints their details, with a message for when no tasks are found. Error handling is included. ```python # List fine_tuning Tasks try: finetuning_tasks_list = client.fine_tuning.tasks.list() if finetuning_tasks_list.task_list: for index, task in enumerate(finetuning_tasks_list.task_list): print(f"\nFine-tuning Task: {index}") for key, value in task.items(): print(f"{key}={value}") else: print("No fine-tuning tasks found.") except Exception as e: print(f"An error occurred while listing fine-tuning tasks: {e}") ``` -------------------------------- ### Configure Model and S3 Details Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/bring_your_own_model/bring_your_own_model.ipynb Defines the bucket name, model name, version, and local directory path for model deployment. Replace placeholders with your specific details. ```python # Define your model bucket and version details bucket_name = "" # "my-bucket-name" model_name = "" # "model_name" version = "" # "v1" <- without '.' in version string local_directory = "" # "./model" ``` -------------------------------- ### Create Datasets using S3 Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Creates datasets for fine-tuning by copying from an S3 location. ```APIDOC ## POST /api/v1/fine_tuning/datasets/copy ### Description Creates datasets for fine-tuning by copying from an S3 location. ### Method POST ### Endpoint /api/v1/fine_tuning/datasets/copy ### Response #### Success Response (200) - **DatasetCopyResponse** (object): Response object containing details of the dataset copy operation. ``` -------------------------------- ### Synchronous Image Generation with Krutrim Cloud SDK Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md Use this snippet for making synchronous image generation requests. It requires importing KrutrimCloud and setting the API key, preferably via environment variables. ```python from krutrim_cloud import KrutrimCloud client = KrutrimCloud( # This is the default and can be omitted api_key=os.environ.get("KRUTRIM_CLOUD_API_KEY")) stable_diffusion_response = client.images.generations.diffusion( model_name="diffusion1XL", image_height=1024, image_width=1024, prompt="Dog with hat on beach" ) print(stable_diffusion_response.created) ``` -------------------------------- ### List Deployment Tasks Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Lists all available deployment tasks, with options to limit and offset the results. ```APIDOC ## GET /api/v1/deploy/tasks ### Description List all the deployment tasks. ### Method GET ### Endpoint /api/v1/deploy/tasks ### Parameters #### Path Parameters None #### Query Parameters - **limit** (int): Required - Limit the max number of items to be returned. - **offset** (int): Required - Offset index. #### Request Body None ### Request Example ```bash curl -X GET "https://api.krutrim.com/api/v1/deploy/tasks?limit=10&offset=0" ``` ### Response #### Success Response (200) - **count** (Optional[int]): Total number of tasks available. - **offset** (Optional[int]): List start offset. - **task_list** (Optional[List[object]]): List of deployment tasks. #### Response Example ```json { "count": 5, "offset": 0, "task_list": [ { "id": "deployment-task-12345", "name": "your-model-name-deployment", "status": "Running" }, { "id": "deployment-task-67890", "name": "another-model-deployment", "status": "Completed" } ] } ``` ``` -------------------------------- ### client.languagelabs.summarization.run Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md This method allows you to generate a summary for a given input text. You need to provide the text, its input language, and the desired summary size. ```APIDOC ## POST /v1/languagelabs/summarization ### Description Generates a summary for the provided input text. ### Method POST ### Endpoint /v1/languagelabs/summarization ### Parameters #### Request Body - **text** (str) - Required - The input text to summarize. - **input_language** (str) - Required - The language code of the input text (e.g., "eng" for English, "hin" for Hindi). - **summary_size** (int) - Required - The desired size of the summary. ### Request Example ```json { "text": "Krutrim, a part of the Ola group, is working on creating the AI computing stack of the future. We endeavor to deliver a state-of-the-art AI computing stack that encompasses the AI computing infrastructure, AI Cloud, foundational models, and AI-powered end applications for the Indian market. Our envisioned AI computing stack can empower consumers, startups, enterprises and scientists across India and the world to build their end AI applications or AI models. While we are building foundational models across text, voice, and vision relevant to our focus markets, we are also developing AI training and inference platforms that enable AI research and development across industry domains. The platforms being built by Krutrim have the potential to impact millions of lives in India, across income and education strata, and across languages. The team at Krutrim represents a convergence of talent across AI research, Applied AI, Cloud Engineering, and semiconductor design. Our teams operate from three locations: Bangalore, Singapore & San Francisco.", "input_language": "eng", "summary_size": 10 } ``` ### Response #### Success Response (200) - **status** (str) - **data** (Dict[str, str]) #### Response Example ```json { "status": "success", "data": { "summary": "Krutrim, part of Ola group, is building India's future AI computing stack with infrastructure, cloud, foundational models, and applications. It aims to empower users globally and impact millions in India across various strata and languages. The team comprises AI research, Applied AI, Cloud Engineering, and semiconductor design experts, operating from Bangalore, Singapore, and San Francisco." } } ``` ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Execute the project's tests using pytest. Ensure the mock server is set up if required by the tests. ```bash rye run pytest ``` -------------------------------- ### Import CogVideoResponse Type Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Import the necessary response type for video generation. ```python from krutrim_cloud.types.videos import CogVideoResponse ``` -------------------------------- ### Create Datasets using File Object Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Creates datasets for fine-tuning using a file object. ```APIDOC ## POST /api/v1/fine_tuning/datasets ### Description Creates datasets for fine-tuning using a file object. ### Method POST ### Endpoint /api/v1/fine_tuning/datasets ### Parameters #### Request Body - **file** (str): Input Dataset File Path. ### Response #### Success Response (200) - None ``` -------------------------------- ### List Fine-Tuning Engines Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Fetches and displays the names of all available fine-tuning engines. This helps in selecting the appropriate framework for fine-tuning. ```python # List fine_tuning engine(framework) name try: fine_tuning_engines = client.fine_tuning.engines.list() print(fine_tuning_engines) except Exception as e: print(f"An error occurred while listing fine-tuning engines: {e}") ``` -------------------------------- ### List Supported Fine-Tuning Modes Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all supported fine-tuning modes on Krutrim Cloud. ```APIDOC ## GET /api/v1/fine_tuning/modes ### Description Retrieves a list of all supported fine-tuning modes. ### Method GET ### Endpoint /api/v1/fine_tuning/modes ### Response #### Success Response (200) - **list** (str): A list of supported modes. ``` -------------------------------- ### List Fine-Tuning Engine by Model and Mode Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Retrieves the fine-tuning engine (framework) that can be used with a given model in a specific mode. Requires 'supported_model_list' and 'supported_modes' to be populated. ```python # List fine_tuning engine(framework) by the given model and mode try: model = supported_model_list[0] mode = supported_modes[0] finetune_engine_given_model = client.fine_tuning.engines.model.mode.retrieve(model=model, mode=mode) print(finetune_engine_given_model) except Exception as e: print(f"An error occurred while retrieving fine-tuning engine for the given model and mode: {e}") ``` -------------------------------- ### List Supported Fine-Tuning Modes Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Lists all fine-tuning modes supported by the API. This is useful for understanding available training configurations. ```python # List all supported fine_tuning modes try: supported_modes = client.fine_tuning.modes.list() print(supported_modes) except Exception as e: print(f"An error occurred while listing supported fine-tuning modes: {e}") ``` -------------------------------- ### Entity Extraction API Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md This script demonstrates the implementation of the Entity Extraction API. It requires the 'krutrim_cloud' library and specifies text, extraction parameters, and source language. ```python from krutrim_cloud.types.language_detection_response import LanguageDetectionResponse ``` ```json "text": "मेरे मित्र राजेश कुमार, जिनका जन्म 5 मई 1985 को दिल्ली में हुआ था, अब बेंगलुरु में रहते हैं। उन्होंने 2010 में आईआईटी दिल्ली से कंप्यूटर विज्ञान में स्नातक की डिग्री प्राप्त की थी। राजेश की पत्नी का नाम अंजलि है और उनके दो बच्चे हैं। राजेश एक सॉफ्टवेयर इंजीनियर के रूप में इंफोसिस में काम करते हैं। उनका फोन नंबर 9876543210 है और उनका ईमेल पता rajesh.kumar@example.com है। राजेश का पता 123, एमजी रोड, बेंगलुरु - 560001 है।", "param_list" : ["ner", "pii"], "lang_from" :"hin" ``` -------------------------------- ### Import Libraries and Load Environment Variables Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/inference/inference.ipynb Imports necessary libraries and loads environment variables from a .env file. Ensure you have a .env file with your API key. ```python # Import necessary libraries from krutrim_cloud import KrutrimCloud from dotenv import load_dotenv import os # Load environment variables from .env file load_dotenv() ``` -------------------------------- ### List Fine-Tuning Checkpoints Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/inference/inference.ipynb Fetches and displays all available fine-tuning checkpoints for monitoring models. Includes error handling for API calls. ```python try: # List all fine-tuning checkpoints fine_tuning_checkpoints = client.inference.checkpoints.list() print(fine_tuning_checkpoints) # Print or process the checkpoints list except Exception as e: # Handle any exceptions that occur during the API call print(f"An error occurred while fetching the fine-tuning checkpoints: {e}") ``` -------------------------------- ### List Models by Engine and Mode Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Retrieves models that are compatible with a specified engine and fine-tuning mode. Use this to find suitable models for your training. ```python # List all models supported by the given engine and mode try: engine = fine_tuning_engines[0] mode = supported_modes[0] supported_models_given_engine_mode = client.fine_tuning.models.mode.retrieve(engine=engine, mode=mode) print(supported_models_given_engine_mode) except Exception as e: print(f"An error occurred while retrieving models for the given engine and mode: {e}") ``` -------------------------------- ### List All Fine-Tuning Tasks Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Use this to list all fine-tuning tasks. It returns a TaskListResponse object containing task count, offset, and a list of tasks. ```python from krutrim_cloud.types.fine_tuning import TaskListResponse ``` -------------------------------- ### Configure Granular Timeout with httpx.Timeout Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md Use httpx.Timeout for more detailed control over connection, read, and write timeouts. ```python import httpx client = KrutrimCloud( timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0), ) ``` -------------------------------- ### List All Supported Models Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all models supported for fine-tuning. This method returns a ModelListResponse object. ```python from krutrim_cloud.types.fine_tuning import ModelListResponse ``` -------------------------------- ### List Modes Supported by a Given Engine Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Displays the fine-tuning modes that are available for a specific engine. This helps in determining compatible training modes for an engine. ```python # List all modes supported by the given engine try: engine = fine_tuning_engines[0] supported_modes_given_engine = client.fine_tuning.modes.retrieve(engine=engine) print(supported_modes_given_engine) except Exception as e: print(f"An error occurred while retrieving modes for the given engine: {e}") ``` -------------------------------- ### client.images.generations.params Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Generates a video from a text prompt using the CogVideoX-2b model. Users can customize the video by specifying parameters such as the prompt, number of frames, guidance scale, and inference steps. ```APIDOC ## POST /v1/videos/generations/text2video ### Description Generates a video from a text prompt using the CogVideoX-2b model. Users can customize the video by specifying parameters such as the prompt, number of frames, guidance scale, and inference steps. ### Method POST ### Endpoint /v1/videos/generations/text2video ### Parameters #### Request Body - **model_name** (str): Required - Specifies the model to be used for generating the video. Must be set to "cogvideo". - **prompt** (List[str]): Required - Defines the text prompt used to generate the video. It should be a single prompt passed in the form of a List. - **num_frames** (int): Optional - Defaults to 48. Minimum value of 10 and maximum value is 49. Determines the number of video frames to generate. - **guidance_scale** (float): Optional - Defaults to 6. Optimal values are <= 15. Controls how strongly the model adheres to the prompt. - **num_inference_steps** (int): Optional - Defaults to 50. Maximum value is 50. Defines the number of steps for the inference process. - **seed** (int): Optional - Leave it empty to generate a random value. Use the same value if you wish to get the same image. Modify the remaining parameters to get variants of the image. - **output_img_type** (str): Optional - Defaults to "pil". Supported: "pil" only. Specifies the format of the output image. - **timeout** (float): Optional - Overrides the client-level default timeout for this request, in seconds. ### Response #### Success Response (200) - **data** (List[Dict[str, str]]): Contains the generated video data. - **error** (Optional[str]): Optional - If an error occurred, this field will contain an error message. ``` -------------------------------- ### List Models Supported by a Specific Engine Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Retrieves and prints models that are compatible with a specified fine-tuning engine. It uses the first engine from the previously fetched list. ```python # List all models supported by the given engine try: engine = fine_tuning_engines[0] supported_models = client.fine_tuning.models.retrieve(engine) print(supported_models) except Exception as e: print(f"An error occurred while retrieving models for the given engine: {e}") ``` -------------------------------- ### Upload Audio File for Speech-to-Text Translation Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/speech/speech_to_text_translation_large_files.ipynb Uploads an audio file to the Krutrim Cloud Speech-to-Text API for translation and transcription. Requires KrutrimCloud client initialization and environment variables for API keys. Adjust the audio file path and language codes as needed. ```python from fileinput import filename from krutrim_cloud import KrutrimCloud from dotenv import load_dotenv from pathlib import Path from krutrim_cloud.lib.utils import poll_request_status,get_transcribed_text_from_s3,save_text_content # Load environment variables (e.g., API_KEY) load_dotenv() # Initialize KrutrimCloud client with the API key (if required by the API) client = KrutrimCloud() # Define request parameters for the speech_to_text_translation API audio_file_path = Path("../resources/speech_1.mp3") # Adjust this path to the actual audio file src_language = "eng" # Source language (e.g., English) tgt_language = "hin" # Target language (e.g., Hindi) # Path to save the translated transcription output translation_output_path = "./output" file_name = "translated_transcription.txt" try: with open(audio_file_path, 'rb') as audio_file: # Send the request to the API for speech-to-text translation response = client.languagelabs.stt_trans_lf.upload( file=audio_file_path, src_lang_code=src_language, tgt_lang_code=tgt_language ) request_id = response.data.request_id print(f"Extracted request_id: {request_id}") except Exception as e: # Catch any exceptions and print detailed error print("An error occurred while processing the request:",e) ``` -------------------------------- ### Configure HTTP Client Per Request Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md Override HTTP client settings for individual requests using the .with_options() method. ```python client.with_options(http_client=DefaultHttpxClient(...)) ``` -------------------------------- ### Create Deployment Task Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Creates a deployment task to deploy a model from S3 storage. This allows for deploying custom models into the Krutrim environment. ```APIDOC ## POST /api/v1/deploy/tasks ### Description Deploy your own model from S3 storage path. ### Method POST ### Endpoint /api/v1/deploy/tasks ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **model** (str): Required - Model name. - **path** (str): Required - S3's model directory path. - **s3_access_key** (str): Required - S3 access key. - **s3_endpoint** (str): Required - S3 endpoint. - **s3_region** (str): Required - S3 region. - **s3_secret** (str): Required - S3 secret. - **argument** (Optional[str]): Optional - additional argument to parse to inference engine. - **max_batch_size** (Optional[int]): Optional, defaults to 256 - max batch size. - **max_replicas** (Optional[int]): Optional, defaults to 1 - Max number of replicas. - **min_replicas** (Optional[int]): Optional, defaults to 1 - Min number of replicas. ### Request Example ```json { "model": "your-model-name", "path": "s3://your-bucket/path/to/model", "s3_access_key": "YOUR_ACCESS_KEY", "s3_endpoint": "your-s3-endpoint.com", "s3_region": "us-east-1", "s3_secret": "YOUR_SECRET_KEY", "max_batch_size": 512, "min_replicas": 2 } ``` ### Response #### Success Response (200) - **id** (str): Deployment Task ID - **name** (str): Model Deployment Name #### Response Example ```json { "id": "deployment-task-12345", "name": "your-model-name-deployment" } ``` ``` -------------------------------- ### Create Datasets using S3 Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Creates new datasets for fine-tuning by copying from an S3 location. This method returns a DatasetCopyResponse object upon successful creation. ```python from krutrim_cloud.types.fine_tuning import DatasetCopyResponse ``` -------------------------------- ### List Supported Modes for Engine and Model Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Retrieves all fine-tuning modes supported by a specific engine and model. Ensure 'fine_tuning_engines' and 'supported_model_list' are populated. ```python # List all modes supported by the given engine and model try: engine = fine_tuning_engines[0] model = supported_model_list[0] supported_modes_given_engine_model = client.fine_tuning.modes.model.retrieve(engine=engine, model=model) print(supported_modes_given_engine_model) except Exception as e: print(f"An error occurred while retrieving modes for the given engine and model: {e}") ``` -------------------------------- ### List All Supported Engines Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all engines supported for fine-tuning. This method returns an EngineListResponse object. ```python from krutrim_cloud.types.fine_tuning import EngineListResponse ``` -------------------------------- ### Create a Fine-Tuning Task Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Use this to create a new fine-tuning task. It requires various parameters such as engine, task name, dataset, and model configuration. It returns a TaskCreateResponse object. ```python from krutrim_cloud.types.fine_tuning import TaskCreateResponse ``` -------------------------------- ### List Fine-Tuning Engine by Model Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/examples/finetuning/finetuning.ipynb Finds the fine-tuning engine (framework) used for a specific model. Requires 'supported_model_list' to be populated. ```python # List fine_tuning engine(framework) by the given model try: model = supported_model_list[0] finetune_engine_given_model = client.fine_tuning.engines.model.retrieve(model=model) print(finetune_engine_given_model) except Exception as e: print(f"An error occurred while retrieving fine-tuning engine for the given model: {e}") ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/README.md Set the KRUTRIM_CLOUD_LOG environment variable to 'debug' to enable detailed logging. ```shell $ export KRUTRIM_CLOUD_LOG=debug ``` -------------------------------- ### Sync Dependencies with Rye Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/CONTRIBUTING.md Use this command to synchronize all dependencies and features when using Rye for environment management. ```sh $ rye sync --all-features ``` -------------------------------- ### Create a Fine-Tuning Task Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Creates a new fine-tuning task with specified parameters. ```APIDOC ## GET /api/v1/fine_tuning/tasks ### Description Creates a new fine-tuning task with specified parameters. ### Method GET ### Endpoint /api/v1/fine_tuning/tasks ### Parameters #### Request Body - **engine** (str) - Required - Engine type - **task_name** (str) - Required - Task Name - **namespace** (str) - Required - Namespace - **priority** (int) - Required - Priority - **model** (str) - Required - Model Name - **mode** (str) - Required - Mode - **dataset** (str) - Required - Dataset Name - **test_dataset** (str) - Optional - Test Dataset Name - **ngpu** (int) - Optional - Number of GPUs - **lora_rank** (int) - Optional - Lora Rank - **lora_alpha** (int) - Optional - Lora Alpha - **batch** (int) - Optional - Batch Size - **lr** (int) - Optional - Learning Rate - **epoch** (int) - Optional - Epoch Number - **seed** (int) - Optional - Random Seed - **version** (str) - Optional - Version String - **total_checkpoint** (int) - Optional - Total Checkpoint ### Response #### Success Response (200) - **task_id** (Optional[str]): Task ID. ``` -------------------------------- ### List All Fine-Tuning Tasks Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Retrieves a list of all fine-tuning tasks, including their status and details. ```APIDOC ## GET /api/v1/fine_tuning/tasks ### Description Retrieves a list of all fine-tuning tasks, including their status and details. ### Method GET ### Endpoint /api/v1/fine_tuning/tasks ### Response #### Success Response (200) - **count** (Optional[int]): Total number of tasks. - **offset** (Optional[int]): List start offset. - **task_list** (Optional[List[object]]): List of tasks. - **name** (Optional[str]): Name. - **model** (Optional[str]): Model. - **id** (Optional[str]): ID. - **status** (Optional[str]): Status. - **mtime** (Optional[str]): Modification time. - **total_checkpoint** (Optional[int]): Number of total checkpoints. - **checkpoints** (Optional[list]): Checkpoints. ``` -------------------------------- ### Import Chat Completion Types Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Import the necessary type for chat completion responses. ```python from krutrim_cloud.types.chat import CompletionCreateResponse ``` -------------------------------- ### Deploy Model from S3 Storage Source: https://github.com/ola-krutrim/krutrim-cloud-python/blob/main/api.md Initiates a deployment task for a model stored in S3. Requires S3 credentials and endpoint details. You can configure batch size and replica counts. ```python from krutrim_cloud.types.deploy import TaskCreateResponse client.deploy.tasks.create( model=params["model"], path=params["path"], s3_access_key=params["s3_access_key"], s3_endpoint=params["s3_endpoint"], s3_region=params["s3_region"], s3_secret=params["s3_secret"], argument=params.get("argument"), max_batch_size=params.get("max_batch_size", 256), min_replicas=params.get("min_replicas", 1), max_replicas=params.get("max_replicas", 1) ) ```