Rethink Core module package
Project description
Rethink Core
A Python client library for interacting with the Rethink AI API, providing easy access to text generation, chat completions, and image generation services.
Features
- Text Generation: Generate text using various AI models with support for conversation history.
- Chat Completions: OpenAI-compatible chat completions with streaming support.
- Image Generation: Create images from text prompts with customizable dimensions.
- CLI Interface: Command-line tool for quick interactions.
- Error Handling: Robust error handling with documentation links.
Installation
Install from source:
git clone https://github.com/fiandev/rethink-core
cd rethink
pip install .
Or install directly if published:
pip install rethink-core
Quick Start
Python Usage
from rethink.Core import Core
# Initialize with your API key
core = Core("your_api_key_here", system_prompt="You are a helpful assistant.")
# Generate text
response = core.generate_text("Explain quantum computing in simple terms")
print(response["content"])
# Chat completion
messages = [{"role": "user", "content": "Hello!"}]
result = core.chat(messages)
print(result["response"]["content"])
# Generate image
image_result = core.imagine("A sunset over mountains", width=1024, height=768)
print(f"Image URL: {image_result['url']}")
CLI Usage
The package includes a CLI tool:
# Set your API key
export RETHINK_API_KEY="your_api_key_here"
# Chat
rethink chat "Hello, how are you?"
# Generate image
rethink imagine "A beautiful landscape" --width 512 --height 512
API Reference
Core Class
__init__(api_key, system_prompt="", model="deepseek")
Initialize the client.
api_key: Your Rethink API key.system_prompt: Default system instruction.model: Default AI model.
generate_text(prompt, history=None)
Generate text.
prompt: Text prompt.history: Optional conversation history (list of dicts).- Returns:
{"content": "...", "model": "..."}
chat(messages, max_tokens=150, temperature=0.7, stream=False)
Chat completion (OpenAI compatible).
messages: List of message dicts (e.g.,{"role": "user", "content": "..."}).max_tokens: Max tokens in response.temperature: Response randomness.stream: Enable streaming.- Returns:
{"response": {"role": "assistant", "content": "..."}}
imagine(prompt, width=1024, height=768)
Generate image.
prompt: Image description.width/height: Image dimensions.- Returns:
{"url": "...", "model": "...", "width": ..., "height": ...}
change_model(model)
Update the default model.
set_histories(histories)
Set conversation history (dict).
Testing
Run unit tests:
pytest tests/test_Core.py
For integration tests (real API calls, use with caution):
pytest tests/test_Core_integration.py
Set RETHINK_API_KEY environment variable for integration tests.
Error Handling
The library raises Exception for API errors, including HTTP status codes and messages. Check the Rethink API docs at https://core.rethink.web.id/docs/generation for details.
Contributing
Contributions welcome! Please submit issues and pull requests.
License
See LICENSE file (assuming MIT or similar).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rethink_core-0.1.1.tar.gz.
File metadata
- Download URL: rethink_core-0.1.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed6c8460991cc6c0a1d7f2a1d33574afdf54161b12d6e8ca5b859403b605ce40
|
|
| MD5 |
1622f98aade1f1dd3cc5c8aeeb68f2f4
|
|
| BLAKE2b-256 |
21fd02d43d99259d1259da5f9d743debb8efd5e599044ed78df6b222cb0bbfeb
|
File details
Details for the file rethink_core-0.1.1-py3-none-any.whl.
File metadata
- Download URL: rethink_core-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcb21bee3915bec74b97d328990ddc74a3db3b14d893f9ac423bb0e98963776f
|
|
| MD5 |
b9cae5a20771c077ad93d0d129302e22
|
|
| BLAKE2b-256 |
8a2278e0601e952c4eaec6f43483f6678d9aab5fdb88889414d7bb6929338537
|