-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from llm-agents-php/feature/options-docs
Adds default implementation for options and also provides information on what options are
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\LLM; | ||
|
||
class Options implements OptionsInterface | ||
{ | ||
private array $options; | ||
|
||
public function __construct(array $options = []) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
public function has(string $option): bool | ||
{ | ||
return isset($this->options[$option]); | ||
} | ||
|
||
public function get(string $option, mixed $default = null): mixed | ||
{ | ||
return $this->options[$option] ?? $default; | ||
} | ||
|
||
public function with(string $option, mixed $value): static | ||
{ | ||
$new = clone $this; | ||
$new->options[$option] = $value; | ||
return $new; | ||
} | ||
|
||
public function merge(OptionsInterface $options): static | ||
{ | ||
$new = clone $this; | ||
foreach ($options as $key => $value) { | ||
$new->options[$key] = $value; | ||
} | ||
|
||
return $new; | ||
} | ||
|
||
public function getIterator(): \Traversable | ||
{ | ||
return new \ArrayIterator($this->options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LLM\Agents\LLM; | ||
|
||
final class OptionsFactory implements OptionsFactoryInterface | ||
{ | ||
public function create(array $options = []): OptionsInterface | ||
{ | ||
return new Options($options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters