ostruct-cli 0.6.1__tar.gz → 0.7.0__tar.gz
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_cli-0.6.1 → ostruct_cli-0.7.0}/PKG-INFO +71 -165
- ostruct_cli-0.7.0/README.md +282 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/pyproject.toml +2 -2
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/__init__.py +2 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/cli.py +200 -73
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/errors.py +61 -54
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/model_creation.py +67 -94
- ostruct_cli-0.7.0/src/ostruct/cli/registry_updates.py +162 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/errors.py +1 -1
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/normalization.py +1 -1
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/security_manager.py +48 -7
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/template_extensions.py +32 -1
- ostruct_cli-0.7.0/src/ostruct/cli/template_utils.py +455 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/utils.py +3 -1
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/validators.py +6 -2
- ostruct_cli-0.6.1/README.md +0 -376
- ostruct_cli-0.6.1/src/ostruct/cli/template_utils.py +0 -296
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/LICENSE +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/__init__.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/base_errors.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/cache_manager.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/click_options.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/exit_codes.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/file_info.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/file_list.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/file_utils.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/path_utils.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/progress.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/schema_validation.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/__init__.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/allowed_checker.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/base.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/case_manager.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/safe_joiner.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/symlink_resolver.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/types.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/security/windows_paths.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/serialization.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/template_env.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/template_filters.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/template_io.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/template_rendering.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/template_schema.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/template_validation.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/cli/token_utils.py +0 -0
- {ostruct_cli-0.6.1 → ostruct_cli-0.7.0}/src/ostruct/py.typed +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: ostruct-cli
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.7.0
|
4
4
|
Summary: CLI for OpenAI Structured Output
|
5
5
|
Author: Yaniv Golan
|
6
6
|
Author-email: yaniv@golan.name
|
@@ -16,7 +16,7 @@ Requires-Dist: click (>=8.1.7,<9.0.0)
|
|
16
16
|
Requires-Dist: ijson (>=3.2.3,<4.0.0)
|
17
17
|
Requires-Dist: jsonschema (>=4.23.0,<5.0.0)
|
18
18
|
Requires-Dist: openai (>=1.0.0,<2.0.0)
|
19
|
-
Requires-Dist: openai-structured (>=2.
|
19
|
+
Requires-Dist: openai-structured (>=2.1.0,<3.0.0)
|
20
20
|
Requires-Dist: pydantic (>=2.6.3,<3.0.0)
|
21
21
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
22
22
|
Requires-Dist: tiktoken (==0.9.0)
|
@@ -33,7 +33,9 @@ Description-Content-Type: text/markdown
|
|
33
33
|
[](https://github.com/yaniv-golan/ostruct/actions/workflows/ci.yml)
|
34
34
|
[](https://opensource.org/licenses/MIT)
|
35
35
|
|
36
|
-
|
36
|
+
ostruct tranforms unstructured inputs into structured, usable JSON output using OpenAI APIs.
|
37
|
+
|
38
|
+
ostruct will process a set of plain text files (data, source code, CSV, etc), input variables, a dynamic prompt template, and a JSON schema specifying the desired output format, and will produce the result in JSON format.
|
37
39
|
|
38
40
|
## Features
|
39
41
|
|
@@ -42,6 +44,12 @@ Command-line interface for working with OpenAI models and structured output, pow
|
|
42
44
|
- Automatic token counting and context window management
|
43
45
|
- Streaming support for real-time output
|
44
46
|
- Secure handling of sensitive data
|
47
|
+
- Model registry management with support for updating to the latest OpenAI models
|
48
|
+
- Non-intrusive registry update checks with user notifications
|
49
|
+
|
50
|
+
## Requirements
|
51
|
+
|
52
|
+
- Python 3.10 or higher
|
45
53
|
|
46
54
|
## Installation
|
47
55
|
|
@@ -57,6 +65,16 @@ pip install ostruct-cli
|
|
57
65
|
|
58
66
|
If you plan to contribute to the project, see the [Development Setup](#development-setup) section below for instructions on setting up the development environment with Poetry.
|
59
67
|
|
68
|
+
## Environment Variables
|
69
|
+
|
70
|
+
ostruct-cli respects the following environment variables:
|
71
|
+
|
72
|
+
- `OPENAI_API_KEY`: Your OpenAI API key (required unless provided via command line)
|
73
|
+
- `OPENAI_API_BASE`: Custom API base URL (optional)
|
74
|
+
- `OPENAI_API_VERSION`: API version to use (optional)
|
75
|
+
- `OPENAI_API_TYPE`: API type (e.g., "azure") (optional)
|
76
|
+
- `OSTRUCT_DISABLE_UPDATE_CHECKS`: Set to "1", "true", or "yes" to disable automatic registry update checks
|
77
|
+
|
60
78
|
## Shell Completion
|
61
79
|
|
62
80
|
ostruct-cli supports shell completion for Bash, Zsh, and Fish shells. To enable it:
|
@@ -209,196 +227,84 @@ The command will output:
|
|
209
227
|
}
|
210
228
|
```
|
211
229
|
|
212
|
-
|
230
|
+
## System Prompt Handling
|
213
231
|
|
214
|
-
|
232
|
+
ostruct-cli provides three ways to specify a system prompt, with a clear precedence order:
|
215
233
|
|
216
|
-
|
217
|
-
Extract information about the people from this data:
|
234
|
+
1. Command-line option (`--sys-prompt` or `--sys-file`):
|
218
235
|
|
219
|
-
|
220
|
-
|
236
|
+
```bash
|
237
|
+
# Direct string
|
238
|
+
ostruct run template.j2 schema.json --sys-prompt "You are an expert analyst"
|
221
239
|
|
222
|
-
|
240
|
+
# From file
|
241
|
+
ostruct run template.j2 schema.json --sys-file system_prompt.txt
|
242
|
+
```
|
223
243
|
|
224
|
-
|
225
|
-
```
|
244
|
+
2. Template frontmatter:
|
226
245
|
|
227
|
-
|
246
|
+
```jinja
|
247
|
+
---
|
248
|
+
system_prompt: You are an expert analyst
|
249
|
+
---
|
250
|
+
Extract information from: {{ text }}
|
251
|
+
```
|
228
252
|
|
229
|
-
|
230
|
-
{
|
231
|
-
"type": "object",
|
232
|
-
"properties": {
|
233
|
-
"people": {
|
234
|
-
"type": "array",
|
235
|
-
"items": {
|
236
|
-
"type": "object",
|
237
|
-
"properties": {
|
238
|
-
"name": {
|
239
|
-
"type": "string",
|
240
|
-
"description": "The person's full name"
|
241
|
-
},
|
242
|
-
"age": {
|
243
|
-
"type": "integer",
|
244
|
-
"description": "The person's age"
|
245
|
-
},
|
246
|
-
"occupation": {
|
247
|
-
"type": "string",
|
248
|
-
"description": "The person's job or profession"
|
249
|
-
}
|
250
|
-
},
|
251
|
-
"required": ["name", "age", "occupation"],
|
252
|
-
"additionalProperties": false
|
253
|
-
}
|
254
|
-
}
|
255
|
-
},
|
256
|
-
"required": ["people"],
|
257
|
-
"additionalProperties": false
|
258
|
-
}
|
259
|
-
```
|
253
|
+
3. Default system prompt (built into the CLI)
|
260
254
|
|
261
|
-
|
255
|
+
### Precedence Rules
|
262
256
|
|
263
|
-
|
264
|
-
# Basic usage
|
265
|
-
ostruct run extract_from_profiles.j2 schema.json -p profiles "profiles/*.txt"
|
257
|
+
When multiple system prompts are provided, they are resolved in this order:
|
266
258
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
--model gpt-4o \
|
271
|
-
--sys-prompt "Extract precise information about the person" \
|
272
|
-
--temperature 0.5
|
273
|
-
```
|
259
|
+
1. Command-line options take highest precedence:
|
260
|
+
- If both `--sys-prompt` and `--sys-file` are provided, `--sys-prompt` wins
|
261
|
+
- Use `--ignore-task-sysprompt` to ignore template frontmatter
|
274
262
|
|
275
|
-
|
263
|
+
2. Template frontmatter is used if:
|
264
|
+
- No command-line options are provided
|
265
|
+
- `--ignore-task-sysprompt` is not set
|
276
266
|
|
277
|
-
|
278
|
-
{
|
279
|
-
"people": [
|
280
|
-
{
|
281
|
-
"name": "John Smith",
|
282
|
-
"age": 35,
|
283
|
-
"occupation": "software engineer"
|
284
|
-
},
|
285
|
-
{
|
286
|
-
"name": "Jane Doe",
|
287
|
-
"age": 28,
|
288
|
-
"occupation": "data scientist"
|
289
|
-
}
|
290
|
-
]
|
291
|
-
}
|
292
|
-
```
|
293
|
-
|
294
|
-
### About Template Files
|
295
|
-
|
296
|
-
Template files use the `.j2` extension to indicate they contain Jinja2 template syntax. This convention:
|
297
|
-
|
298
|
-
- Enables proper syntax highlighting in most editors
|
299
|
-
- Makes it clear the file contains template logic
|
300
|
-
- Follows industry standards for Jinja2 templates
|
267
|
+
3. Default system prompt is used only if no other prompts are provided
|
301
268
|
|
302
|
-
|
303
|
-
|
304
|
-
The CLI revolves around a single subcommand called `run`. Basic usage:
|
269
|
+
Example combining multiple sources:
|
305
270
|
|
306
271
|
```bash
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
Common options include:
|
311
|
-
|
312
|
-
- File & Directory Inputs:
|
313
|
-
- `-f <NAME> <PATH>`: Map a single file to a variable name
|
314
|
-
- `-d <NAME> <DIR>`: Map a directory to a variable name
|
315
|
-
- `-p <NAME> <PATTERN>`: Map files matching a glob pattern to a variable name
|
316
|
-
- `-R, --recursive`: Enable recursive directory/pattern scanning
|
317
|
-
|
318
|
-
- Variables:
|
319
|
-
- `-V name=value`: Define a simple string variable
|
320
|
-
- `-J name='{"key":"value"}'`: Define a JSON variable
|
321
|
-
|
322
|
-
- Model Parameters:
|
323
|
-
- `-m, --model MODEL`: Select the OpenAI model (supported: gpt-4o, o1, o3-mini)
|
324
|
-
- `--temperature FLOAT`: Set sampling temperature (0.0-2.0)
|
325
|
-
- `--max-output-tokens INT`: Set maximum output tokens
|
326
|
-
- `--top-p FLOAT`: Set top-p sampling parameter (0.0-1.0)
|
327
|
-
- `--frequency-penalty FLOAT`: Adjust frequency penalty (-2.0-2.0)
|
328
|
-
- `--presence-penalty FLOAT`: Adjust presence penalty (-2.0-2.0)
|
329
|
-
- `--reasoning-effort [low|medium|high]`: Control model reasoning effort
|
330
|
-
|
331
|
-
- System Prompt:
|
332
|
-
- `--sys-prompt TEXT`: Provide system prompt directly
|
333
|
-
- `--sys-file FILE`: Load system prompt from file
|
334
|
-
- `--ignore-task-sysprompt`: Ignore system prompt in template frontmatter
|
335
|
-
|
336
|
-
- API Configuration:
|
337
|
-
- `--api-key KEY`: OpenAI API key (defaults to OPENAI_API_KEY env var)
|
338
|
-
- `--timeout FLOAT`: API timeout in seconds (default: 60.0)
|
339
|
-
|
340
|
-
## Debug Options
|
341
|
-
|
342
|
-
- `--debug-validation`: Show detailed schema validation debugging
|
343
|
-
- `--debug-openai-stream`: Enable low-level debug output for OpenAI streaming
|
344
|
-
- `--progress-level {none,basic,detailed}`: Set progress reporting level
|
345
|
-
- `none`: No progress indicators
|
346
|
-
- `basic`: Show key operation steps (default)
|
347
|
-
- `detailed`: Show all steps with additional info
|
348
|
-
- `--show-model-schema`: Display the generated Pydantic model schema
|
349
|
-
- `--verbose`: Enable verbose logging
|
350
|
-
- `--dry-run`: Validate and render template without making API calls
|
351
|
-
- `--no-progress`: Disable all progress indicators
|
352
|
-
|
353
|
-
All debug and error logs are written to:
|
272
|
+
# Command-line prompt will override template frontmatter
|
273
|
+
ostruct run template.j2 schema.json --sys-prompt "Override prompt"
|
354
274
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
For more detailed documentation and examples, visit our [documentation](https://ostruct.readthedocs.io/).
|
359
|
-
|
360
|
-
## Development
|
361
|
-
|
362
|
-
To contribute or report issues, please visit our [GitHub repository](https://github.com/yaniv-golan/ostruct).
|
363
|
-
|
364
|
-
## Development Setup
|
365
|
-
|
366
|
-
1. Clone the repository:
|
367
|
-
|
368
|
-
```bash
|
369
|
-
git clone https://github.com/yanivgolan/ostruct.git
|
370
|
-
cd ostruct
|
275
|
+
# Ignore template frontmatter and use default
|
276
|
+
ostruct run template.j2 schema.json --ignore-task-sysprompt
|
371
277
|
```
|
372
278
|
|
373
|
-
|
279
|
+
## Model Registry Management
|
374
280
|
|
375
|
-
|
376
|
-
curl -sSL https://install.python-poetry.org | python3 -
|
377
|
-
```
|
281
|
+
ostruct-cli maintains a registry of OpenAI models and their capabilities, which includes:
|
378
282
|
|
379
|
-
|
283
|
+
- Context window sizes for each model
|
284
|
+
- Maximum output token limits
|
285
|
+
- Supported parameters and their constraints
|
286
|
+
- Model version information
|
380
287
|
|
381
|
-
|
382
|
-
poetry install
|
383
|
-
```
|
384
|
-
|
385
|
-
4. Install openai-structured in editable mode:
|
288
|
+
To ensure you're using the latest models and features, you can update the registry:
|
386
289
|
|
387
290
|
```bash
|
388
|
-
|
389
|
-
|
291
|
+
# Update from the official repository
|
292
|
+
ostruct update-registry
|
390
293
|
|
391
|
-
|
294
|
+
# Update from a custom URL
|
295
|
+
ostruct update-registry --url https://example.com/models.yml
|
392
296
|
|
393
|
-
|
394
|
-
|
297
|
+
# Force an update even if the registry is current
|
298
|
+
ostruct update-registry --force
|
395
299
|
```
|
396
300
|
|
397
|
-
|
301
|
+
This is especially useful when:
|
398
302
|
|
399
|
-
|
303
|
+
- New OpenAI models are released
|
304
|
+
- Model capabilities or parameters change
|
305
|
+
- You need to work with custom model configurations
|
400
306
|
|
401
|
-
|
307
|
+
The registry file is stored at `~/.openai_structured/config/models.yml` and is automatically referenced when validating model parameters and token limits.
|
402
308
|
|
403
|
-
|
309
|
+
The update command uses HTTP conditional requests (If-Modified-Since headers) to check if the remote registry has changed before downloading, ensuring efficient updates.
|
404
310
|
|
@@ -0,0 +1,282 @@
|
|
1
|
+
# ostruct-cli
|
2
|
+
|
3
|
+
[](https://badge.fury.io/py/ostruct-cli)
|
4
|
+
[](https://pypi.org/project/ostruct-cli)
|
5
|
+
[](https://ostruct.readthedocs.io/en/latest/?badge=latest)
|
6
|
+
[](https://github.com/yaniv-golan/ostruct/actions/workflows/ci.yml)
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
8
|
+
|
9
|
+
ostruct tranforms unstructured inputs into structured, usable JSON output using OpenAI APIs.
|
10
|
+
|
11
|
+
ostruct will process a set of plain text files (data, source code, CSV, etc), input variables, a dynamic prompt template, and a JSON schema specifying the desired output format, and will produce the result in JSON format.
|
12
|
+
|
13
|
+
## Features
|
14
|
+
|
15
|
+
- Generate structured JSON output from natural language using OpenAI models and a JSON schema
|
16
|
+
- Rich template system for defining prompts (Jinja2-based)
|
17
|
+
- Automatic token counting and context window management
|
18
|
+
- Streaming support for real-time output
|
19
|
+
- Secure handling of sensitive data
|
20
|
+
- Model registry management with support for updating to the latest OpenAI models
|
21
|
+
- Non-intrusive registry update checks with user notifications
|
22
|
+
|
23
|
+
## Requirements
|
24
|
+
|
25
|
+
- Python 3.10 or higher
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
### For Users
|
30
|
+
|
31
|
+
To install the latest stable version from PyPI:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
pip install ostruct-cli
|
35
|
+
```
|
36
|
+
|
37
|
+
### For Developers
|
38
|
+
|
39
|
+
If you plan to contribute to the project, see the [Development Setup](#development-setup) section below for instructions on setting up the development environment with Poetry.
|
40
|
+
|
41
|
+
## Environment Variables
|
42
|
+
|
43
|
+
ostruct-cli respects the following environment variables:
|
44
|
+
|
45
|
+
- `OPENAI_API_KEY`: Your OpenAI API key (required unless provided via command line)
|
46
|
+
- `OPENAI_API_BASE`: Custom API base URL (optional)
|
47
|
+
- `OPENAI_API_VERSION`: API version to use (optional)
|
48
|
+
- `OPENAI_API_TYPE`: API type (e.g., "azure") (optional)
|
49
|
+
- `OSTRUCT_DISABLE_UPDATE_CHECKS`: Set to "1", "true", or "yes" to disable automatic registry update checks
|
50
|
+
|
51
|
+
## Shell Completion
|
52
|
+
|
53
|
+
ostruct-cli supports shell completion for Bash, Zsh, and Fish shells. To enable it:
|
54
|
+
|
55
|
+
### Bash
|
56
|
+
|
57
|
+
Add this to your `~/.bashrc`:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
eval "$(_OSTRUCT_COMPLETE=bash_source ostruct)"
|
61
|
+
```
|
62
|
+
|
63
|
+
### Zsh
|
64
|
+
|
65
|
+
Add this to your `~/.zshrc`:
|
66
|
+
|
67
|
+
```bash
|
68
|
+
eval "$(_OSTRUCT_COMPLETE=zsh_source ostruct)"
|
69
|
+
```
|
70
|
+
|
71
|
+
### Fish
|
72
|
+
|
73
|
+
Add this to your `~/.config/fish/completions/ostruct.fish`:
|
74
|
+
|
75
|
+
```fish
|
76
|
+
eval (env _OSTRUCT_COMPLETE=fish_source ostruct)
|
77
|
+
```
|
78
|
+
|
79
|
+
After adding the appropriate line, restart your shell or source the configuration file.
|
80
|
+
Shell completion will help you with:
|
81
|
+
|
82
|
+
- Command options and their arguments
|
83
|
+
- File paths for template and schema files
|
84
|
+
- Directory paths for `-d` and `--base-dir` options
|
85
|
+
- And more!
|
86
|
+
|
87
|
+
## Quick Start
|
88
|
+
|
89
|
+
1. Set your OpenAI API key:
|
90
|
+
|
91
|
+
```bash
|
92
|
+
export OPENAI_API_KEY=your-api-key
|
93
|
+
```
|
94
|
+
|
95
|
+
### Example 1: Using stdin (Simplest)
|
96
|
+
|
97
|
+
1. Create a template file `extract_person.j2`:
|
98
|
+
|
99
|
+
```jinja
|
100
|
+
Extract information about the person from this text: {{ stdin }}
|
101
|
+
```
|
102
|
+
|
103
|
+
2. Create a schema file `schema.json`:
|
104
|
+
|
105
|
+
```json
|
106
|
+
{
|
107
|
+
"type": "object",
|
108
|
+
"properties": {
|
109
|
+
"person": {
|
110
|
+
"type": "object",
|
111
|
+
"properties": {
|
112
|
+
"name": {
|
113
|
+
"type": "string",
|
114
|
+
"description": "The person's full name"
|
115
|
+
},
|
116
|
+
"age": {
|
117
|
+
"type": "integer",
|
118
|
+
"description": "The person's age"
|
119
|
+
},
|
120
|
+
"occupation": {
|
121
|
+
"type": "string",
|
122
|
+
"description": "The person's job or profession"
|
123
|
+
}
|
124
|
+
},
|
125
|
+
"required": ["name", "age", "occupation"],
|
126
|
+
"additionalProperties": false
|
127
|
+
}
|
128
|
+
},
|
129
|
+
"required": ["person"],
|
130
|
+
"additionalProperties": false
|
131
|
+
}
|
132
|
+
```
|
133
|
+
|
134
|
+
3. Run the CLI:
|
135
|
+
|
136
|
+
```bash
|
137
|
+
# Basic usage
|
138
|
+
echo "John Smith is a 35-year-old software engineer" | ostruct run extract_person.j2 schema.json
|
139
|
+
|
140
|
+
# For longer text using heredoc
|
141
|
+
cat << EOF | ostruct run extract_person.j2 schema.json
|
142
|
+
John Smith is a 35-year-old software engineer
|
143
|
+
working at Tech Corp. He has been programming
|
144
|
+
for over 10 years.
|
145
|
+
EOF
|
146
|
+
|
147
|
+
# With advanced options
|
148
|
+
echo "John Smith is a 35-year-old software engineer" | \
|
149
|
+
ostruct run extract_person.j2 schema.json \
|
150
|
+
--model gpt-4o \
|
151
|
+
--sys-prompt "Extract precise information about the person" \
|
152
|
+
--temperature 0.7
|
153
|
+
```
|
154
|
+
|
155
|
+
The command will output:
|
156
|
+
|
157
|
+
```json
|
158
|
+
{
|
159
|
+
"person": {
|
160
|
+
"name": "John Smith",
|
161
|
+
"age": 35,
|
162
|
+
"occupation": "software engineer"
|
163
|
+
}
|
164
|
+
}
|
165
|
+
```
|
166
|
+
|
167
|
+
### Example 2: Processing a Single File
|
168
|
+
|
169
|
+
1. Create a template file `extract_from_file.j2`:
|
170
|
+
|
171
|
+
```jinja
|
172
|
+
Extract information about the person from this text: {{ text.content }}
|
173
|
+
```
|
174
|
+
|
175
|
+
2. Use the same schema file `schema.json` as above.
|
176
|
+
|
177
|
+
3. Run the CLI:
|
178
|
+
|
179
|
+
```bash
|
180
|
+
# Basic usage
|
181
|
+
ostruct run extract_from_file.j2 schema.json -f text input.txt
|
182
|
+
|
183
|
+
# With advanced options
|
184
|
+
ostruct run extract_from_file.j2 schema.json \
|
185
|
+
-f text input.txt \
|
186
|
+
--model gpt-4o \
|
187
|
+
--max-output-tokens 1000 \
|
188
|
+
--temperature 0.7
|
189
|
+
```
|
190
|
+
|
191
|
+
The command will output:
|
192
|
+
|
193
|
+
```json
|
194
|
+
{
|
195
|
+
"person": {
|
196
|
+
"name": "John Smith",
|
197
|
+
"age": 35,
|
198
|
+
"occupation": "software engineer"
|
199
|
+
}
|
200
|
+
}
|
201
|
+
```
|
202
|
+
|
203
|
+
## System Prompt Handling
|
204
|
+
|
205
|
+
ostruct-cli provides three ways to specify a system prompt, with a clear precedence order:
|
206
|
+
|
207
|
+
1. Command-line option (`--sys-prompt` or `--sys-file`):
|
208
|
+
|
209
|
+
```bash
|
210
|
+
# Direct string
|
211
|
+
ostruct run template.j2 schema.json --sys-prompt "You are an expert analyst"
|
212
|
+
|
213
|
+
# From file
|
214
|
+
ostruct run template.j2 schema.json --sys-file system_prompt.txt
|
215
|
+
```
|
216
|
+
|
217
|
+
2. Template frontmatter:
|
218
|
+
|
219
|
+
```jinja
|
220
|
+
---
|
221
|
+
system_prompt: You are an expert analyst
|
222
|
+
---
|
223
|
+
Extract information from: {{ text }}
|
224
|
+
```
|
225
|
+
|
226
|
+
3. Default system prompt (built into the CLI)
|
227
|
+
|
228
|
+
### Precedence Rules
|
229
|
+
|
230
|
+
When multiple system prompts are provided, they are resolved in this order:
|
231
|
+
|
232
|
+
1. Command-line options take highest precedence:
|
233
|
+
- If both `--sys-prompt` and `--sys-file` are provided, `--sys-prompt` wins
|
234
|
+
- Use `--ignore-task-sysprompt` to ignore template frontmatter
|
235
|
+
|
236
|
+
2. Template frontmatter is used if:
|
237
|
+
- No command-line options are provided
|
238
|
+
- `--ignore-task-sysprompt` is not set
|
239
|
+
|
240
|
+
3. Default system prompt is used only if no other prompts are provided
|
241
|
+
|
242
|
+
Example combining multiple sources:
|
243
|
+
|
244
|
+
```bash
|
245
|
+
# Command-line prompt will override template frontmatter
|
246
|
+
ostruct run template.j2 schema.json --sys-prompt "Override prompt"
|
247
|
+
|
248
|
+
# Ignore template frontmatter and use default
|
249
|
+
ostruct run template.j2 schema.json --ignore-task-sysprompt
|
250
|
+
```
|
251
|
+
|
252
|
+
## Model Registry Management
|
253
|
+
|
254
|
+
ostruct-cli maintains a registry of OpenAI models and their capabilities, which includes:
|
255
|
+
|
256
|
+
- Context window sizes for each model
|
257
|
+
- Maximum output token limits
|
258
|
+
- Supported parameters and their constraints
|
259
|
+
- Model version information
|
260
|
+
|
261
|
+
To ensure you're using the latest models and features, you can update the registry:
|
262
|
+
|
263
|
+
```bash
|
264
|
+
# Update from the official repository
|
265
|
+
ostruct update-registry
|
266
|
+
|
267
|
+
# Update from a custom URL
|
268
|
+
ostruct update-registry --url https://example.com/models.yml
|
269
|
+
|
270
|
+
# Force an update even if the registry is current
|
271
|
+
ostruct update-registry --force
|
272
|
+
```
|
273
|
+
|
274
|
+
This is especially useful when:
|
275
|
+
|
276
|
+
- New OpenAI models are released
|
277
|
+
- Model capabilities or parameters change
|
278
|
+
- You need to work with custom model configurations
|
279
|
+
|
280
|
+
The registry file is stored at `~/.openai_structured/config/models.yml` and is automatically referenced when validating model parameters and token limits.
|
281
|
+
|
282
|
+
The update command uses HTTP conditional requests (If-Modified-Since headers) to check if the remote registry has changed before downloading, ensuring efficient updates.
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
[tool.poetry]
|
6
6
|
name = "ostruct-cli"
|
7
|
-
version = "0.
|
7
|
+
version = "0.7.0"
|
8
8
|
description = "CLI for OpenAI Structured Output"
|
9
9
|
authors = ["Yaniv Golan <yaniv@golan.name>"]
|
10
10
|
readme = "README.md"
|
@@ -24,7 +24,7 @@
|
|
24
24
|
click = "^8.1.7"
|
25
25
|
werkzeug = "^3.1.3"
|
26
26
|
openai = "^1.0.0"
|
27
|
-
openai-structured = "^2.
|
27
|
+
openai-structured = "^2.1.0"
|
28
28
|
tiktoken = "0.9.0"
|
29
29
|
|
30
30
|
[tool.poetry.scripts]
|
@@ -8,6 +8,7 @@ from .cli import (
|
|
8
8
|
validate_variable_mapping,
|
9
9
|
)
|
10
10
|
from .path_utils import validate_path_mapping
|
11
|
+
from .registry_updates import get_update_notification
|
11
12
|
|
12
13
|
__all__ = [
|
13
14
|
"ExitCode",
|
@@ -16,4 +17,5 @@ __all__ = [
|
|
16
17
|
"validate_schema_file",
|
17
18
|
"validate_task_template",
|
18
19
|
"validate_variable_mapping",
|
20
|
+
"get_update_notification",
|
19
21
|
]
|