API Reference: ogpu.client¶
Essential API reference for the ogpu.client
module - the foundation for task publishing and response management on the OpenGPU network.
Task and Source Management
This module is designed for interacting with the OpenGPU network. Use ogpu.client
to publish tasks, manage sources, retrieve responses, and configure blockchain connections.
Source Operations¶
ogpu.client.source.publish_source
¶
Publish a source to the Nexus contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_info
|
SourceInfo
|
SourceInfo object containing source configuration |
required |
private_key
|
str | None
|
Private key for signing the transaction. If None, will use CLIENT_PRIVATE_KEY environment variable. |
None
|
Returns:
Type | Description |
---|---|
str
|
Address of the created source contract |
Source code in ogpu/client/source.py
Purpose: Publish AI services as sources on the OpenGPU network.
Example:
from web3 import Web3
from ogpu.client import publish_source, SourceInfo, ImageEnvironments, DeliveryMethod
source_info = SourceInfo(
name="sentiment-service",
description="AI sentiment analysis service",
logoUrl="https://example.com/logo.png",
imageEnvs=ImageEnvironments(
cpu="https://raw.githubusercontent.com/user/repo/main/docker-compose.yml",
nvidia="https://raw.githubusercontent.com/user/repo/main/docker-compose-gpu.yml"
),
minPayment=Web3.to_wei(0.001, "ether"),
minAvailableLockup=Web3.to_wei(0.01, "ether"),
maxExpiryDuration=86400,
deliveryMethod=DeliveryMethod.MANUAL_CONFIRMATION
)
source_address = publish_source(source_info)
print(f"Source published at: {source_address}")
Task Operations¶
ogpu.client.task.publish_task
¶
Publish a task to the Controller contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_info
|
TaskInfo
|
TaskInfo object containing task configuration |
required |
private_key
|
str | None
|
Private key for signing the transaction. If None, will use CLIENT_PRIVATE_KEY environment variable. |
None
|
Returns:
Type | Description |
---|---|
str
|
Address of the created task contract |
Source code in ogpu/client/task.py
Purpose: Publish AI tasks to the OpenGPU network for distributed processing.
Example:
import time
from web3 import Web3
from ogpu.client import publish_task, TaskInfo, TaskInput
# Create task configuration
task_config = TaskInput(
function_name="analyze_sentiment",
data={"text": "I love this product!"}
)
task_info = TaskInfo(
source="0x1234567890123456789012345678901234567890",
config=task_config,
expiryTime=int(time.time()) + 3600, # 1 hour from now
payment=Web3.to_wei(0.01, "ether")
)
task_address = publish_task(task_info)
print(f"Task published at: {task_address}")
Response Operations¶
ogpu.client.responses.get_task_responses
¶
Get all responses for a specific task address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_address
|
str
|
The task contract address |
required |
lower
|
int
|
Lower bound for response pagination (default: 0) |
0
|
upper
|
Optional[int]
|
Upper bound for response pagination (default: None, gets all) |
None
|
Returns:
Type | Description |
---|---|
List[Response]
|
List of TaskResponse objects containing response data |
Raises:
Type | Description |
---|---|
Exception
|
If the contract call fails or task doesn't exist |
Source code in ogpu/client/responses.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
Purpose: Retrieve all responses for a published task.
Example:
responses = get_task_responses(task_address)
for response in responses:
print(f"Provider: {response.provider}")
print(f"Status: {response.status}")
print(f"Data: {response.data}")
ogpu.client.responses.get_confirmed_response
¶
Get confirmed response data for a specific task address by calling the API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_address
|
str
|
The task contract address |
required |
Returns:
Type | Description |
---|---|
ConfirmedResponse
|
ConfirmedResponse object containing the confirmed response data |
Raises:
Type | Description |
---|---|
Exception
|
If the API call fails or no confirmed response is found |
Source code in ogpu/client/responses.py
Purpose: Retrieve the confirmed response for a completed task.
Example:
ogpu.client.responses.confirm_response
¶
Confirm a response using the Controller contract.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response_address
|
str
|
The response contract address to confirm |
required |
private_key
|
str | None
|
Private key for signing the transaction. If None, will use CLIENT_PRIVATE_KEY environment variable. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Transaction hash of the confirmation |
Raises:
Type | Description |
---|---|
Exception
|
If the confirmation fails |
Source code in ogpu/client/responses.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
Purpose: Confirm a response to complete the task and release payment.
Example:
Network Configuration¶
ogpu.client.chain_config.ChainId
¶
Enum for supported blockchain networks.
Attributes:
Name | Type | Description |
---|---|---|
OGPU_MAINNET |
Main OpenGPU network (Chain ID: 1071) |
|
OGPU_TESTNET |
Test OpenGPU network (Chain ID: 200820172034) |
Purpose: Enum defining supported blockchain networks.
ogpu.client.chain_config.ChainConfig.set_chain
classmethod
¶
Set the current active chain
Purpose: Set the current active blockchain network.
Example:
from ogpu.client import ChainConfig, ChainId
# Set to testnet
ChainConfig.set_chain(ChainId.OGPU_TESTNET)
# Set to mainnet
ChainConfig.set_chain(ChainId.OGPU_MAINNET)
ogpu.client.chain_config.ChainConfig.get_current_chain
classmethod
¶
Purpose: Get the currently active blockchain network.
Example:
current_chain = ChainConfig.get_current_chain()
print(f"Current chain: {current_chain.name}")
print(f"Chain ID: {current_chain.value}")
ogpu.client.chain_config.ChainConfig.get_contract_address
classmethod
¶
Get contract address for the current chain
Source code in ogpu/client/chain_config.py
Purpose: Get contract address for a specific contract on the current chain.
Example:
# Get contract addresses for current chain
nexus_address = ChainConfig.get_contract_address("NEXUS")
controller_address = ChainConfig.get_contract_address("CONTROLLER")
terminal_address = ChainConfig.get_contract_address("TERMINAL")
print(f"NEXUS: {nexus_address}")
print(f"CONTROLLER: {controller_address}")
print(f"TERMINAL: {terminal_address}")
ogpu.client.chain_config.ChainConfig.get_all_supported_chains
classmethod
¶
Purpose: Get list of all supported blockchain networks.
Example:
supported_chains = ChainConfig.get_all_supported_chains()
for chain in supported_chains:
print(f"Chain: {chain.name} (ID: {chain.value})")
Data Types¶
ogpu.client.types.ImageEnvironments
dataclass
¶
Docker compose file paths for different environments.
Attributes:
Name | Type | Description |
---|---|---|
cpu |
str
|
URL to CPU-only docker-compose.yml file |
nvidia |
str
|
URL to NVIDIA GPU docker-compose.yml file |
amd |
str
|
URL to AMD GPU docker-compose.yml file |
Purpose: Docker compose file URLs for different hardware environments.
Example:
image_envs = ImageEnvironments(
cpu="https://raw.githubusercontent.com/user/repo/main/docker-compose.yml",
nvidia="https://raw.githubusercontent.com/user/repo/main/docker-compose-gpu.yml",
amd="https://raw.githubusercontent.com/user/repo/main/docker-compose-amd.yml"
)
ogpu.client.types.DeliveryMethod
¶
Enum for delivery method options.
Attributes:
Name | Type | Description |
---|---|---|
MANUAL_CONFIRMATION |
Client manually confirms the response |
|
FIRST_RESPONSE |
First provider to submit a response wins |
Purpose: Enum defining how task responses are delivered and confirmed.
ogpu.client.types.SourceInfo
dataclass
¶
User-friendly source information structure.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Human-readable name for the source |
description |
str
|
Description of the AI service |
logoUrl |
str
|
URL to the source logo image |
imageEnvs |
ImageEnvironments
|
Docker environment configurations |
minPayment |
int
|
Minimum payment required in wei |
minAvailableLockup |
int
|
Minimum lockup amount in wei |
maxExpiryDuration |
int
|
Maximum task duration in seconds |
deliveryMethod |
DeliveryMethod
|
How responses are delivered |
Purpose: Configuration data for publishing AI services as sources.
Example:
source_info = SourceInfo(
name="sentiment-service",
description="AI sentiment analysis service",
logoUrl="https://example.com/logo.png",
imageEnvs=ImageEnvironments(
cpu="https://raw.githubusercontent.com/user/repo/main/docker-compose.yml",
nvidia="https://raw.githubusercontent.com/user/repo/main/docker-compose-gpu.yml"
),
minPayment=Web3.to_wei(0.001, "ether"),
minAvailableLockup=Web3.to_wei(0.01, "ether"),
maxExpiryDuration=86400,
deliveryMethod=DeliveryMethod.MANUAL_CONFIRMATION
)
ogpu.client.types.TaskInput
dataclass
¶
Configuration structure for tasks.
Attributes:
Name | Type | Description |
---|---|---|
function_name |
str
|
Name of the function to call on the source |
data |
BaseModel | dict[str, Any]
|
Input data for the function (Pydantic model or dictionary) |
Purpose: Configuration for task input data and function specification.
Example:
# Using a dictionary
task_input = TaskInput(
function_name="inference",
data={"inputs": "Translate to French: Hello"}
)
# Using a Pydantic model
from pydantic import BaseModel
class InferenceData(BaseModel):
inputs: str
parameters: dict = {}
task_input = TaskInput(
function_name="inference",
data=InferenceData(inputs="Hello world")
)
ogpu.client.types.TaskInfo
dataclass
¶
User-friendly task information structure.
Attributes:
Name | Type | Description |
---|---|---|
source |
str
|
Address of the source to run the task on |
config |
TaskInput
|
Task input configuration and function call |
expiryTime |
int
|
Unix timestamp when task expires |
payment |
int
|
Payment amount for the task in wei |
Purpose: Configuration data for publishing tasks to the network.
Example:
task_info = TaskInfo(
source="0x1234...",
config=TaskInput(
function_name="inference",
data={"inputs": "What is AI?"}
),
expiryTime=1640995200,
payment=1000000000000000000 # 1 OGPU in wei
)
ogpu.client.types.Response
dataclass
¶
Response data structure for task responses.
Attributes:
Name | Type | Description |
---|---|---|
address |
str
|
Blockchain address of the response |
task |
str
|
Address of the task this responds to |
provider |
str
|
Address of the provider who submitted the response |
data |
str
|
Response data from the AI service |
payment |
int
|
Payment amount in wei |
status |
int
|
Response status code |
timestamp |
int
|
Unix timestamp when response was submitted |
confirmed |
bool
|
Whether the response has been confirmed |
Purpose: Response data structure from completed tasks.
Example:
# Response object from get_task_responses()
response = Response(
address="0xabcd...",
task="0x1234...",
provider="0x5678...",
data='{"result": "positive sentiment"}',
payment=1000000000000000000,
status=1,
timestamp=1640995200,
confirmed=False
)
ogpu.client.types.ConfirmedResponse
dataclass
¶
Simplified confirmed response data structure.
Attributes:
Name | Type | Description |
---|---|---|
address |
str
|
Blockchain address of the confirmed response |
data |
str
|
The confirmed response data |
Purpose: Simplified confirmed response data structure.
Example: