-
Notifications
You must be signed in to change notification settings - Fork 21
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 #3 from jld-adriano/cli
Add cli interface
- Loading branch information
Showing
6 changed files
with
116 additions
and
9 deletions.
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,66 @@ | ||
import json | ||
import sys | ||
|
||
from typer import Option, Typer | ||
|
||
from .jaiqu import translate_schema | ||
|
||
typer_app = Typer() | ||
|
||
|
||
@typer_app.command() | ||
def jaiqu( | ||
schema_file: str = Option(..., "-s", "--schema", help="Json schema file path"), | ||
data_file: str = Option( | ||
None, | ||
"-d", | ||
"--data", | ||
help="Json data file path. if not passed will try to read from stdin", | ||
), | ||
quiet: bool = Option(False, "-q", "--quiet", help="Quiet mode, only print errors"), | ||
key_hints: str = Option( | ||
None, | ||
"-k", | ||
"--key-hints", | ||
help="Extra prompt for the ai to help it complete the task", | ||
), | ||
max_retries: int = Option( | ||
10, | ||
"-r", | ||
"--max-retries", | ||
help="Max number of retries for the ai to complete the task", | ||
), | ||
): | ||
""" | ||
Validate and translate a json schema to jq filter | ||
""" | ||
with open(schema_file) as f: | ||
output_schema = json.load(f) | ||
if data_file is None: | ||
if sys.stdin.isatty(): | ||
sys.exit("Error: No data piped to stdin.") | ||
else: | ||
if not quiet: | ||
print("--data not provided, reading from stdin") | ||
data_file = sys.stdin.read() | ||
input_json = json.loads(data_file) | ||
else: | ||
with open(data_file) as f: | ||
input_json = json.load(f) | ||
|
||
query = translate_schema( | ||
output_schema=output_schema, | ||
input_json=input_json, | ||
key_hints=key_hints, | ||
max_retries=max_retries, | ||
quiet=quiet | ||
) | ||
print(query) | ||
|
||
|
||
def main(): | ||
typer_app() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "jaiqu" | ||
version = "0.0.4" | ||
version = "0.0.5" | ||
authors = [ | ||
{ name = "Alex Reibman", email = "[email protected]" }, | ||
{ name = "Howard Gil", email = "[email protected]" }, | ||
|
@@ -21,7 +21,8 @@ classifiers = [ | |
dependencies = [ | ||
"jq==1.6.0", | ||
"openai~=1.12.0", | ||
"jsonschema==4.21.1" | ||
"jsonschema==4.21.1", | ||
"typer==0.9.0", | ||
] | ||
|
||
[project.optional-dependencies] | ||
|
@@ -34,3 +35,9 @@ dev = [ | |
[project.urls] | ||
Homepage = "https://github.com/AgentOps-AI/Jaiqu" | ||
Issues = "https://github.com/AgentOps-AI/Jaiqu/issues" | ||
|
||
[project.entry-points.console_scripts] | ||
jaiqu = "jaiqu.cli:main" | ||
|
||
[tool.setuptools] | ||
packages = { find = { where = ["."], exclude = ["samples"] } } |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
jq==1.6.0 | ||
openai>=1.12.0,<2.0.0 | ||
jsonschema==4.21.1 | ||
jsonschema==4.21.1 | ||
typer==0.9.0 |
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,11 @@ | ||
{ | ||
"call.id": "123", | ||
"datetime": "2022-01-01", | ||
"timestamp": 1640995200, | ||
"Address": "123 Main St", | ||
"user": { | ||
"name": "John Doe", | ||
"age": 30, | ||
"contact": "[email protected]" | ||
} | ||
} |
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,22 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": ["string", "null"], | ||
"description": "A unique identifier for the record." | ||
}, | ||
"date": { | ||
"type": "string", | ||
"description": "A string describing the date." | ||
}, | ||
"model": { | ||
"type": "string", | ||
"description": "A text field representing the model used." | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"date" | ||
] | ||
} |