From 7263ab6aa3523b2cbdcec211f56f6ea88ac3eee0 Mon Sep 17 00:00:00 2001 From: "Cody J. Hanson" Date: Wed, 13 Nov 2024 20:50:24 -0600 Subject: [PATCH] Command to loop through schemas and send to llm --- scripts/autogenerate.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/scripts/autogenerate.py b/scripts/autogenerate.py index 10558f3..860b171 100644 --- a/scripts/autogenerate.py +++ b/scripts/autogenerate.py @@ -1,6 +1,8 @@ """Tools for autogenerating streams.""" +import subprocess import typer +import click from pathlib import Path import json import jsonref @@ -58,6 +60,11 @@ def get_export_specs( print(items_schema) +def _get_response_spec_for_path(spec_path: Path, url_path: str): + full_spec = get_spec_from_path(spec_path) + return get_response_spec_from_path(full_spec, url_path) + + @app.command() def get_response_spec_for_path( spec_path: Annotated[ @@ -66,9 +73,28 @@ def get_response_spec_for_path( url_path: str, ): """Get the response schema for a path.""" - full_spec = get_spec_from_path(spec_path) - response_spec = get_response_spec_from_path(full_spec, url_path) - print(response_spec) + print(_get_response_spec_for_path(spec_path, url_path)) + + +@app.command() +def get_prompts( + spec_path: Annotated[ + Path, typer.Option(exists=True, file_okay=True, dir_okay=False, readable=True) + ], +): + """Get all prompts for a given spec file.""" + for path in _get_paths_with_get(get_spec_from_path(spec_path)): + try: + response_spec = _get_response_spec_for_path(spec_path, path) + text = f"URL path segment: {path}\nJSON schema:\n{response_spec}" + process = subprocess.Popen( + "pbcopy", env={"LANG": "en_US.UTF-8"}, stdin=subprocess.PIPE + ) + process.communicate(text.encode("utf-8")) + print(f"Path: {path}") + click.pause() + except KeyError: + pass if __name__ == "__main__":