diff options
author | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
---|---|---|
committer | S. Solomon Darnell | 2025-03-28 21:52:21 -0500 |
commit | 4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch) | |
tree | ee3dc5af3b6313e921cd920906356f5d4febc4ed /R2R/r2r/main/r2r.py | |
parent | cc961e04ba734dd72309fb548a2f97d67d578813 (diff) | |
download | gn-ai-master.tar.gz |
Diffstat (limited to 'R2R/r2r/main/r2r.py')
-rwxr-xr-x | R2R/r2r/main/r2r.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/R2R/r2r/main/r2r.py b/R2R/r2r/main/r2r.py new file mode 100755 index 00000000..2d8601b2 --- /dev/null +++ b/R2R/r2r/main/r2r.py @@ -0,0 +1,51 @@ +from typing import Optional + +from .app import R2RApp +from .assembly.config import R2RConfig +from .engine import R2REngine + + +class R2R: + engine: R2REngine + app: R2RApp + + def __init__( + self, + engine: Optional[R2REngine] = None, + app: Optional[R2RApp] = None, + config: Optional[R2RConfig] = None, + from_config: Optional[str] = None, + *args, + **kwargs + ): + if engine and app: + self.engine = engine + self.app = app + elif (config or from_config) or ( + config is None and from_config is None + ): + from .assembly.builder import R2RBuilder + + # Handle the case where 'from_config' is None and 'config' is None + if not config and not from_config: + from_config = "default" + builder = R2RBuilder( + config=config, + from_config=from_config, + ) + built = builder.build() + self.engine = built.engine + self.app = built.app + else: + raise ValueError( + "Must provide either 'engine' and 'app', or 'config'/'from_config' to build the R2R object." + ) + + def __getattr__(self, name): + # Check if the attribute name is 'app' and return it directly + if name == "app": + return self.app + elif name == "serve": + return self.app.serve + # Otherwise, delegate to the engine + return getattr(self.engine, name) |