29 lines
924 B
Python
29 lines
924 B
Python
|
|
import argparse
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from cockpit_agent.common.model_registry import ModelRegistry
|
||
|
|
from cockpit_agent.config import load_config
|
||
|
|
from cockpit_agent.intent.parser import ModelIntentParser
|
||
|
|
|
||
|
|
|
||
|
|
DEFAULT_CONFIG = Path(__file__).resolve().parents[1] / "configs" / "default.toml"
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> None:
|
||
|
|
parser = argparse.ArgumentParser(description="Parse a cockpit instruction")
|
||
|
|
parser.add_argument("--instruction", required=True)
|
||
|
|
parser.add_argument("--config", type=Path, default=DEFAULT_CONFIG)
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
config = load_config(args.config)
|
||
|
|
registry = ModelRegistry()
|
||
|
|
model = registry.get_text_generator(config.intent)
|
||
|
|
intent_parser = ModelIntentParser(model, config.intent.max_new_tokens)
|
||
|
|
intent = intent_parser.parse(args.instruction)
|
||
|
|
print(json.dumps(intent.to_dict(), indent=2, ensure_ascii=False))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|