Skip to content

Commit fd64f8a

Browse files
fix: Improve download model command optional arguments
1 parent 4560a3d commit fd64f8a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Commands/DownloadModelCommand.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function configure(): void
5959
'The filename of the exact model weights version to download.',
6060
null
6161
);
62-
62+
6363
$this->addOption(
6464
'host',
6565
null,
@@ -79,12 +79,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7979
$quantized = filter_var($input->getOption('quantized'), FILTER_VALIDATE_BOOLEAN);
8080
$task = $input->getArgument('task');
8181
$modelFilename = $input->getOption('model-filename');
82-
$host = $input->getOption('host') ?? Transformers::$remoteHost;
83-
84-
Transformers::setup()
85-
->setCacheDir($cacheDir)
86-
->setRemoteHost(rtrim($host,'/'))
87-
->apply();
82+
$host = $input->getOption('host');
83+
84+
$transformers = Transformers::setup();
85+
86+
if ($cacheDir != null) $transformers->setCacheDir($cacheDir);
87+
if ($host != null) $transformers->setRemoteHost($host);
8888

8989
try {
9090
$task = $task ? Task::tryFrom($task) : null;
@@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
115115

116116
return Command::SUCCESS;
117117
} catch (Exception $e) {
118-
$output->writeln('' . $e->getMessage());
118+
$output->writeln(''.$e->getMessage());
119119
return Command::FAILURE;
120120
}
121121
}

src/Transformers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public static function ensureInitialized(): void
6565
/**
6666
* Set the default cache directory for transformers models and tokenizers
6767
*
68-
* @param string|null $cacheDir
68+
* @param string $cacheDir
6969
*
7070
* @return $this
7171
*/
72-
public function setCacheDir(?string $cacheDir): static
72+
public function setCacheDir(string $cacheDir): static
7373
{
74-
if ($cacheDir != null) self::$cacheDir = $cacheDir;
74+
self::$cacheDir = $cacheDir;
7575

7676
return $this;
7777
}

0 commit comments

Comments
 (0)