Skip to content

Commit c86e883

Browse files
balogh.adam@icloud.combalogh.adam@icloud.com
authored andcommitted
refactor
1 parent 4e6d808 commit c86e883

28 files changed

Lines changed: 235 additions & 582 deletions

examples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ All examples use a similar pattern to initialize the OpenGradient client:
163163
import os
164164
import opengradient as og
165165

166-
og_client = og.new_client(
166+
og_client = og.Client(
167+
private_key=os.environ.get("OG_PRIVATE_KEY"),
167168
email=os.environ.get("OG_MODEL_HUB_EMAIL"),
168169
password=os.environ.get("OG_MODEL_HUB_PASSWORD"),
169-
private_key=os.environ.get("OG_PRIVATE_KEY")
170170
)
171171
```
172172

@@ -175,7 +175,7 @@ og_client = og.new_client(
175175
Basic inference pattern:
176176

177177
```python
178-
result = og_client.infer(
178+
result = og_client.inference.infer(
179179
model_cid="your-model-cid",
180180
model_input={"input_key": "input_value"},
181181
inference_mode=og.InferenceMode.VANILLA
@@ -189,7 +189,7 @@ print(f"Tx hash: {result.transaction_hash}")
189189
LLM chat pattern:
190190

191191
```python
192-
completion = og_client.llm_chat(
192+
completion = og_client.llm.chat(
193193
model=og.TEE_LLM.CLAUDE_3_5_HAIKU,
194194
messages=[{"role": "user", "content": "Your message"}],
195195
)

examples/alpha/create_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import opengradient as og
44

5-
og_client = og.new_client(email=None, password=None, private_key=os.environ.get("OG_PRIVATE_KEY"))
5+
og_client = og.Client(private_key=os.environ.get("OG_PRIVATE_KEY"))
66

77
# Define model input
88
input_query = og.HistoricalInputQuery(

examples/alpha/run_embeddings_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import opengradient as og
44

5-
og_client = og.new_client(email=None, password=None, private_key=os.environ.get("OG_PRIVATE_KEY"))
5+
og_client = og.Client(private_key=os.environ.get("OG_PRIVATE_KEY"))
66

77
queries = [
88
"how much protein should a female eat",
@@ -14,7 +14,7 @@
1414
"Since you're reading this, you are probably someone from a judo background or someone who is just wondering how judo techniques can be applied under wrestling rules. So without further ado, let's get to the question. Are Judo throws allowed in wrestling? Yes, judo throws are allowed in freestyle and folkstyle wrestling. You only need to be careful to follow the slam rules when executing judo throws. In wrestling, a slam is lifting and returning an opponent to the mat with unnecessary force.",
1515
]
1616

17-
model_embeddings = og_client.infer(
17+
model_embeddings = og_client.inference.infer(
1818
model_cid="intfloat/multilingual-e5-large-instruct",
1919
model_input={"queries": queries, "instruction": instruction, "passages": passages},
2020
inference_mode=og.InferenceMode.VANILLA,

examples/alpha/run_inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import opengradient as og
44

5-
og_client = og.new_client(email=None, password=None, private_key=os.environ.get("OG_PRIVATE_KEY"))
5+
og_client = og.Client(private_key=os.environ.get("OG_PRIVATE_KEY"))
66

7-
inference_result = og_client.infer(
7+
inference_result = og_client.inference.infer(
88
model_cid="hJD2Ja3akZFt1A2LT-D_1oxOCz_OtuGYw4V9eE1m39M",
99
model_input={
1010
"open_high_low_close": [

examples/alpha/use_workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import opengradient as og
44

5-
og_client = og.new_client(email=None, password=None, private_key=os.environ.get("OG_PRIVATE_KEY"))
5+
og_client = og.Client(private_key=os.environ.get("OG_PRIVATE_KEY"))
66

77
model_output = og_client.alpha.read_workflow_result(
88
# This is the workflow contract address that you previously deployed

examples/create_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import opengradient as og
44

5-
og_client = og.new_client(
5+
og_client = og.Client(
6+
private_key=os.environ.get("OG_PRIVATE_KEY"),
67
email=os.environ.get("OG_MODEL_HUB_EMAIL"),
78
password=os.environ.get("OG_MODEL_HUB_PASSWORD"),
8-
private_key=os.environ.get("OG_PRIVATE_KEY"),
99
)
1010

11-
og_client.create_model(
11+
og_client.model_hub.create_model(
1212
model_name="example-model", model_desc="An example machine learning model for demonstration purposes", version="1.0.0"
1313
)

examples/run_x402_gemini_tools.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import opengradient as og
1212

1313
# Initialize client with Google API key
14-
client = og.new_client(
15-
email=None,
16-
password=None,
14+
client = og.Client(
1715
private_key=os.environ.get("OG_PRIVATE_KEY"),
1816
)
1917

@@ -58,7 +56,7 @@
5856
print(f"Tools: {tools}")
5957
print("-" * 50)
6058

61-
result = client.llm_chat(
59+
result = client.llm.chat(
6260
model=og.TEE_LLM.GEMINI_2_5_FLASH_LITE,
6361
messages=messages,
6462
tools=tools,

examples/run_x402_llm.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
import opengradient as og
1515

16-
client = og.new_client(
17-
email=None,
18-
password=None,
16+
client = og.Client(
1917
private_key=os.environ.get("OG_PRIVATE_KEY"),
2018
)
2119

@@ -25,7 +23,7 @@
2523
{"role": "user", "content": "What makes it good for beginners?"},
2624
]
2725

28-
result = client.llm_chat(
26+
result = client.llm.chat(
2927
model=og.TEE_LLM.GPT_4_1_2025_04_14,
3028
messages=messages,
3129
x402_settlement_mode=og.x402SettlementMode.SETTLE_METADATA,

examples/run_x402_llm_stream.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
import opengradient as og
44

5-
client = og.new_client(
6-
email=None,
7-
password=None,
5+
client = og.Client(
86
private_key=os.environ.get("OG_PRIVATE_KEY"),
97
)
108

119
messages = [
1210
{"role": "user", "content": "Describe to me the 7 network layers?"},
1311
]
1412

15-
stream = client.llm_chat(
13+
stream = client.llm.chat(
1614
model=og.TEE_LLM.GPT_4_1_2025_04_14,
1715
messages=messages,
1816
x402_settlement_mode=og.x402SettlementMode.SETTLE_METADATA,

examples/upload_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import opengradient as og
44

5-
og_client = og.new_client(
5+
og_client = og.Client(
6+
private_key=os.environ.get("OG_PRIVATE_KEY"),
67
email=os.environ.get("OG_MODEL_HUB_EMAIL"),
78
password=os.environ.get("OG_MODEL_HUB_PASSWORD"),
8-
private_key=os.environ.get("OG_PRIVATE_KEY"),
99
)
1010

11-
model_repo = og_client.create_model(model_name="Demo_Custom_Model_Adam", model_desc="My custom model for demoing Model Hub")
12-
upload_result = og_client.upload(model_name=model_repo.name, version=model_repo.initialVersion, model_path="./path/to/model.onnx")
11+
model_repo = og_client.model_hub.create_model(model_name="Demo_Custom_Model_Adam", model_desc="My custom model for demoing Model Hub")
12+
upload_result = og_client.model_hub.upload(model_name=model_repo.name, version=model_repo.initialVersion, model_path="./path/to/model.onnx")
1313

1414
print(f"Uploaded model, use following CID to access: {upload_result.modelCid}")

0 commit comments

Comments
 (0)