Skip to content

Commit dd5d3c6

Browse files
committed
fix file schema
1 parent 2c06780 commit dd5d3c6

File tree

4 files changed

+49
-30
lines changed

4 files changed

+49
-30
lines changed

examples/run.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,34 @@
44
def run_with_updates() -> None:
55
"""Example showing how to get streaming updates."""
66
api_key = "1nfsh-7yxm9j9mdpkkpsab2dxtnddxft"
7-
client = Inference(api_key=api_key, base_url="https://api-dev.inference.sh")
7+
client = Inference(api_key=api_key, base_url="https://api.inference.sh")
88

99
try:
1010
# Run with stream=True to get updates
1111
for update in client.run(
1212
{
13-
"app": "lginf/llm-router",
14-
"input": {"image": "https://storage.googleapis.com/folip-api-images/images/rGF6LfQuGQUEox9YF3JkuOiITUm1/dc4c0e18cb7a4f669bc6b6f3b99e6147.png"},
13+
"app": "infsh/glm-45-air",
14+
"input": {"text": "lolo"},
1515
"infra": "cloud",
1616
"variant": "default"
1717
},
1818
stream=True # Enable streaming updates
1919
):
20-
# Print each update as it comes in
20+
# Print detailed update info
2121
status = update.get("status")
2222
status_name = TaskStatus(status).name if status is not None else "UNKNOWN"
23-
print(f"Status: {status_name}")
2423

25-
# Print output when task completes
24+
# Print all available info
25+
print("\nUpdate received:")
26+
print(f" Status: {status_name}")
27+
if update.get("logs"):
28+
print(f" Logs: {update['logs']}")
29+
if update.get("progress"):
30+
print(f" Progress: {update['progress']}")
31+
if update.get("metrics"):
32+
print(f" Metrics: {update['metrics']}")
33+
34+
# Handle completion states
2635
if status == TaskStatus.COMPLETED:
2736
print("\n✓ Task completed!")
2837
print(f"Output: {update.get('output')}")
@@ -45,26 +54,15 @@ def run_simple() -> None:
4554
client = Inference(api_key=api_key, base_url="https://api-dev.inference.sh")
4655

4756
try:
48-
# Simple synchronous run
49-
task = client.run(
50-
{
51-
"app": "lginf/llm-router",
52-
"input": {"image": "https://storage.googleapis.com/folip-api-images/images/rGF6LfQuGQUEox9YF3JkuOiITUm1/dc4c0e18cb7a4f669bc6b6f3b99e6147.png"},
53-
"infra": "cloud",
54-
"variant": "default"
55-
}
56-
)
57+
# Simple synchronous run - waits for completion by default
58+
result = client.run({
59+
"app": "lginf/llm-router",
60+
"input": {"image": "https://storage.googleapis.com/folip-api-images/images/rGF6LfQuGQUEox9YF3JkuOiITUm1/dc4c0e18cb7a4f669bc6b6f3b99e6147.png"},
61+
"infra": "cloud",
62+
"variant": "default"
63+
})
5764

58-
print(f"Task ID: {task.get('id')}")
59-
60-
# Print final task
61-
if task.get("status") == TaskStatus.COMPLETED:
62-
print("\n✓ Task completed successfully!")
63-
print(f"Output: {task.get('output')}")
64-
else:
65-
status = task.get("status")
66-
status_name = TaskStatus(status).name if status is not None else "UNKNOWN"
67-
print(f"\n✗ Task did not complete. Final status: {status_name}")
65+
print(f"Task completed! Output: {result['output']}")
6866

6967
except Exception as exc: # noqa: BLE001
7068
print(f"\nError: {type(exc).__name__}: {exc}")

src/inferencesh/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ def run(
366366
task_id = task["id"]
367367
368368
# Stream updates
369-
for update in client.run(params, stream=True):
369+
stream = client.run(params, stream=True)
370+
for update in stream:
370371
print(f"Status: {update.get('status')}")
371372
if update.get('status') == TaskStatus.COMPLETED:
372373
print(f"Result: {update.get('output')}")
@@ -794,7 +795,8 @@ async def run(
794795
task_id = task["id"]
795796
796797
# Stream updates
797-
async for update in await client.run(params, stream=True):
798+
stream = await client.run(params, stream=True)
799+
for update in stream:
798800
print(f"Status: {update.get('status')}")
799801
if update.get('status') == TaskStatus.COMPLETED:
800802
print(f"Result: {update.get('output')}")

src/inferencesh/models/file.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,15 @@ def __get_pydantic_json_schema__(
266266
) -> dict[str, Any]:
267267
"""Generate a simple JSON schema that accepts either a string or an object"""
268268
json_schema = handler(schema)
269-
# Don't resolve refs here - that's what was causing the recursion
269+
if "$ref" in json_schema:
270+
# If we got a ref, resolve it to the actual schema
271+
json_schema = handler.resolve_ref_schema(json_schema)
272+
273+
# Add string as an alternative without recursion
270274
return {
271275
"$id": "/schemas/File",
272276
"oneOf": [
273-
json_schema,
277+
{k: v for k, v in json_schema.items() if k != "$ref"}, # Remove any $ref to prevent recursion
274278
{"type": "string"}
275279
]
276280
}

tests/test_sdk.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,19 @@ def read(self):
159159
tmp_path = file._tmp_path
160160
assert os.path.exists(tmp_path)
161161
del file
162-
assert not os.path.exists(tmp_path)
162+
assert not os.path.exists(tmp_path)
163+
164+
def test_file_schema():
165+
file = File(uri="https://example.com/test.txt")
166+
print(file.model_json_schema())
167+
assert file.model_json_schema() is not None
168+
assert file.model_json_schema()["$id"] == "/schemas/File"
169+
assert file.model_json_schema()["oneOf"] is not None
170+
assert file.model_json_schema()["oneOf"][0] is not None
171+
assert file.model_json_schema()["oneOf"][0]["type"] == "object"
172+
assert file.model_json_schema()["oneOf"][0]["properties"] is not None
173+
assert file.model_json_schema()["oneOf"][0]["properties"]["uri"] is not None
174+
assert file.model_json_schema()["oneOf"][0]["properties"]["path"] is not None
175+
assert file.model_json_schema()["oneOf"][0]["properties"]["content_type"] is not None
176+
assert file.model_json_schema()["oneOf"][0]["properties"]["size"] is not None
177+
assert file.model_json_schema()["oneOf"][0]["properties"]["filename"] is not None

0 commit comments

Comments
 (0)