Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

schemas.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import base64
  17. from typing import Optional
  18. from pydantic import BaseModel, Field, field_validator
  19. from models.enums import ResourceLimitType, ResultStatus, RuntimeErrorType, SupportLanguage, UnauthorizedAccessType
  20. class CodeExecutionResult(BaseModel):
  21. status: ResultStatus
  22. stdout: str
  23. stderr: str
  24. exit_code: int
  25. detail: Optional[str] = None
  26. # Resource usage
  27. time_used_ms: Optional[float] = None
  28. memory_used_kb: Optional[float] = None
  29. # Error details
  30. resource_limit_type: Optional[ResourceLimitType] = None
  31. unauthorized_access_type: Optional[UnauthorizedAccessType] = None
  32. runtime_error_type: Optional[RuntimeErrorType] = None
  33. class CodeExecutionRequest(BaseModel):
  34. code_b64: str = Field(..., description="Base64 encoded code string")
  35. language: SupportLanguage = Field(default=SupportLanguage.PYTHON, description="Programming language")
  36. arguments: Optional[dict] = Field(default={}, description="Arguments")
  37. @field_validator("code_b64")
  38. @classmethod
  39. def validate_base64(cls, v: str) -> str:
  40. try:
  41. base64.b64decode(v, validate=True)
  42. return v
  43. except Exception as e:
  44. raise ValueError(f"Invalid base64 encoding: {str(e)}")