Metadata-Version: 2.2
Name: opengradient
Version: 0.4.4
Summary: Python SDK for OpenGradient decentralized model management & inference services
Author-email: OpenGradient <oliver@opengradient.ai>
License: MIT License
        
        Copyright (c) 2024 OpenGradient
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://opengradient.ai
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: eth-account>=0.13.4
Requires-Dist: web3>=7.3.0
Requires-Dist: click>=8.1.7
Requires-Dist: firebase-rest-api>=1.11.0
Requires-Dist: grpcio>=1.66.2
Requires-Dist: numpy>=1.26.4
Requires-Dist: requests>=2.32.3
Requires-Dist: langchain>=0.3.7
Requires-Dist: openai>=1.58.1
Requires-Dist: pydantic>=2.9.2

# OpenGradient Python SDK
Python SDK for the OpenGradient platform provides decentralized model management & inference services. Python SDK allows programmatic access to our model repository and decentralized AI infrastructure. 

## Installation

To install Python SDK and CLI, run the following command:
```python
pip install opengradient
```

## Quick Start

To get started, run:

```python
import opengradient as og
og.init(private_key="<private_key>", email="<email>", password="<password>")
```

The following commands show how to use Python SDK.

### Create a Model
```python
og.create_model(model_name="<model_name>", model_desc="<model_description>")
```

### Create a Model (with file upload)
```python
og.create_model(model_name="<model_name>", model_desc="<model_description>", model_path="<model_path>")
```

### Create a Version of a Model
```python
og.create_version(model_name="<model_name>", notes="<model_notes>")
```

### Upload Files to a Model
```python
og.upload(model_path="<model_path>", model_name="<model_name>", version="<version>")
```

### List Files of a Model Version
```python
og.list_files(model_name="<model_name>", version="<version>")
```

### Run Inference
```python
inference_mode = og.InferenceMode.VANILLA
og.infer(model_cid, model_inputs, inference_mode)
```
 - inference mode can be `VANILLA`, `ZKML`, or `TEE`

### LLM Inference
#### LLM Completion
```python
tx_hash, response = og.llm_completion(
    model_cid='meta-llama/Meta-Llama-3-8B-Instruct',
    prompt="Translate the following English text to French: 'Hello, how are you?'",
    max_tokens=50,
    temperature=0.0
)
``` 

#### LLM Chat
```python
# create messages history
messages = [
    {
        "role": "system",
        "content": "You are a helpful AI assistant.",
        "name": "HAL"
    },
    {
        "role": "user",
        "content": "Hello! How are you doing? Can you repeat my name?",
    }]

# run LLM inference
tx_hash, finish_reason, message = og.llm_chat(
  model_cid=og.LLM.MISTRAL_7B_INSTRUCT_V3,
  messages=messages
)
```



## Using the CLI

```bash
export OPENGRADIENT_EMAIL="<email>"
export OPENGRADIENT_PASSWORD="<password>"
```

#### Creating a Model Repo
```bash
opengradient create_model_repo "<model_name>" "<description>" 
```
- creating a model automatically initializes version `v0.01`

#### Creating a Version
```bash
opengradient create_model_repo "<model_name>" "<description>" 
```

#### Upload a File
```bash
opengradient upload "<model_path>" "<model_name>" "<version>" 
```

#### List Files of a Model Version
```bash
opengradient list_files "<model_name>" "<version>"
```

####  CLI infer using string 
```bash
opengradient infer QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ VANILLA '{"num_input1":[1.0, 2.0, 3.0], "num_input2":10, "str_input1":["hello", "ONNX"], "str_input2":" world"}'
```

#### CLI infer using file path input
```bash
opengradient infer QmbUqS93oc4JTLMHwpVxsE39mhNxy6hpf6Py3r9oANr8aZ VANILLA --input_file input.json
```

#### Run LLM Inference
We also have explicit support for using LLMs through the completion and chat commands in the CLI.

For example, you can run a competion inference with Llama-3 using the following command:

``` bash
opengradient completion --model "meta-llama/Meta-Llama-3-8B-Instruct" --prompt "hello who are you?" --max-tokens 50
```

Or you can use files instead of text input in order to simplify your command:

```bash
opengradient chat --model "mistralai/Mistral-7B-Instruct-v0.3" --messages-file messages.json --tools-file tools.json --max-tokens 200
```

For more information read the OpenGradient [documentation](https://docs.opengradient.ai/).
