@@ -667,7 +667,7 @@ def subscribe_to_datasource_jobs(client, datasource_id, callback=None, timeout=3
667
667
try :
668
668
# Query for all jobs with this datasource as source
669
669
response = client .http_client .get (
670
- f"{ client .base_url } /v1/jobs/status " ,
670
+ f"{ client .base_url } /v1/jobs/by-source " ,
671
671
params = {"source" : "datasource" , "source_id" : datasource_id },
672
672
)
673
673
@@ -689,7 +689,7 @@ def subscribe_to_datasource_jobs(client, datasource_id, callback=None, timeout=3
689
689
690
690
# Start monitoring any new jobs we find
691
691
for job in jobs :
692
- job_id = job .get ("id " )
692
+ job_id = job .get ("job_id " )
693
693
if job_id and job_id not in monitored_jobs :
694
694
logger .info (
695
695
f"Found new job to monitor: { job_id } (status: { job .get ('status' )} )"
@@ -942,113 +942,71 @@ def main(): # noqa: C901
942
942
# Step 9: List API endpoints
943
943
print_step (9 , "List API endpoints" )
944
944
945
- try :
946
- # Try to get endpoints through the API if available
947
- # This is a placeholder - adjust according to the actual API endpoints
948
- print ("Available API endpoints:" )
949
- for i , qp in enumerate (published_queries , 1 ):
950
- endpoint_path = f"/v1/live/{ project .id } /{ qp .id } /data"
951
- print (f" { i } . { qp .name } " )
952
- print (f" Endpoint: { client .base_url } { endpoint_path } " )
953
- print (" Method: GET" )
954
-
955
- # Try to get OpenAPI spec if available
956
- print ("\n API Documentation (OpenAPI):" )
957
- print (f" URL: { client .base_url } /v1/openapi/{ project .id } " )
958
- except Exception as e :
959
- print (f"Error listing endpoints: { e } " )
945
+ print ("Fetching API endpoints for the project..." )
946
+ response = client .http_client .get (f"{ client .base_url } /v1/apis/project/{ project .id } " )
947
+
948
+ if response .status_code == 200 :
949
+ apis = response .json ()
950
+ print (f"Found { len (apis )} APIs for project { project .id } " )
951
+
952
+ for i , api in enumerate (apis , 1 ):
953
+ print (f" { i } . API ID: { api .get ('id' )} " )
954
+ print (f" Path: { api .get ('base_path' , 'Unknown' )} " )
955
+ print (f" Name: { api .get ('name' , 'Unnamed' )} " )
956
+ print (f" Description: { api .get ('description' , 'Unknown' )} " )
957
+ print (f" Version: { api .get ('version' , 'v1' )} " )
958
+ else :
959
+ print (f"Error fetching APIs: { response .status_code } { response .text } " )
960
+ raise Exception (f"Error fetching APIs: { response .status_code } { response .text } " )
961
+
962
+ # Try to get endpoints through the API if available
963
+ print ("Available API endpoints:" )
964
+ for i , endpoint in enumerate (api ["endpoints" ]):
965
+ path = endpoint ["path" ]
966
+ url = f"{ client .base_url } /live/{ api ['base_path' ]} /{ api ['version' ]} /{ path } "
967
+ print (f" { i } . { url } " )
968
+ else :
969
+ print ("No endpoints available to test" )
970
+
971
+ # Try to get OpenAPI spec if available
972
+ print ("\n API Documentation (OpenAPI):" )
973
+ print (
974
+ f" URL: { client .base_url } /live/{ api ['base_path' ]} /{ api ['version' ]} /openapi.json"
975
+ )
976
+ print ("\n LLM Tools Compatibility:" )
977
+ print (
978
+ f" URL: { client .base_url } /live/{ api ['base_path' ]} /{ api ['version' ]} /tools.json"
979
+ )
960
980
961
981
# Step 10: Make API requests with custom parameters
962
- print_step (10 , "Make API requests with custom parameters" )
963
-
964
- if published_queries :
965
- try :
966
- # Pick the first published query for testing
967
- test_query = published_queries [0 ]
968
- endpoint_path = f"/v1/live/{ project .id } /{ test_query .id } /data"
969
- full_url = f"{ client .base_url } { endpoint_path } "
970
-
971
- print (f"Testing API endpoint: { full_url } " )
972
- print ("With parameters: limit=5, sort_by=date" )
982
+ print_step (10 , "Make API requests with default parameters" )
973
983
974
- headers = {
975
- "Authorization" : f"Bearer { API_KEY } " ,
976
- "Content-Type" : "application/json" ,
977
- }
984
+ # Try to get endpoints through the API if available
985
+ print ("Available API endpoints:" )
986
+ for i , endpoint in enumerate (api ["endpoints" ]):
987
+ path = endpoint ["path" ]
988
+ url = f"{ client .base_url } /live/{ api ['base_path' ]} /{ api ['version' ]} /{ path } "
989
+ print (f" { i } . { url } " )
978
990
979
- params = {"limit" : 5 , "sort_by" : "date" }
980
-
981
- response = requests .get (full_url , headers = headers , params = params )
991
+ headers = {
992
+ "Authorization" : f"Bearer { API_KEY } " ,
993
+ "Content-Type" : "application/json" ,
994
+ }
982
995
983
- if response .status_code == 200 :
984
- print ("API request successful!" )
985
- result = response .json ()
986
- print (json .dumps (result , indent = 2 ))
987
- else :
988
- print (f"API request failed with status code { response .status_code } " )
989
- print (response .text )
990
-
991
- # If real API fails, show mock data
992
- print ("\n Mock response for demonstration:" )
993
- mock_response = {
994
- "data" : [
995
- {
996
- "date" : "2023-03-01" ,
997
- "symbol" : "AAPL" ,
998
- "price" : 145.91 ,
999
- "volume" : 83521000 ,
1000
- },
1001
- {
1002
- "date" : "2023-03-02" ,
1003
- "symbol" : "AAPL" ,
1004
- "price" : 149.58 ,
1005
- "volume" : 75684300 ,
1006
- },
1007
- {
1008
- "date" : "2023-03-03" ,
1009
- "symbol" : "AAPL" ,
1010
- "price" : 151.03 ,
1011
- "volume" : 70898900 ,
1012
- },
1013
- ],
1014
- "meta" : {
1015
- "count" : 3 ,
1016
- "total" : 22 ,
1017
- "sort_by" : "date" ,
1018
- "order" : "asc" ,
1019
- },
1020
- }
1021
- print (json .dumps (mock_response , indent = 2 ))
996
+ response = requests .get (url , headers = headers )
997
+ if response .status_code == 200 :
998
+ result = response .json ()
999
+ print (
1000
+ f"\033 [34mResponse data: { json .dumps (result , indent = 2 )[:500 ]} ...\033 [0m"
1001
+ ) # Truncate long responses
1002
+ else :
1003
+ print (f"Request failed with status code { response .status_code } " )
1004
+ print (f"Response: { response .text } " )
1005
+ else :
1006
+ print ("No endpoints available to test" )
1022
1007
1023
- except Exception as e :
1024
- print (f"Error making API request: { e } " )
1025
-
1026
- # Show mock data if real request fails
1027
- print ("\n Mock response for demonstration:" )
1028
- mock_response = {
1029
- "data" : [
1030
- {
1031
- "date" : "2023-03-01" ,
1032
- "symbol" : "AAPL" ,
1033
- "price" : 145.91 ,
1034
- "volume" : 83521000 ,
1035
- },
1036
- {
1037
- "date" : "2023-03-02" ,
1038
- "symbol" : "AAPL" ,
1039
- "price" : 149.58 ,
1040
- "volume" : 75684300 ,
1041
- },
1042
- {
1043
- "date" : "2023-03-03" ,
1044
- "symbol" : "AAPL" ,
1045
- "price" : 151.03 ,
1046
- "volume" : 70898900 ,
1047
- },
1048
- ],
1049
- "meta" : {"count" : 3 , "total" : 22 , "sort_by" : "date" , "order" : "asc" },
1050
- }
1051
- print (json .dumps (mock_response , indent = 2 ))
1008
+ if not published_queries :
1009
+ raise Exception ("No published queries found" )
1052
1010
1053
1011
# Step 11: Use the chat endpoint with streaming response
1054
1012
print_step (11 , "Use the chat endpoint with streaming response" )
0 commit comments