Skip to content

Commit

Permalink
fix bind completion file process
Browse files Browse the repository at this point in the history
  • Loading branch information
dtria91 committed Dec 18, 2024
1 parent f2a1096 commit 19075d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/app/services/file_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def bind_completion_file(
],
)

return CompletionDatasetDTO.from_current_dataset(inserted_file)
return CompletionDatasetDTO.from_completion_dataset(inserted_file)

except NoCredentialsError as nce:
raise HTTPException(
Expand Down
9 changes: 5 additions & 4 deletions sdk/radicalbit_platform_sdk/apis/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from io import BytesIO
import os
from typing import Dict, List, Optional
Expand Down Expand Up @@ -531,8 +532,9 @@ def load_completion_dataset(
"""

try:
json_data = pd.read_json(file_name).to_dict(orient='records')
validated_json_bytes = self.__validate_json(json_data)
with open(file_name, 'r', encoding='utf-8') as f:
raw_json = json.load(f)
validated_json_bytes = self.__validate_json(raw_json)
except Exception as e:
raise ClientError(
f'Failed to validate JSON file {file_name}: {str(e)}'
Expand Down Expand Up @@ -618,8 +620,7 @@ def __required_headers(self) -> List[str]:
def __validate_json(json_data: List[Dict]) -> BytesIO:
try:
validated_data = CompletionResponses.model_validate(json_data)
validated_json = pd.DataFrame(validated_data.model_dump())
return BytesIO(validated_json.to_json(orient='records').encode('utf-8'))
return BytesIO(validated_data.model_dump_json().encode())
except ValidationError as e:
raise ClientError(f'JSON validation error: {str(e)}') from e
except Exception as e:
Expand Down

0 comments on commit 19075d9

Please sign in to comment.