├── README.md └── infiniteGPT └── blastoff.py /README.md: -------------------------------------------------------------------------------- 1 | # InfiniteGPT 🚀 2 | 3 | InfiniteGPT is a Python script that lets you input an unlimited size text into the OpenAI API. No more tedious copy & pasting. It's a single python script that can connect to any of the OpenAI API chat models (gpt-3.5-turbo, gpt4, etc.). 4 | 5 | This eliminates the need for re-prompting when using a large text input or copying and pasting endless chunks of text into chatGPT. 📚 6 | 7 | ## Dependencies 📦 8 | 9 | - python3 10 | - openai 11 | 12 | ## BYOK (Bring Your Own Keys!) 🔑 13 | 14 | Go to [OpenAI](https://www.openai.com) to get your personal API keys. 15 | 16 | This script does not hide your API keys, so please do so if you plan on integrating it into a public application. ⚠️ 17 | 18 | ## Usage 🛠️ 19 | 20 | 1. Clone the repository 21 | 2. Install the required dependencies 22 | 3. Add your API keys 23 | 4. Run the script 24 | 25 | ## License 📄 26 | 27 | MIT License. See [LICENSE](LICENSE) for more information. 28 | 29 | ## Connect with me 📣 30 | 31 | I write about using AI tools & share my latest building on Twitter [@ehalm_](https://twitter.com/ehalm_). DM me with any questions. 🐦 32 | 33 | ## Happy building! 🎉 34 | -------------------------------------------------------------------------------- /infiniteGPT/blastoff.py: -------------------------------------------------------------------------------- 1 | import openai 2 | from concurrent.futures import ThreadPoolExecutor 3 | import tiktoken 4 | 5 | # Add your own OpenAI API key 6 | 7 | openai.api_key = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 8 | 9 | def load_text(file_path): 10 | with open(file_path, 'r') as file: 11 | return file.read() 12 | 13 | def save_to_file(responses, output_file): 14 | with open(output_file, 'w') as file: 15 | for response in responses: 16 | file.write(response + '\n') 17 | 18 | # Change your OpenAI chat model accordingly 19 | 20 | def call_openai_api(chunk): 21 | response = openai.ChatCompletion.create( 22 | model="gpt-3.5-turbo", 23 | messages=[ 24 | {"role": "system", "content": "PASS IN ANY ARBITRARY SYSTEM VALUE TO GIVE THE AI AN IDENITY"}, 25 | {"role": "user", "content": f"YOUR DATA TO PASS IN: {chunk}."}, 26 | ], 27 | max_tokens=500, 28 | n=1, 29 | stop=None, 30 | temperature=0.5, 31 | ) 32 | return response.choices[0]['message']['content'].strip() 33 | 34 | def split_into_chunks(text, tokens=500): 35 | encoding = tiktoken.encoding_for_model('gpt-3.5-turbo') 36 | words = encoding.encode(text) 37 | chunks = [] 38 | for i in range(0, len(words), tokens): 39 | chunks.append(' '.join(encoding.decode(words[i:i + tokens]))) 40 | return chunks 41 | 42 | def process_chunks(input_file, output_file): 43 | text = load_text(input_file) 44 | chunks = split_into_chunks(text) 45 | 46 | # Processes chunks in parallel 47 | with ThreadPoolExecutor() as executor: 48 | responses = list(executor.map(call_openai_api, chunks)) 49 | 50 | save_to_file(responses, output_file) 51 | 52 | # Specify your input and output files 53 | 54 | if __name__ == "__main__": 55 | input_file = "test_input.txt" 56 | output_file = "output_og.txt" 57 | process_chunks(input_file, output_file) 58 | 59 | # Can take up to a few minutes to run depending on the size of your data input 60 | --------------------------------------------------------------------------------