ostruct-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ostruct/__init__.py +0 -0
- ostruct/cli/__init__.py +19 -0
- ostruct/cli/cache_manager.py +175 -0
- ostruct/cli/cli.py +2033 -0
- ostruct/cli/errors.py +329 -0
- ostruct/cli/file_info.py +316 -0
- ostruct/cli/file_list.py +151 -0
- ostruct/cli/file_utils.py +518 -0
- ostruct/cli/path_utils.py +123 -0
- ostruct/cli/progress.py +105 -0
- ostruct/cli/security.py +311 -0
- ostruct/cli/security_types.py +49 -0
- ostruct/cli/template_env.py +55 -0
- ostruct/cli/template_extensions.py +51 -0
- ostruct/cli/template_filters.py +650 -0
- ostruct/cli/template_io.py +261 -0
- ostruct/cli/template_rendering.py +347 -0
- ostruct/cli/template_schema.py +565 -0
- ostruct/cli/template_utils.py +288 -0
- ostruct/cli/template_validation.py +375 -0
- ostruct/cli/utils.py +31 -0
- ostruct/py.typed +0 -0
- ostruct_cli-0.1.0.dist-info/LICENSE +21 -0
- ostruct_cli-0.1.0.dist-info/METADATA +182 -0
- ostruct_cli-0.1.0.dist-info/RECORD +27 -0
- ostruct_cli-0.1.0.dist-info/WHEEL +4 -0
- ostruct_cli-0.1.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Yaniv Golan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,182 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: ostruct-cli
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: CLI for OpenAI Structured Output
|
5
|
+
Author: Yaniv Golan
|
6
|
+
Author-email: yaniv@golan.name
|
7
|
+
Requires-Python: >=3.9,<4.0
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
14
|
+
Requires-Dist: cachetools (>=5.3.2,<6.0.0)
|
15
|
+
Requires-Dist: chardet (>=5.0.0,<6.0.0)
|
16
|
+
Requires-Dist: ijson (>=3.2.3,<4.0.0)
|
17
|
+
Requires-Dist: jsonschema (>=4.23.0,<5.0.0)
|
18
|
+
Requires-Dist: openai-structured (>=1.0.0,<2.0.0)
|
19
|
+
Requires-Dist: pydantic (>=2.6.3,<3.0.0)
|
20
|
+
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
21
|
+
Requires-Dist: tiktoken (>=0.6.0,<0.7.0)
|
22
|
+
Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
|
23
|
+
Description-Content-Type: text/markdown
|
24
|
+
|
25
|
+
# ostruct-cli
|
26
|
+
|
27
|
+
[](https://badge.fury.io/py/ostruct-cli)
|
28
|
+
[](https://pypi.org/project/ostruct-cli/)
|
29
|
+
[](https://ostruct-cli.readthedocs.io/en/latest/?badge=latest)
|
30
|
+
[](https://github.com/yaniv-golan/ostruct/actions/workflows/ci.yml)
|
31
|
+
[](https://opensource.org/licenses/MIT)
|
32
|
+
|
33
|
+
Command-line interface for working with OpenAI models and structured output, powered by the [openai-structured](https://github.com/yaniv-golan/openai-structured) library.
|
34
|
+
|
35
|
+
## Features
|
36
|
+
|
37
|
+
- Generate structured output from natural language using OpenAI models
|
38
|
+
- Rich template system for defining output schemas
|
39
|
+
- Automatic token counting and context window management
|
40
|
+
- Streaming support for real-time output
|
41
|
+
- Caching system for cost optimization
|
42
|
+
- Secure handling of sensitive data
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
```bash
|
47
|
+
pip install ostruct-cli
|
48
|
+
```
|
49
|
+
|
50
|
+
## Quick Start
|
51
|
+
|
52
|
+
1. Set your OpenAI API key:
|
53
|
+
|
54
|
+
```bash
|
55
|
+
export OPENAI_API_KEY=your-api-key
|
56
|
+
```
|
57
|
+
|
58
|
+
2. Create a task template file `task.j2`:
|
59
|
+
|
60
|
+
```
|
61
|
+
Extract information about the person: {{ stdin }}
|
62
|
+
```
|
63
|
+
|
64
|
+
3. Create a schema file `schema.json`:
|
65
|
+
|
66
|
+
```json
|
67
|
+
{
|
68
|
+
"type": "object",
|
69
|
+
"properties": {
|
70
|
+
"name": {
|
71
|
+
"type": "string",
|
72
|
+
"description": "The person's full name"
|
73
|
+
},
|
74
|
+
"age": {
|
75
|
+
"type": "integer",
|
76
|
+
"description": "The person's age"
|
77
|
+
},
|
78
|
+
"occupation": {
|
79
|
+
"type": "string",
|
80
|
+
"description": "The person's job or profession"
|
81
|
+
}
|
82
|
+
},
|
83
|
+
"required": ["name", "age", "occupation"]
|
84
|
+
}
|
85
|
+
```
|
86
|
+
|
87
|
+
4. Run the CLI:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
echo "John Smith is a 35 year old software engineer" | ostruct --task @task.j2 --schema schema.json
|
91
|
+
```
|
92
|
+
|
93
|
+
Output:
|
94
|
+
|
95
|
+
```json
|
96
|
+
{
|
97
|
+
"name": "John Smith",
|
98
|
+
"age": 35,
|
99
|
+
"occupation": "software engineer"
|
100
|
+
}
|
101
|
+
```
|
102
|
+
|
103
|
+
### About Template Files
|
104
|
+
|
105
|
+
Template files use the `.j2` extension to indicate they contain Jinja2 template syntax. This convention:
|
106
|
+
|
107
|
+
- Enables proper syntax highlighting in most editors
|
108
|
+
- Makes it clear the file contains template logic
|
109
|
+
- Follows industry standards for Jinja2 templates
|
110
|
+
|
111
|
+
While the CLI accepts templates with any extension (when prefixed with `@`), we recommend using `.j2` for better tooling support and clarity.
|
112
|
+
|
113
|
+
## Debug Options
|
114
|
+
|
115
|
+
- `--show-model-schema`: Display the generated Pydantic model schema
|
116
|
+
- `--debug-validation`: Show detailed schema validation debugging
|
117
|
+
- `--verbose-schema`: Enable verbose schema debugging output
|
118
|
+
- `--debug-openai-stream`: Enable low-level debug output for OpenAI streaming (very verbose)
|
119
|
+
- `--progress-level {none,basic,detailed}`: Set progress reporting level (default: basic)
|
120
|
+
|
121
|
+
All debug and error logs are written to:
|
122
|
+
|
123
|
+
- `~/.ostruct/logs/ostruct.log`: General application logs
|
124
|
+
- `~/.ostruct/logs/openai_stream.log`: OpenAI streaming operations logs
|
125
|
+
|
126
|
+
For more detailed documentation and examples, visit our [documentation](https://ostruct-cli.readthedocs.io/).
|
127
|
+
|
128
|
+
## Development
|
129
|
+
|
130
|
+
To contribute or report issues, please visit our [GitHub repository](https://github.com/yaniv-golan/ostruct).
|
131
|
+
|
132
|
+
## Development Setup
|
133
|
+
|
134
|
+
1. Clone the repository:
|
135
|
+
|
136
|
+
```bash
|
137
|
+
git clone https://github.com/yanivgolan/ostruct.git
|
138
|
+
cd ostruct
|
139
|
+
```
|
140
|
+
|
141
|
+
2. Install Poetry if you haven't already:
|
142
|
+
|
143
|
+
```bash
|
144
|
+
curl -sSL https://install.python-poetry.org | python3 -
|
145
|
+
```
|
146
|
+
|
147
|
+
3. Install dependencies:
|
148
|
+
|
149
|
+
```bash
|
150
|
+
poetry install
|
151
|
+
```
|
152
|
+
|
153
|
+
4. Install openai-structured in editable mode:
|
154
|
+
|
155
|
+
```bash
|
156
|
+
poetry add --editable ../openai-structured # Adjust path as needed
|
157
|
+
```
|
158
|
+
|
159
|
+
5. Run tests:
|
160
|
+
|
161
|
+
```bash
|
162
|
+
poetry run pytest
|
163
|
+
```
|
164
|
+
|
165
|
+
## Contributing
|
166
|
+
|
167
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
168
|
+
|
169
|
+
## License
|
170
|
+
|
171
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
172
|
+
|
173
|
+
## Migration from openai-structured
|
174
|
+
|
175
|
+
If you were previously using the CLI bundled with openai-structured (pre-1.0.0), this is its new home. The migration is straightforward:
|
176
|
+
|
177
|
+
1. Update openai-structured to version 1.0.0 or later
|
178
|
+
2. Install ostruct-cli
|
179
|
+
3. Replace any `openai-structured` CLI commands with `ostruct`
|
180
|
+
|
181
|
+
The functionality remains the same, just moved to a dedicated package for better maintenance and focus.
|
182
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
ostruct/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
ostruct/cli/__init__.py,sha256=dbdUfKRT4ARSHgjsZOmQ-TJT1mHwL7L3xMuilPkhG4Q,411
|
3
|
+
ostruct/cli/cache_manager.py,sha256=ej3KrRfkKKZ_lEp2JswjbJ5bW2ncsvna9NeJu81cqqs,5192
|
4
|
+
ostruct/cli/cli.py,sha256=GC1YHGlD7PxX4duWgfmLijTmMBg2tVqG9JOIHqmipxk,69662
|
5
|
+
ostruct/cli/errors.py,sha256=vxfjXpUbsarYJoTBaGFpjpa8wXqOMGQryTh-roUhRuU,9454
|
6
|
+
ostruct/cli/file_info.py,sha256=jjsLVDD8YMpVryBzKVdoQsjE33PLA1BBTVqH3VOHbuA,10167
|
7
|
+
ostruct/cli/file_list.py,sha256=jTtqNo05GT4m4TpEpd3MT9ZlueH_sQgcjHiERRbt-IY,5217
|
8
|
+
ostruct/cli/file_utils.py,sha256=NLbYIum2vB3SOPrG5hsE4Djg5WeStRppIX2v7L1Y9Dg,17404
|
9
|
+
ostruct/cli/path_utils.py,sha256=jhJsvmxsq0_FU5cWwB-JoEymGbvB2JX9Q0a-dUf0s1w,4461
|
10
|
+
ostruct/cli/progress.py,sha256=rj9nVEco5UeZORMbzd7mFJpFGJjbH9KbBFh5oTE5Anw,3415
|
11
|
+
ostruct/cli/security.py,sha256=8X3eiK9XN1Fcw6TQ5hxfEb-Dt0vF21vdoXpxr5p-Aos,10332
|
12
|
+
ostruct/cli/security_types.py,sha256=oSNbaKjhZVHB6pQEG_WOUhUYKlw9cl4uGOBx2R9BxRk,1341
|
13
|
+
ostruct/cli/template_env.py,sha256=S2ZvxuMQMicodSVqUhrw0kOzbNmlpQjSHtWlOwjXCms,1538
|
14
|
+
ostruct/cli/template_extensions.py,sha256=jGj8nKKyWOaN4u271N9luDNZAZ60xGu17qalf9ybibc,1645
|
15
|
+
ostruct/cli/template_filters.py,sha256=SNp7PR4ZbuC9BVUlEgwzd6VZYjI0lsobTabLiJe_sZM,19030
|
16
|
+
ostruct/cli/template_io.py,sha256=6rDw2Wx6czK1VntKGUM6cvyMbMWojt41hUlYRpfQuoc,8749
|
17
|
+
ostruct/cli/template_rendering.py,sha256=JcxwVppl2Q6dNsH_pAv4hW3LH2if76cvgwrh-VNPpL8,12769
|
18
|
+
ostruct/cli/template_schema.py,sha256=ckH4rUZnEgfm_BHS9LnMGr8LtDxRmZ0C6UBVrSp8KTc,19604
|
19
|
+
ostruct/cli/template_utils.py,sha256=QGgewxU_Tgn81J5U-Y4xfi67CkN2dEqXI7PsaNiI9es,7812
|
20
|
+
ostruct/cli/template_validation.py,sha256=ygM_37Cqd2RfOugf9PmhS-Z3WFwDvjPhduB7-C2LMfw,11759
|
21
|
+
ostruct/cli/utils.py,sha256=1UCl4rHjBWKR5EKugvlVGHiHjO3XXmqvkgeAUSyIPDU,831
|
22
|
+
ostruct/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
|
+
ostruct_cli-0.1.0.dist-info/LICENSE,sha256=QUOY6QCYVxAiH8vdrUTDqe3i9hQ5bcNczppDSVpLTjk,1068
|
24
|
+
ostruct_cli-0.1.0.dist-info/METADATA,sha256=mjUKxVR_dV0JIsNR988ppA5JrhQn6J-j44rX6rbnXiw,5236
|
25
|
+
ostruct_cli-0.1.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
26
|
+
ostruct_cli-0.1.0.dist-info/entry_points.txt,sha256=NFq9IuqHVTem0j9zKjV8C1si_zGcP1RL6Wbvt9fUDXw,48
|
27
|
+
ostruct_cli-0.1.0.dist-info/RECORD,,
|