Giter Club home page Giter Club logo

gptauto's Introduction

gptauto

A fully functional ChatGPT selenium scraper written in Python


Requirements

  • Install pip requirements pip install -r requirements.txt

  • Download Firefox and geckodriver and place it in folder registered in PATH.

  • In a Firefox profile of your choise, (or default one) ensure you are logged in to chatgpt.

  • Provide the firefox profile absolute path to the ask_chatgpt function, using the profile_path parameter.


Examples

  • Example asking one question and returning answer

    import gptauto
    
    QUESTION = input("Ask question\n>>").lstrip().rstrip()
    res = gptauto.ask_chatgpt(QUESTION,
        headless=True,
        quiet=True,
    )
    print(res)
  • Example with a long text as input

    import gptauto
    
    long_text = ""
    with open("text.txt", "r") as fp:
        transcript = fp.read().rstrip()
    
    # Any of these prompts can be omitted
    
    START_PROMPT = (
        "A message with a start prompt, if present is written before question message"
    )
    
    # These will only be written if
    # the text was long enough to be
    # separated in batches
    START_BATCH_PROMPT = "<WRITTEN BEFORE TEXT CHUNK>\n"
    END_BATCH_PROMPT = "<WRITTEN AFTER TEXT CHUNK>\n"
    
    END_PROMPT = (
        "This message if present will be written at last, after every chunk is sent"
    )
    
    res = gptauto.ask_chatgpt(
        long_text,
        start_prompt=START_PROMPT,
        start_batch_prompt=START_BATCH_PROMPT,
        end_batch_prompt=END_BATCH_PROMPT,
        end_prompt=END_PROMPT,
        headless=True,  # False by default
        quiet=False,  # Use False to watch progress
    )
  • Example of a continuous chat

    import gptauto
    import traceback
    
    # None initialize driver
    driver = None
    
    # Previous messages used for filtering response
    last_messages = []
    
    while True:
        try:
            QUESTION = input("\nAsk question\n>>").lstrip().rstrip()
            # If chat_mode is enabled, ask_chatgpt will return a tuple
            # with (driver_intsance, response).
            driver, res = gptauto.ask_chatgpt(
                QUESTION,
                headless=True,  # False by default
                quiet=True,  # Disable status print()
                chat_mode=True,  # Enable chat mode
                driver=driver,  # Pass cached driver instance
            )
    
            # Filter old answers...
            for m in last_messages:
                res = res.replace(m, "")
            last_messages.append(res)
    
            print(res)
        except Exception as e:
            traceback.print_exc()
            # Once done, ensure to call quit() on driver instance
            if driver:
                driver.quit()
            break

Notes

For bug reporting, please feel free to open an issue in this repository : )

gptauto's People

Contributors

st1vms avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.