Skip to main content

ChatGPT reads Text files

Project description

Text ChatGPT Connector

The Text ChatGPT Connector is a simple script for connecting text files and ChatGPT.

Forked from scrapbox_chatgpt_connector.

Ref: https://scrapbox.io/villagepump/Scrapbox_ChatGPT_Connector

How to install

Install by pip:

$ pip install text_chatgpt_connector

Or you can use repository directly. Install Poetry and run

$ poetry install
$ poetry run tcc ...

You can run `tcc directly if you enter the poetry virtual environment:

$ poetry shell

How to use

Make index

To make index, run:

$ tcc index -i <input_dir>

input_dir is the directory which has text files (with suffix of .txt, .md or .markdown by default).

This will create pickle file named index.pickle. If you want to change the name, set -o <output_file>.

If you run with different input_dir for the same output_file, the index is appended to the previous one.

Ask question

To ask a question, run:

$ tcc ask -q  "もっとも大事な問いとは何だろう?"

If you want compare the answer without index, run with -n (--no_index) option:

$ tcc ask -n -q  "もっとも大事な問いとは何だろう?"

Usage

usage: tcc [-h] [-i INPUT_DIR] [-s INPUT_SUFFIX] [-o OUTPUT_FILE] [-k KEY] [-c CHARACTER_ENCODING] [--chat_model CHAT_MODEL]
           [--encoding ENCODING] [--embedding EMBEDDING] [--remain_url] [--keep_spaces] [--block_size BLOCK_SIZE]
           [--embed_max_size EMBED_MAX_SIZE] [--max_prompt_size MAX_PROMPT_SIZE] [--return_size RETURN_SIZE] [--prompt PROMPT]
           [--bare_prompt BARE_PROMPT] [-q QUESTION] [-n] [-v]
           [command]

positional arguments:
  command               Command (index or ask)

options:
  -h, --help            show this help message and exit
  -i INPUT_DIR, --input_dir INPUT_DIR
                        Input directory
  -s INPUT_SUFFIX, --input_suffix INPUT_SUFFIX
                        Comma separated suffixes of input files, "txt,md,markdown"
  -o OUTPUT_FILE, --output_file OUTPUT_FILE
                        Output file (pickle), default: "index.pickle"
  -k KEY, --key KEY     OpenAI API key. If not given, try to get from environment variable: OPENAI_API_KEY.
  -c CHARACTER_ENCODING, --character_encoding CHARACTER_ENCODING
                        Character encoding for input file, default: "utf-8"
  --chat_model CHAT_MODEL
                        Chat model name, default: "gpt-3.5-turbo"
  --encoding ENCODING   Encoding name for tiktoken, default: "cl100k_base"
  --embedding EMBEDDING
                        Embedding model name, default: "text-embedding-ada-002"
  --remain_url          Keep URL in the text
  --keep_spaces         Keep spaces in the text
  --block_size BLOCK_SIZE
                        Block size for embedding, default: 500
  --embed_max_size EMBED_MAX_SIZE
                        Max size for embedding, default: 8150
  --max_prompt_size MAX_PROMPT_SIZE
                        Max size for prompt, default: 4096
  --return_size RETURN_SIZE
                        Return size, default: 250
  --prompt PROMPT       Prompt template, default: "Read the following text and answer the question. Your reply should be shorter
                        than 250 characters. ## Text {text} ## Question {question}"
  --bare_prompt BARE_PROMPT
                        Prompt template without index, default: "Read the following text and answer the question. Your reply
                        should be shorter than 250 characters. ## Text {text} ## Question {question}"
  -q QUESTION, --question QUESTION
                        Question words for ask, default: "What is the most important question?"
  -n, --no_index        Ask the question directly
  -v, --version         Show version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

text_chatgpt_connector-0.0.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

text_chatgpt_connector-0.0.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file text_chatgpt_connector-0.0.2.tar.gz.

File metadata

  • Download URL: text_chatgpt_connector-0.0.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for text_chatgpt_connector-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2cd2d3de3cb9310507ef82facb0e3e098c0abb76918a919faa8eedbf67aab757
MD5 4f91e6f98210bfd0570adb58e1c738c4
BLAKE2b-256 212a1e5fd4015459a51540f0fbce72b1227ebfd57752e303e0a7c2b43d1c5db1

See more details on using hashes here.

File details

Details for the file text_chatgpt_connector-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: text_chatgpt_connector-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for text_chatgpt_connector-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4728cbe9ed90f4fc32119639146d1ef664c1b36b7d6e00ec3c9629e8e883c46
MD5 297ea36b5a1a9028a442af98cccc70b6
BLAKE2b-256 c493b48386d1c5b2b63c16b042b0fdbae4eb1367f101c9ecc427731786a7307a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page