Skip to content

Commit

Permalink
Enable a no-user-input mode for automation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhogg committed Jan 31, 2024
1 parent 2a62fea commit 742c9f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ run:
# Executes the given command inside the virtualenv
poetry run gptauthor --story openai-drama --total-chapters 3 --llm-model gpt-3.5-turbo --llm-temperature 0.1 --llm-top-p 1.0

run-no-allow-user-input:
# Executes the given command inside the virtualenv
poetry run gptauthor --story openai-drama --total-chapters 3 --llm-model gpt-3.5-turbo --llm-temperature 0.1 --llm-top-p 1.0 --no-allow-user-input

build:
# Build the source and wheels archives
poetry build
Expand Down
2 changes: 2 additions & 0 deletions gptauthor/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def run(
int, typer.Option(help="LLM use localhost:8081 instead of openai")
] = consts.default_llm_use_localhost,
total_chapters: Annotated[int, typer.Option(help="Total chapters to write")] = consts.default_write_total_chapters,
allow_user_input: Annotated[bool, typer.Option(help="Allow command line user input")] = True,
version: Annotated[
Optional[bool],
typer.Option("--version", help=f"Display {consts.package_name} version", callback=version_callback),
Expand Down Expand Up @@ -66,6 +67,7 @@ def run(
"localhost_sleep": int(env.get("LLM_USE_LOCALHOST_SLEEP", 0)),
"default_output_folder": consts.default_output_folder,
"story_file": story_file,
"allow_user_input": allow_user_input,
}
)

Expand Down
27 changes: 16 additions & 11 deletions gptauthor/library/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def user_input_continue_processing(synopsis_response_user_edited_filename):

def do_writing(llm_config):
start = time.time()
p(f"Start {consts.package_name} {consts.version}, {llm_config.total_chapters=}, {llm_config.story_file=}...")
p(
f"Start {consts.package_name} {consts.version}, {llm_config.total_chapters=}, {llm_config.story_file=}, {llm_config.allow_user_input=}..."
)

# ------------------------------------------------------------------------------
# Create synopsis
Expand Down Expand Up @@ -111,7 +113,9 @@ def do_writing(llm_config):
# ------------------------------------------------------------------------------
# User input to continue or quit
# ------------------------------------------------------------------------------
if not user_input_continue_processing(str(output_folder / synopsis_response_user_edited_filename)):
if llm_config.allow_user_input and not user_input_continue_processing(
str(output_folder / synopsis_response_user_edited_filename)
):
with open(output_folder / "__aborted.txt", "w") as f:
f.write(f"Aborted writing book: {synopsis_title}.\n\n")
f.write(str(safe_llm_config))
Expand Down Expand Up @@ -242,12 +246,13 @@ def do_writing(llm_config):
f"\n{took=:.2f}s, {total_process_tokens=:,}, ${rough_gpt4_8k_price_estimate=:.2f}, ${rough_gpt35_4k_price_estimate=:.2f}"
)

while True:
user_input = input("Press 'Y' to open the html book in a browser, or Enter/Return to finish: ")
if user_input.lower() == "y":
abs_file = (output_folder / "_whole_book.html").resolve()
webbrowser.open(f"file://{abs_file}")
elif user_input.lower() == "":
return
else:
print("Invalid input. Please try again.")
if llm_config.allow_user_input:
while True:
user_input = input("Press 'Y' to open the html book in a browser, or Enter/Return to finish: ")
if user_input.lower() == "y":
abs_file = (output_folder / "_whole_book.html").resolve()
webbrowser.open(f"file://{abs_file}")
elif user_input.lower() == "":
return
else:
print("Invalid input. Please try again.")

0 comments on commit 742c9f8

Please sign in to comment.