Skip to main content

GMI Cloud Python SDK

Project description

GMICloud

Overview

This project is an open-source SDK for interacting with the GMICLOUD platform. It provides functionalities to manage artifacts, tasks, and usage data efficiently.

Features

  • Create and manage artifacts
  • Create and manage tasks
  • Fetch usage data
  • Integration with OpenAI for chat completions

Installation

To install the SDK, use pip:

pip install gmicloud-sdk

Usage

Initialize the Client

from gmicloud import Client

client = Client(username="your_username", password="your_password")

Create an Artifact with a File

artifact_id = client.artifact_manager.create_artifact_with_file(
    artifact_name="Llama3.1 8B",
    artifact_file_path="./files/Llama-3.1-8B-Instruct.zip",
    description="This is a test artifact",
    tags=['example', 'test']
)

Create an Artifact from a Template

artifact_id = client.artifact_manager.create_artifact_from_template(
    artifact_template_id="template_id"
)

Create and Start a Task

task_id = client.task_manager.create_task(Task(
    config=TaskConfig(
        ray_task_config=RayTaskConfig(
            ray_version="2.40.0-py310-gpu",
            file_path="serve",
            artifact_id=artifact_id,
            deployment_name="app",
            replica_resource=ReplicaResource(
                cpu=2,
                ram_gb=128,
                gpu=2,
            ),
        ),
        task_scheduling=TaskScheduling(
            scheduling_oneoff=OneOffScheduling(
                trigger_timestamp=int(datetime.now().timestamp()) + 60,
                min_replicas=1,
                max_replicas=10,
            )
        ),
    ),
))

client.task_manager.start_task(task_id)

Call Chat Completion

from openai import OpenAI

task = client.task_manager.get_task(task_id)
open_ai = OpenAI(
    api_key="YOUR_API_KEY",
    base_url=task.info.endpoint
)

completion = open_ai.chat.completions.create(
    model="meta-llama/Llama-3.1-8B-Instruct",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Translate the sentences to Chinese"},
    ],
    max_tokens=200,
    temperature=0.7
)

print(completion.choices[0].message.content)

Configuration

One-off Task Configuration

examples/config/one-off_task.json:

{
  "config": {
    "ray_task_config": {
      "ray_version": "2.40.0",
      "file_path": "serve",
      "deployment_name": "string",
      "replica_resource": {
        "cpu": 2,
        "ram_gb": 12,
        "gpu": 1
      }
    },
    "task_scheduling": {
      "scheduling_oneoff": {
        "min_replicas": 1,
        "max_replicas": 1
      }
    }
  }
}

Daily Task Configuration

examples/config/daily_task.json:

{
  "config": {
    "ray_task_config": {
      "ray_version": "2.40.0-py310-gpu",
      "file_path": "serve",
      "deployment_name": "string",
      "replica_resource": {
        "cpu": 6,
        "ram_gb": 64,
        "gpu": 2
      }
    },
    "task_scheduling": {
      "scheduling_daily": {
        "triggers": [
          {
            "timezone": "UTC",
            "Hour": 0,
            "minute": 10,
            "second": 0,
            "min_replicas": 1,
            "max_replicas": 2
          },
          {
            "timezone": "UTC",
            "Hour": 0,
            "minute": 10,
            "second": 30,
            "min_replicas": 1,
            "max_replicas": 4
          }
        ]
      }
    }
  }
}

Running Tests

To run the unit tests, use the following command:

pytest

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

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

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

gmicloud-0.1.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

gmicloud-0.1.0-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file gmicloud-0.1.0.tar.gz.

File metadata

  • Download URL: gmicloud-0.1.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for gmicloud-0.1.0.tar.gz
Algorithm Hash digest
SHA256 97e981e051e28217c1edf39f7f1714ab3383f8e6a1bad86765551c8e6072c855
MD5 0083fcc63de9be365cdad5eedbd11f16
BLAKE2b-256 f6defa9d07739a8beb2753f94023556e5927545ba8b34bb7b149a69719802c42

See more details on using hashes here.

File details

Details for the file gmicloud-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gmicloud-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for gmicloud-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e3810de0ebdfc7a1850b55e982018ed0b10044de2a11bd69e763fcf1b05a837
MD5 33af199b49140f46d0f32d7ac0540b8d
BLAKE2b-256 b882b103498fc67dc25d97d0f8dd0a051b1a37a98ad97207a62de21fbceed034

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