|
23 | 23 | json_schema_format, |
24 | 24 | ) |
25 | 25 |
|
26 | | -from ._common import get_client |
| 26 | +from ._common import get_client, write_output |
27 | 27 |
|
28 | 28 | console = Console() |
29 | 29 | is_interactive = sys.stdout.isatty() |
@@ -76,8 +76,7 @@ def extract(url, output, fmt, api): |
76 | 76 | output_str = f"Title: {title}\n\nURL: {url}\n\nContent: {content}" |
77 | 77 |
|
78 | 78 | if output: |
79 | | - with open(output, "w") as f: |
80 | | - f.write(output_str) |
| 79 | + write_output(output, output_str) |
81 | 80 | click.echo(f"Output written to {output}") |
82 | 81 | else: |
83 | 82 | print_markdown(output_str) |
@@ -170,8 +169,7 @@ def ask(prompt: str, output: Optional[str] = None, as_json: bool = False, schema |
170 | 169 | else: |
171 | 170 | for chunk in db.ask(messages): |
172 | 171 | response += chunk |
173 | | - with open(output, "w") as f: |
174 | | - f.write(response) |
| 172 | + write_output(output, response) |
175 | 173 | click.echo(f"Output written to {output}") |
176 | 174 | elif as_json: |
177 | 175 | sys.stdout.write( |
@@ -258,8 +256,7 @@ def crawl(site, hops, job_name, max_to_crawl, max_to_process, restrict_domain, |
258 | 256 | output_str = "\n".join(lines) |
259 | 257 |
|
260 | 258 | if output: |
261 | | - with open(output, "w") as f: |
262 | | - f.write(output_str) |
| 259 | + write_output(output, output_str) |
263 | 260 | click.echo(f"Output written to {output}") |
264 | 261 | else: |
265 | 262 | print_markdown(output_str) |
|
0 commit comments