Simatwa / python-tgpt

AI Chat in Terminal + Package + REST-API
https://python-tgpt.onrender.com
MIT License
106 stars 15 forks source link

Multiline prompt #59

Closed 11100010 closed 3 weeks ago

11100010 commented 3 weeks ago

I'm learning python, so do not really understand all part of your code. Could you suggest me which part of your code related handling the prompt from the user in CLI? I want to make it accept multiline prompt being pasted fro the clipboard content without automatically separate it to multiple prompts. Thank you for your great work.

11100010 commented 3 weeks ago

this simple piece of code really helps:

Gather multi-line input

full_input = line while True: try:

Wait for the next line of input

next_line = input() # This waits for the user to enter another line if next_line.strip() == "Q": # Stop if the line is equal to the string "Q" break full_input += "\n" + next_line # Append the next line except EOFError: # Handle end of input break

11100010 commented 3 weeks ago

this version will allow the prompt being sent when three consecutive "\n" appear, it can be three empty lines from the clipboard or three times pressing enter key, actually 4 times to form 3 empty lines :D

full_input = line empty_line_count = 0 # Initialize a counter for empty lines

    while True:
        try:
            # Wait for the next line of input
            next_line = input()  # This waits for the user to enter another line

            if next_line.strip() == "":
                empty_line_count += 1  # Increment the empty line counter
            else:
                empty_line_count = 0  # Reset the counter if a non-empty line is encountered

            full_input += "\n" + next_line  # Append the next line

            if empty_line_count >= 3:  # Stop if three consecutive empty lines appear
                break

        except EOFError:  # Handle end of input
            break
11100010 commented 3 weeks ago

demo render1727167932975