1313
1414# Define the request model
1515class DeviceSummaryRequest (BaseModel ):
16- device_ids : List [ int ]
16+ device_id : str
1717 time_range : Optional [int ] = Field (
1818 default = 7 , description = "Time range in days, defaults to 7"
1919 )
2020
2121
2222# Define the response model
2323class DeviceStatistics (BaseModel ):
24- device_id : int
24+ device_id : str
2525 time_range : str
2626 data : str
2727
@@ -33,7 +33,7 @@ class DeviceSummaryResponse(BaseModel):
3333
3434
3535class DeviceRebootRequest (BaseModel ):
36- device_ids : List [ int ]
36+ device_id : str
3737
3838
3939# Response model for the device reboot
@@ -49,24 +49,21 @@ def reboot_network_device(request_data: DeviceRebootRequest):
4949 """
5050
5151 # Access data from the Pydantic model
52- device_ids = request_data .device_ids
52+ device_id = request_data .device_id
5353
54- # Validate 'device_ids '
54+ # Validate 'device_id '
5555 # (This is already validated by Pydantic, but additional logic can be added if needed)
56- if not device_ids :
57- raise HTTPException (
58- status_code = 400 , detail = "'device_ids' parameter is required"
59- )
56+ if not device_id :
57+ raise HTTPException (status_code = 400 , detail = "'device_id' parameter is required" )
6058
6159 # Simulate reboot operation and return the response
6260 statistics = []
63- for device_id in device_ids :
64- # Placeholder for actual data retrieval or device reboot logic
65- stats = {"data" : f"Device { device_id } has been successfully rebooted." }
66- statistics .append (stats )
61+ # Placeholder for actual data retrieval or device reboot logic
62+ stats = {"data" : f"Device { device_id } has been successfully rebooted." }
63+ statistics .append (stats )
6764
6865 # Return the response with a summary
69- return CoverageResponse (status = "success" , summary = {"device_ids " : device_ids })
66+ return CoverageResponse (status = "success" , summary = {"device_id " : device_id })
7067
7168
7269# Post method for device summary
@@ -76,28 +73,20 @@ def get_device_summary(request: DeviceSummaryRequest):
7673 Endpoint to retrieve device statistics based on device IDs and an optional time range.
7774 """
7875
79- # Extract 'device_ids ' and 'time_range' from the request
80- device_ids = request .device_ids
76+ # Extract 'device_id ' and 'time_range' from the request
77+ device_id = request .device_id
8178 time_range = request .time_range
8279
8380 # Simulate retrieving statistics for the given device IDs and time range
8481 statistics = []
85- minutes = 1
86- for device_id in device_ids :
87- stats = {
88- "device_id" : device_id ,
89- "time_range" : f"Last { time_range } days" ,
90- "data" : f"""Device { device_id } over the last { time_range } days experienced { minutes }
91- minutes of downtime.""" ,
92- }
93- minutes += 1
94- statistics .append (DeviceStatistics (** stats ))
95-
96- return DeviceSummaryResponse (statistics = statistics )
82+ minutes = 4
83+ stats = {
84+ "device_id" : device_id ,
85+ "time_range" : f"Last { time_range } days" ,
86+ "data" : f"""Device { device_id } over the last { time_range } days experienced { minutes }
87+ minutes of downtime.""" ,
88+ }
9789
90+ statistics .append (DeviceStatistics (** stats ))
9891
99- CHAT_COMPLETION_ENDPOINT = os .getenv ("CHAT_COMPLETION_ENDPOINT" )
100- client = OpenAI (
101- api_key = "--" ,
102- base_url = CHAT_COMPLETION_ENDPOINT ,
103- )
92+ return DeviceSummaryResponse (statistics = statistics )
0 commit comments