
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
A Python library for interacting with KoboldCPP APIs, providing high-level abstractions for text processing, image handling, and generation tasks.
Text Processing
Image Processing
Template Management
API Integration
pip install koboldapi
from koboldapi import KoboldAPICore, ChunkingProcessor
# Initialize the API client
core = KoboldAPICore(api_url="http://localhost:5001")
# Create a chunking processor
chunker = ChunkingProcessor(core.api_client, max_chunk_length=2048)
# Process text
chunks, metadata = chunker.chunk_file("document.txt")
for chunk, token_count in chunks:
response = core.wrap_and_generate(
instruction="Summarize this text:",
content=chunk
)
print(response)
from koboldapi import KoboldAPICore, ImageProcessor
# Initialize processors
core = KoboldAPICore(api_url="http://localhost:5001")
processor = ImageProcessor(max_dimension=1024)
# Process image
encoded_image, img_path = processor.process_image("image.jpg")
response = core.wrap_and_generate(
instruction="Describe this image:",
images=[encoded_image]
)
print(response)
from koboldapi import KoboldAPICore
import asyncio
async def stream_example():
core = KoboldAPICore(api_url="http://localhost:5001")
# Stream tokens as they're generated
async for token in core.api_client.stream_generate(
prompt="Write a story about a robot:",
max_length=200
):
print(token, end='', flush=True)
# Or collect all tokens into final result
result = await core.api_client.generate_sync(
prompt="Write a story about a robot:",
max_length=200
)
print(result)
if __name__ == "__main__":
asyncio.run(stream_example())
The main interface for interacting with KoboldCPP APIs.
core = KoboldAPICore(
api_url="http://localhost:5001",
api_password=None, # Optional API password
generation_params={ # Optional generation parameters
'temp': 0.7,
'top_k': 40,
'top_p': 0.9
},
templates_directory="path/to/templates" # Optional custom templates
)
The ChunkingProcessor class handles text segmentation and processing:
chunker = ChunkingProcessor(
api_client, # KoboldAPI instance
max_chunk_length=2048, # Maximum tokens per chunk
max_total_chunks=1000 # Maximum number of chunks
)
# Process a file
chunks, metadata = chunker.chunk_file("document.txt")
# Process raw text
chunks = chunker.chunk_text("Your text content here")
The ImageProcessor class handles image preparation and optimization:
processor = ImageProcessor(
max_dimension=1024, # Maximum image dimension
patch_sizes=[8, 14, 16, 32], # Patch size options
max_file_size=50 * 1024 * 1024 # Maximum file size in bytes
)
# Process an image
encoded_image, path = processor.process_image("image.jpg")
Custom templates can be provided in JSON format:
{
"template_name": {
"name": ["model_name_pattern"],
"system_start": "\nSystem: ",
"system_end": "\n",
"user_start": "User: ",
"user_end": "\n",
"assistant_start": "Assistant: "
}
}
The package includes example scripts for common tasks:
python text-example.py input.txt \
--task translate \
--api-url http://localhost:5001 \
--language French \
--max-chunk-size 8192
Available tasks:
python image-example.py image.jpg \
--api-url http://localhost:5001 \
--instruction "Describe the image in detail."
The library provides custom exceptions for error handling:
try:
result = core.wrap_and_generate(instruction="Your instruction")
except KoboldAPIError as e:
print(f"API Error: {e}")
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the GPLv3 License - see the LICENSE file for details.
FAQs
Python library for interacting with KoboldCPP API
We found that koboldapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.