Python SDK for LocalMind API - chat, documents, semantic search, and conversation management
Project description
LocalMind SDK for Python
Python SDK for integrating with the LocalMind API. Provides a simple client for chat, document management, semantic search, and conversation operations.
Requirements
- Python 3.9+
requestslibrary
Installation
pip install localmind-sdk
Install from source
cd localmind-sdk-python
pip install -e .
Quick Start
from localmind import LocalMindClient
# Create client (defaults to http://localhost:8080/api/v1)
client = LocalMindClient()
# Authenticate (if auth is configured on the server)
client.login("your-password")
# Simple chat
response = client.chat("Riassumi il documento...")
print(response["content"])
# Chat with provider/model selection
response = client.chat("Explain this concept", provider="OLLAMA", model="llama3")
# Chat with RAG enabled
response = client.chat(
"What does the deployment guide say?",
enable_rag=True,
temperature=0.3,
)
print(response["content"])
if response.get("ragSources"):
for source in response["ragSources"]:
print(f" Source: {source['filename']} (score: {source['score']:.2f})")
Document Management
# List all documents
documents = client.documents.list()
# Upload a document
doc = client.documents.upload("/path/to/report.pdf")
print(f"Uploaded: {doc['filename']} (status: {doc['status']})")
# Get document details
doc = client.documents.get("document-id")
# Delete a document
client.documents.delete("document-id")
Semantic Search
# Search with default topK (5)
results = client.search("deployment procedure")
# Search with custom topK
results = client.search("security policy", top_k=10)
for result in results:
print(f"{result['score']:.2f} - {result['filename']}: {result['content'][:100]}")
Conversation Management
# List all conversations
conversations = client.conversations.list()
# List by tag
tagged = client.conversations.list(tag="project-x")
# Get full conversation with messages
convo = client.conversations.get("conversation-id")
for msg in convo["messages"]:
print(f"{msg['role']}: {msg['content']}")
# Continue a conversation
reply = client.chat("Follow-up question", conversation_id=convo["id"])
# Rename a conversation
client.conversations.rename("conversation-id", "New Title")
# Update system prompt
client.conversations.update_system_prompt("conversation-id", "You are a helpful assistant.")
# Tag management
client.conversations.add_tag("conversation-id", "important")
client.conversations.remove_tag("conversation-id", "old-tag")
# Export to PDF
pdf_bytes = client.conversations.export("conversation-id", format="pdf")
with open("conversation.pdf", "wb") as f:
f.write(pdf_bytes)
# Delete a conversation
client.conversations.delete("conversation-id")
Health Check
health = client.health()
print(f"Status: {health['status']}") # UP or DEGRADED
print(f"Services: {health['services']}") # {"api": "UP", "ollama": "UP"}
Configuration
client = LocalMindClient(
base_url="http://my-server:8080/api/v1", # Custom server URL
auth_token="pre-existing-jwt-token", # Pre-set auth token
timeout=300, # Request timeout in seconds (default: 120)
)
Error Handling
All API errors raise LocalMindException with the HTTP status code and response body:
from localmind import LocalMindClient, LocalMindException
client = LocalMindClient()
try:
client.chat("Hello")
except LocalMindException as e:
print(f"Status: {e.status_code}") # e.g. 401, 500
print(f"Body: {e.response_body}") # Raw server response
print(f"Message: {e}")
License
MIT
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 localmind_sdk-1.0.0.tar.gz.
File metadata
- Download URL: localmind_sdk-1.0.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbaf3b37477e9fa872518fd32090da4c31ecc8499caf48ff7acee80a1ff5ab20
|
|
| MD5 |
9b1d0eb7af9d137f30b5f649e44e354d
|
|
| BLAKE2b-256 |
9cd31ed5298d160a28e152560e81dca6594d3309c3e0d09b40954cc32d872639
|
File details
Details for the file localmind_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: localmind_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
356c1504b6c950c3fb3322262a886c4d5c25a4fafeac4fdb00ebe3a67a265b1d
|
|
| MD5 |
76284d3716144130e09b70bf886e5570
|
|
| BLAKE2b-256 |
7b64c3b7aa1943e83a7bb48c88b4c8010b59bde10f17de570b79d5c440654aee
|