Skip to content

Commit

Permalink
fix: Tirando padrão None em parâmetros obrigatorios
Browse files Browse the repository at this point in the history
Colocando o default=None no Field deixava o parâmetro como não
obrigatório, o que não é esperado.
  • Loading branch information
RWallan committed May 20, 2024
1 parent 7ca6ac9 commit 5ff45ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions openiziai/fine_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class JobStatus(Enum):


class FineTuning(BaseModel):
client: OpenAI = Field(default=None, description='Client da OpenAI.')
client: OpenAI = Field(description='Client da OpenAI.')
train_file: Path | str
task: Task = Field(default=None)
task: Task = Field()
model: str = Field(default='gpt-3.5-turbo')
_file_id: str = PrivateAttr(default=None)
_job_id: str = PrivateAttr(default=None)
Expand Down
2 changes: 0 additions & 2 deletions openiziai/tools/train_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ class TrainDataTool(BaseModel):

client: OpenAI = Field(default=None, description='Client da OpenAI.')
data: DataDict = Field(
default=None,
description='Dados utilizados para construir o dado de treino.',
)
task: Task = Field(
default=None,
description='Descrição da task que o modelo deverá executar.',
)
model: str = Field(
Expand Down
19 changes: 14 additions & 5 deletions tests/test_fine_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,34 @@
from openiziai.fine_tuning import FineTuning


def test_size_validation_success(openai_fine_tuning):
def test_init_invalid_data():
with pytest.raises(ValidationError):
FineTuning(client=None, task=None)


def test_size_validation_success(openai_fine_tuning, valid_task):
mock_path = MagicMock(spec=Path)
mock_path.stat.return_value.st_size = 100000 # Menos de 512MB

fine_tuning = FineTuning(client=openai_fine_tuning, train_file=mock_path)
fine_tuning = FineTuning(
client=openai_fine_tuning, task=valid_task, train_file=mock_path
)

assert fine_tuning.train_file == mock_path


def test_size_validation_failure(openai_fine_tuning):
def test_size_validation_failure(openai_fine_tuning, valid_task):
mock_path = MagicMock(spec=Path)
mock_path.stat.return_value.st_size = 600000000

with pytest.raises(ValidationError):
FineTuning(client=openai_fine_tuning, train_file=mock_path)
FineTuning(
client=openai_fine_tuning, task=valid_task, train_file=mock_path
)


def test_upload_file_to_openai(fine_tuning):
with patch('builtins.open', mock_open(read_data="data")):
with patch('builtins.open', mock_open(read_data='data')):
fine_tuning.upload_file_to_openai()

assert fine_tuning.file_id == 'file-id'
Expand Down

0 comments on commit 5ff45ee

Please sign in to comment.