- add 'generating docs' segment
A powerful and modular library for AI-driven text and book generation, revision, and analysis. With GPTK, you can seamlessly integrate AI tools such as ChatGPT, Claude, Grok, and Gemini for crafting narratives, revising text, and managing content generation workflows.
Using a plug-n-play architecture, it is possible to utilize any number of AI agents at the same time, together or separately. They each have their own strengths and drawbacks, so it is important to know the basics of AI platform API usage before using this library.
The groundbreaking aspect of this toolkit is that you can generate truly quality long-form content using AI and the builtin tools the library offers, rapidly and automatically if desired. Contrast this to using a simple one-at-a-time interaction such as the ChatGPT web portal.
- Overview
- Features
- Getting Started
- Usage
- Configuration
- Modules and Structure
- Changelog
- Todo
- Contributing
- License
GPTK is designed for authors, developers, and researchers looking to leverage AI for content creation and refinement. It offers robust support for managing book outlines, generating chapter fragments, revising text with pattern recognition, and conducting linguistic analysis. By integrating APIs from various AI providers, GPTK provides a unified interface for intelligent text operations.
- Multi-Agent Support: Seamlessly integrate with ChatGPT, Claude, Grok, and Gemini.
- Book Generation: Automate novel creation chapter by chapter, with dynamic fragment handling.
- Content Revision: Revise text using pattern matching, manual operations, or AI-driven corrections.
- Text Analysis: Identify patterns, repeated content, and structural inconsistencies.
- Extensible Configuration: Customize prompts, patterns, and revision workflows.
- Training Data Management: Integrate training data from the
/prompts
directory for contextual reference.
Before using GPTK, you'll need to create accounts and obtain API keys from the AI platforms you wish to use. Here's how to set up each one:
- Visit OpenAI's platform
- Create an account or sign in
- Navigate to Settings → API keys
- Click "Create new secret key"
- Copy and secure your API key
- Current pricing: Pay-as-you-go with usage-based rates
- Go to Anthropic's Console
- Sign up for an account
- Once approved, visit the API Keys section
- Generate a new API key
- Copy and secure your key
- Current pricing: Usage-based billing
- Visit xAI's platform
- Create an account
- Request API access (currently in beta)
- Once approved, generate your API key
- Copy and secure your key
- Current pricing: Contact xAI for pricing details
- Visit Google AI Studio
- Sign in with your Google account
- Create a new project if needed
- Navigate to the API & Services → Credentials
- Create API key
- Copy and secure your key
- Current pricing: Free tier available, then usage-based
Note: Store your API keys securely and never commit them to version control. We recommend using environment variables or a secure credentials manager such as dotenv
.
Example environment variables setup:
export OPENAI_API_KEY='your-key-here'
export ANTHROPIC_API_KEY='your-key-here'
export XAI_API_KEY='your-key-here'
export GOOGLE_AI_API_KEY='your-key-here'
-
Clone the repository:
git clone https://github.com/your-username/gptk.git cd gptk
-
Install dependencies using Bundler:
bundle install
- Ruby 3.0 or later
- Gems:
pragmatic_segmenter
httparty
openai
anthropic
Below are examples of how you might initialize basic clients using the openai
and anthropic
gems. These initialization steps set you up to make requests to ChatGPT (OpenAI) and Claude (Anthropic).
ChatGPT (OpenAI) Example:
require 'openai'
OPENAI_API_KEY = ENV['OPENAI_API_KEY']
my_chatgpt_client = OpenAI::Client.new(
access_token: OPENAI_API_KEY,
request_timeout: 300,
log_errors: true, # Remove `log_errors` param for production!
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{OPENAI_API_KEY}",
'OpenAI-Beta' => 'assistants=v2'
}
)
Claude (Anthropic) Example:
ANTHROPIC_API_KEY = ENV['ANTHROPIC_API_KEY']
my_claude_client = Anthropic::Client.new(
access_token: ANTHROPIC_API_KEY,
request_timeout: 120,
headers: {
'anthropic-beta': 'prompt-caching-2024-07-31'
}
)
Use the Book
class to generate a novel chapter by chapter. Provide an outline, instructions, and AI API clients.
require 'book'
outline = "path/to/outline.txt"
book = GPTK::Book.new outline, openai_client: my_chatgpt_client
# Generate a 5-chapter book with 3 fragments per chapter
book.generate 5, 3
Revise text by identifying and acting on patterns with AI or manual operations.
text = "This is a sample text with repeated patterns."
pattern = "repeated patterns"
revised_text, revisions = book.revise_chapter_content text, pattern
Analyze text to identify repeated patterns or specific issues.
matches = GPTK::Text.analyze_text "Analyze this sample text.", "sample"
GPTK::Text.print_matches matches
All configurations are managed through the /config
directory. Key configuration files include:
ai_setup.rb
: Handles API client initialization.book_setup.rb
: Contains book generation parameters.config.rb
: Loads and manages overall configuration.
Manages the creation and revision of books, chapters, and fragments.
Interfaces with various AI tools for text generation and revision.
Loads and manages application-wide settings.
Handles text processing, including word counting, pattern matching, and list parsing.
Generates structured documents based on text and chapter data.
Provides helper methods like symbolifying hash keys and incrementing filenames.
- AI Training data is located in the
/prompts
directory.
See CHANGELOG.md for a detailed history of changes.
Planned features and enhancements are listed in TODO.md.
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
This library is licensed under the MIT License. See LICENSE for details.