Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pydantic config #189

Merged
merged 53 commits into from
Sep 19, 2024
Merged

Pydantic config #189

merged 53 commits into from
Sep 19, 2024

Conversation

SecretiveShell
Copy link
Contributor

This PR rewrites the configuration logic to be a subclass of a pydantic model. This has the following benefits:

  • type validation for all models
  • single source of truth for all configuration options
  • automatically generate template config files
  • improve type hinting and static analysis
  • remove ambiguity with unknows relating to kwargs
  • remove the need for many unwrap() calls

When a new config option is added to the pydantic models:

  • automatically add new command line arguments
  • automatically add new environment variables
  • automatically add support inside of config.yml

Possible benefits in the future:

  • generate a new config file from the current config at the time of an error to improve debugging
  • generate a new config.yml file with new additions while retaining the current user's config options
  • ship different default configurations on different platforms (e.g docker)

Additional context
This has the side effect of solving #160

- add models for config options
- add function to regenerate config.yml
- replace references to config with pydantic compatible references
- remove unnecessary unwrap() statements

TODO:

- auto generate env vars
- auto generate argparse
- test loading a model
- generate arg parser dynamically
- remove legavy parser code
- convert pydantic to dict to avoid errors with current files
- fix formatting
- load config from env vars (eg. TABBY_NETWORK_HOST)
- remove print statements
- improve command line args automation
@SecretiveShell SecretiveShell marked this pull request as ready for review September 7, 2024 02:13
SecretiveShell and others added 21 commits September 11, 2024 18:00
Pydantic provides these helpers. Better to use these instead of
the inspect lib.

Signed-off-by: kingbri <bdashore3@proton.me>
Appending lines also requires a space between each one otherwise
they'll squish together.

Signed-off-by: kingbri <bdashore3@proton.me>
Remove access of private attributes and use safer functions. Also
move generalized functions into utils files.

Signed-off-by: kingbri <bdashore3@proton.me>
This is no longer needed because config is a singleton.

Signed-off-by: kingbri <bdashore3@proton.me>
Config.yml and args take in two different values.

Signed-off-by: kingbri <bdashore3@proton.me>
Signed-off-by: kingbri <bdashore3@proton.me>
These changes fix the amount and order of newlines to look pleasing
for the user. However, the changes used in here are kind of hacky
and need a proper fix that can contain the same level of efficiency.

Signed-off-by: kingbri <bdashore3@proton.me>
Adheres to the old config.yml's descriptions and allows for newlines
in generated YAML.

Signed-off-by: kingbri <bdashore3@proton.me>
It makes sense for the LLM model groups to be clustered around
each other with the least used groups towards the bottom.

Signed-off-by: kingbri <bdashore3@proton.me>
This makes both config.yml and args more descriptive than before.

Signed-off-by: kingbri <bdashore3@proton.me>
bdashore3 and others added 25 commits September 16, 2024 00:55
Signed-off-by: kingbri <bdashore3@proton.me>
Allows for generation from an existing config file. Primarily used
for migration purposes.

Signed-off-by: kingbri <bdashore3@proton.me>
These keys were changed as well to include a "log_" prefix like the
CLI arguments.

Signed-off-by: kingbri <bdashore3@proton.me>
If a sub-field exists in the model provided to the file generator,
use it. Otherwise always fallback to the default factory. This prevents
any subsequent errors from setting None.

Signed-off-by: kingbri <bdashore3@proton.me>
Rollback to the old config if automigration fails.

Signed-off-by: kingbri <bdashore3@proton.me>
- Let the user know that migration is going to be attempted
- Have a more informative error message if auto-migration fails
- Revert back to the old config file on failure
- Don't load with a partially parsed config

Signed-off-by: kingbri <bdashore3@proton.me>
Keep the models as a separate reference file without any extra
functions.

Signed-off-by: kingbri <bdashore3@proton.me>
Signed-off-by: kingbri <bdashore3@proton.me>
A deprecated preferences global var was being referenced.

Signed-off-by: kingbri <bdashore3@proton.me>
Ignore all "backup" files

Signed-off-by: kingbri <bdashore3@proton.me>
This is not a True default.

Signed-off-by: kingbri <bdashore3@proton.me>
Remove the extraneous newlines from the beginning of the preamble.

Signed-off-by: kingbri <bdashore3@proton.me>
Loading from file adds extra overhead for actions that don't rely
on file loading.

Signed-off-by: kingbri <bdashore3@proton.me>
This is not ideal because users may still have trouble understanding
what a lora includes, but adding an example comment will help instead
of leaving a blank line.

Signed-off-by: kingbri <bdashore3@proton.me>
Uses the new YAML generator.

Signed-off-by: kingbri <bdashore3@proton.me>
Some were using the old unwrap methods.

Signed-off-by: kingbri <bdashore3@proton.me>
Properly add comments and newlines where they need to go.

Signed-off-by: kingbri <bdashore3@proton.me>
The loader takes in the "draft" parameter, so map the config model
to that when creating kwargs for initial load.

Also map the old "draft" key to the new "draft_model" key.

Signed-off-by: kingbri <bdashore3@proton.me>
Leaving blank will use the model's set value or auto-calculate.

Signed-off-by: kingbri <bdashore3@proton.me>
Loaders that read use a safe type while loaders that write use both
round-trip and safe options.

Also don't create module-level parsers where they're not needed.

Signed-off-by: kingbri <bdashore3@proton.me>
Signed-off-by: kingbri <bdashore3@proton.me>
@bdashore3 bdashore3 merged commit 03189bc into theroyallab:main Sep 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants