Skip to content

Commit e37f640

Browse files
committed
Linting Errors
1 parent 8bda201 commit e37f640

File tree

4 files changed

+88
-80
lines changed

4 files changed

+88
-80
lines changed

examples/agent_wait_until_ready.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@
2424
if agent_id:
2525
print(f"Agent created with ID: {agent_id}")
2626
print("Waiting for agent to be ready...")
27-
27+
2828
try:
2929
# Wait for the agent to be deployed and ready
3030
# This will poll the agent status every 5 seconds (default)
3131
# and wait up to 5 minutes (default timeout=300 seconds)
3232
ready_agent = client.agents.wait_until_ready(
3333
agent_id,
3434
poll_interval=5.0, # Check every 5 seconds
35-
timeout=300.0, # Wait up to 5 minutes
35+
timeout=300.0, # Wait up to 5 minutes
3636
)
37-
37+
3838
if ready_agent.agent and ready_agent.agent.deployment:
3939
print(f"Agent is ready! Status: {ready_agent.agent.deployment.status}")
4040
print(f"Agent URL: {ready_agent.agent.url}")
41-
41+
4242
# Now you can use the agent
4343
# ...
44-
44+
4545
except AgentDeploymentError as e:
4646
print(f"Agent deployment failed: {e}")
4747
print(f"Failed status: {e.status}")
48-
48+
4949
except AgentDeploymentTimeoutError as e:
5050
print(f"Agent deployment timed out: {e}")
5151
print(f"Agent ID: {e.agent_id}")
52-
52+
5353
except Exception as e:
5454
print(f"Unexpected error: {e}")
5555

@@ -60,37 +60,37 @@
6060

6161
async def main() -> None:
6262
async_client = AsyncGradient()
63-
63+
6464
# Create a new agent
6565
agent_response = await async_client.agents.create(
6666
name="My Async Agent",
6767
instruction="You are a helpful assistant",
6868
model_uuid="<your-model-uuid>",
6969
region="nyc1",
7070
)
71-
71+
7272
agent_id = agent_response.agent.uuid if agent_response.agent else None
73-
73+
7474
if agent_id:
7575
print(f"Agent created with ID: {agent_id}")
7676
print("Waiting for agent to be ready...")
77-
77+
7878
try:
7979
# Wait for the agent to be deployed and ready (async)
8080
ready_agent = await async_client.agents.wait_until_ready(
8181
agent_id,
8282
poll_interval=5.0,
8383
timeout=300.0,
8484
)
85-
85+
8686
if ready_agent.agent and ready_agent.agent.deployment:
8787
print(f"Agent is ready! Status: {ready_agent.agent.deployment.status}")
8888
print(f"Agent URL: {ready_agent.agent.url}")
89-
89+
9090
except AgentDeploymentError as e:
9191
print(f"Agent deployment failed: {e}")
9292
print(f"Failed status: {e.status}")
93-
93+
9494
except AgentDeploymentTimeoutError as e:
9595
print(f"Agent deployment timed out: {e}")
9696
print(f"Agent ID: {e.agent_id}")

examples/knowledge_base_indexing_wait.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,35 @@ def main():
1919
# Example 1: Basic usage - wait for indexing job to complete
2020
print("Example 1: Basic usage")
2121
print("-" * 50)
22-
22+
2323
# Create an indexing job (replace with your actual knowledge base UUID)
2424
knowledge_base_uuid = os.getenv("KNOWLEDGE_BASE_UUID", "your-kb-uuid-here")
25-
25+
2626
print(f"Creating indexing job for knowledge base: {knowledge_base_uuid}")
2727
indexing_job = client.knowledge_bases.indexing_jobs.create(
2828
knowledge_base_uuid=knowledge_base_uuid,
2929
)
30-
30+
3131
job_uuid = indexing_job.job.uuid if indexing_job.job else None
3232
if not job_uuid:
3333
print("Error: Could not create indexing job")
3434
return
35-
35+
3636
print(f"Indexing job created with UUID: {job_uuid}")
3737
print("Waiting for indexing job to complete...")
38-
38+
3939
try:
4040
# Wait for the job to complete (polls every 5 seconds by default)
41-
completed_job = client.knowledge_bases.indexing_jobs.wait_for_completion(
42-
job_uuid
43-
)
44-
41+
completed_job = client.knowledge_bases.indexing_jobs.wait_for_completion(job_uuid)
42+
4543
print("\n✅ Indexing job completed successfully!")
4644
if completed_job.job:
4745
print(f"Phase: {completed_job.job.phase}")
4846
print(f"Total items indexed: {completed_job.job.total_items_indexed}")
4947
print(f"Total items failed: {completed_job.job.total_items_failed}")
5048
print(f"Total datasources: {completed_job.job.total_datasources}")
5149
print(f"Completed datasources: {completed_job.job.completed_datasources}")
52-
50+
5351
except IndexingJobTimeoutError as e:
5452
print(f"\n⏱️ Timeout: {e}")
5553
except IndexingJobError as e:
@@ -62,42 +60,44 @@ def example_with_custom_polling():
6260
"""Example with custom polling interval and timeout"""
6361
print("\n\nExample 2: Custom polling interval and timeout")
6462
print("-" * 50)
65-
63+
6664
client = Gradient()
6765
knowledge_base_uuid = os.getenv("KNOWLEDGE_BASE_UUID", "your-kb-uuid-here")
68-
66+
6967
print(f"Creating indexing job for knowledge base: {knowledge_base_uuid}")
7068
indexing_job = client.knowledge_bases.indexing_jobs.create(
7169
knowledge_base_uuid=knowledge_base_uuid,
7270
)
73-
71+
7472
job_uuid = indexing_job.job.uuid if indexing_job.job else None
7573
if not job_uuid:
7674
print("Error: Could not create indexing job")
7775
return
78-
76+
7977
print(f"Indexing job created with UUID: {job_uuid}")
8078
print("Waiting for indexing job to complete (polling every 10 seconds, 5 minute timeout)...")
81-
79+
8280
try:
8381
# Wait with custom poll interval (10 seconds) and timeout (5 minutes = 300 seconds)
8482
completed_job = client.knowledge_bases.indexing_jobs.wait_for_completion(
8583
job_uuid,
8684
poll_interval=10, # Poll every 10 seconds
87-
timeout=300, # Timeout after 5 minutes
85+
timeout=300, # Timeout after 5 minutes
8886
)
89-
87+
9088
print("\n✅ Indexing job completed successfully!")
9189
if completed_job.job:
9290
print(f"Phase: {completed_job.job.phase}")
93-
91+
9492
except IndexingJobTimeoutError:
9593
print("\n⏱️ Job did not complete within 5 minutes")
9694
# You can still check the current status
9795
current_status = client.knowledge_bases.indexing_jobs.retrieve(job_uuid)
9896
if current_status.job:
9997
print(f"Current phase: {current_status.job.phase}")
100-
print(f"Completed datasources: {current_status.job.completed_datasources}/{current_status.job.total_datasources}")
98+
print(
99+
f"Completed datasources: {current_status.job.completed_datasources}/{current_status.job.total_datasources}"
100+
)
101101
except IndexingJobError as e:
102102
print(f"\n❌ Job failed: {e}")
103103

@@ -106,31 +106,31 @@ def example_manual_polling():
106106
"""Example of the old manual polling approach (for comparison)"""
107107
print("\n\nExample 3: Manual polling (old approach)")
108108
print("-" * 50)
109-
109+
110110
client = Gradient()
111111
knowledge_base_uuid = os.getenv("KNOWLEDGE_BASE_UUID", "your-kb-uuid-here")
112-
112+
113113
indexing_job = client.knowledge_bases.indexing_jobs.create(
114114
knowledge_base_uuid=knowledge_base_uuid,
115115
)
116-
116+
117117
job_uuid = indexing_job.job.uuid if indexing_job.job else None
118118
if not job_uuid:
119119
print("Error: Could not create indexing job")
120120
return
121-
121+
122122
print(f"Indexing job created with UUID: {job_uuid}")
123123
print("Manual polling (old approach)...")
124-
124+
125125
import time
126-
126+
127127
while True:
128128
indexing_job = client.knowledge_bases.indexing_jobs.retrieve(job_uuid)
129-
129+
130130
if indexing_job.job and indexing_job.job.phase:
131131
phase = indexing_job.job.phase
132132
print(f"Current phase: {phase}")
133-
133+
134134
if phase in ["BATCH_JOB_PHASE_UNKNOWN", "BATCH_JOB_PHASE_PENDING", "BATCH_JOB_PHASE_RUNNING"]:
135135
time.sleep(5)
136136
continue
@@ -146,36 +146,36 @@ async def example_async():
146146
"""Example using async/await"""
147147
print("\n\nExample 4: Async usage")
148148
print("-" * 50)
149-
149+
150150
from gradient import AsyncGradient
151-
151+
152152
client = AsyncGradient()
153153
knowledge_base_uuid = os.getenv("KNOWLEDGE_BASE_UUID", "your-kb-uuid-here")
154-
154+
155155
print(f"Creating indexing job for knowledge base: {knowledge_base_uuid}")
156156
indexing_job = await client.knowledge_bases.indexing_jobs.create(
157157
knowledge_base_uuid=knowledge_base_uuid,
158158
)
159-
159+
160160
job_uuid = indexing_job.job.uuid if indexing_job.job else None
161161
if not job_uuid:
162162
print("Error: Could not create indexing job")
163163
return
164-
164+
165165
print(f"Indexing job created with UUID: {job_uuid}")
166166
print("Waiting for indexing job to complete (async)...")
167-
167+
168168
try:
169169
completed_job = await client.knowledge_bases.indexing_jobs.wait_for_completion(
170170
job_uuid,
171171
poll_interval=5,
172172
timeout=600, # 10 minute timeout
173173
)
174-
174+
175175
print("\n✅ Indexing job completed successfully!")
176176
if completed_job.job:
177177
print(f"Phase: {completed_job.job.phase}")
178-
178+
179179
except IndexingJobTimeoutError as e:
180180
print(f"\n⏱️ Timeout: {e}")
181181
except IndexingJobError as e:
@@ -187,11 +187,11 @@ async def example_async():
187187
if __name__ == "__main__":
188188
# Run the basic example
189189
main()
190-
190+
191191
# Uncomment to run other examples:
192192
# example_with_custom_polling()
193193
# example_manual_polling()
194-
194+
195195
# For async example, you would need to run:
196196
# import asyncio
197197
# asyncio.run(example_async())

tests/api_resources/knowledge_bases/test_indexing_jobs.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ def test_wait_for_completion_raises_indexing_job_error_on_error(self, client: Gr
282282
assert "error" in str(exc_info.value).lower()
283283

284284
@parametrize
285-
def test_wait_for_completion_raises_indexing_job_error_on_cancelled(self, client: Gradient, respx_mock: Any) -> None:
285+
def test_wait_for_completion_raises_indexing_job_error_on_cancelled(
286+
self, client: Gradient, respx_mock: Any
287+
) -> None:
286288
"""Test that IndexingJobError is raised when job phase is CANCELLED"""
287289
job_uuid = "test-job-uuid"
288290
respx_mock.get(f"{base_url}/v2/gen-ai/indexing_jobs/{job_uuid}").mock(
@@ -321,9 +323,7 @@ def test_wait_for_completion_raises_timeout_error(self, client: Gradient, respx_
321323
)
322324

323325
with pytest.raises(IndexingJobTimeoutError) as exc_info:
324-
client.knowledge_bases.indexing_jobs.wait_for_completion(
325-
job_uuid, poll_interval=0.1, timeout=0.2
326-
)
326+
client.knowledge_bases.indexing_jobs.wait_for_completion(job_uuid, poll_interval=0.1, timeout=0.2)
327327

328328
assert exc_info.value.uuid == job_uuid
329329
assert exc_info.value.phase == "BATCH_JOB_PHASE_RUNNING"
@@ -567,7 +567,9 @@ async def test_path_params_update_cancel(self, async_client: AsyncGradient) -> N
567567
)
568568

569569
@parametrize
570-
async def test_wait_for_completion_raises_indexing_job_error_on_failed(self, async_client: AsyncGradient, respx_mock: Any) -> None:
570+
async def test_wait_for_completion_raises_indexing_job_error_on_failed(
571+
self, async_client: AsyncGradient, respx_mock: Any
572+
) -> None:
571573
"""Test that IndexingJobError is raised when job phase is FAILED"""
572574
job_uuid = "test-job-uuid"
573575
respx_mock.get(f"{base_url}/v2/gen-ai/indexing_jobs/{job_uuid}").mock(
@@ -592,7 +594,9 @@ async def test_wait_for_completion_raises_indexing_job_error_on_failed(self, asy
592594
assert "failed" in str(exc_info.value).lower()
593595

594596
@parametrize
595-
async def test_wait_for_completion_raises_indexing_job_error_on_error(self, async_client: AsyncGradient, respx_mock: Any) -> None:
597+
async def test_wait_for_completion_raises_indexing_job_error_on_error(
598+
self, async_client: AsyncGradient, respx_mock: Any
599+
) -> None:
596600
"""Test that IndexingJobError is raised when job phase is ERROR"""
597601
job_uuid = "test-job-uuid"
598602
respx_mock.get(f"{base_url}/v2/gen-ai/indexing_jobs/{job_uuid}").mock(
@@ -615,7 +619,9 @@ async def test_wait_for_completion_raises_indexing_job_error_on_error(self, asyn
615619
assert "error" in str(exc_info.value).lower()
616620

617621
@parametrize
618-
async def test_wait_for_completion_raises_indexing_job_error_on_cancelled(self, async_client: AsyncGradient, respx_mock: Any) -> None:
622+
async def test_wait_for_completion_raises_indexing_job_error_on_cancelled(
623+
self, async_client: AsyncGradient, respx_mock: Any
624+
) -> None:
619625
"""Test that IndexingJobError is raised when job phase is CANCELLED"""
620626
job_uuid = "test-job-uuid"
621627
respx_mock.get(f"{base_url}/v2/gen-ai/indexing_jobs/{job_uuid}").mock(

0 commit comments

Comments
 (0)