44def 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 ("\n Update 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"\n Error: { type (exc ).__name__ } : { exc } " )
0 commit comments