GLChat Python Client
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
GLChat Python SDK
A lightweight, flexible Python client for interacting with the GLChat Backend API, providing a simple interface to send messages and receive streaming responses. Built with an OpenAI-like API design for familiarity and ease of use.
Overview
GLChat Python Client is a Python library that simplifies interaction with the GLChat service. It provides a clean, intuitive API for sending messages, handling file attachments, and processing streaming responses, enabling rapid development of chat applications.
Features
- OpenAI-like API: Familiar interface following the OpenAI SDK pattern
- Authentication Support: Built-in API key authentication
- Simple API: Send messages and receive responses with minimal code
- Streaming Support: Process responses in real-time as they arrive
- File Integration: Easily attach and send files with your messages
- Type Safety: Comprehensive type hints for better development experience
- Flexible Response Handling: Choose between streaming or complete text responses
- Memory Efficient: Optimized file handling for large files
Installation
To install the package:
pip install @gdplabs/glchat-sdk
After installation, you can verify it works by trying to import it from any directory:
from glchat_python import GLChatClient
Quick Start
Creating a chat client with GLChat is incredibly simple:
from glchat_python import GLChatClient
# Initialize the GLChat client with your API key
client = GLChatClient(api_key="your-api-key")
# Send a message to the chatbot and receive a streaming response
for chunk in client.message.create(
chatbot_id="your-chatbot-id",
message="Hello!"
):
print(chunk.decode("utf-8"), end="")
Note: Make sure you have the correct chatbot ID and API key before running example.
Advanced Usage
Sending Messages with Files
from pathlib import Path
from glchat_python import GLChatClient
client = GLChatClient(api_key="your-api-key")
# Send message with file attachment
for chunk in client.message.create(
chatbot_id="your-chatbot-id",
message="What's in this file?",
files=[Path("/path/to/your/file.txt")],
user_id="user@example.com",
conversation_id="your-conversation-id",
model_name="openai/gpt-4o-mini"
):
print(chunk.decode("utf-8"), end="")
Using Different File Types
from glchat_python import GLChatClient
import io
client = GLChatClient(api_key="your-api-key")
# File path
file_path = "/path/to/file.txt"
# File-like object
file_obj = io.BytesIO(b"file content")
# Raw bytes
file_bytes = b"file content"
# Send with different file types
for chunk in client.message.create(
chatbot_id="your-chatbot-id",
message="Process these files",
files=[file_path, file_obj, file_bytes]
):
print(chunk.decode("utf-8"), end="")
API Reference
GLChatClient
The main client class for interacting with the GLChat API.
Initialization
client = GLChatClient(
api_key: str | None = None,
base_url: str | None = None,
timeout: float = 60.0
)
Parameters:
api_key: Your GLChat API key for authenticationbase_url: Custom base URL for the GLChat API (optional)timeout: Request timeout in seconds (default: 60.0)
Methods
message.create
Creates a streaming response from the GLChat API.
response_stream = client.message.create(
chatbot_id: str,
message: str,
parent_id: str | None = None,
source: str | None = None,
quote: str | None = None,
user_id: str | None = None,
conversation_id: str | None = None,
user_message_id: str | None = None,
assistant_message_id: str | None = None,
chat_history: str | None = None,
files: List[Union[str, Path, BinaryIO, bytes]] | None = None,
stream_id: str | None = None,
metadata: str | None = None,
model_name: str | None = None,
anonymize_em: bool | None = None,
anonymize_lm: bool | None = None,
use_cache: bool | None = None,
search_type: str | None = None
) -> Iterator[bytes]
Parameters:
chatbot_id: Required chatbot identifiermessage: Required user messagefiles: List of files (filepath, binary, file object, or bytes)**kwargs: Additional message parameters (see MessageRequest model)
Returns:
Iterator[bytes]: Streaming response chunks
File Support
The client supports various file input types with optimized memory handling:
- File paths (string or Path object)
- Binary data (bytes)
- File-like objects (with read() method) - passed directly to avoid memory issues
Authentication
The client supports API key authentication. When an API key is provided, it's automatically included in the Authorization header for all requests:
client = GLChatClient(api_key="your-api-key")
# API key is automatically used in requests
Error Handling
The client uses httpx for HTTP requests and will raise appropriate exceptions for HTTP errors. Make sure to handle these exceptions in your code.
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 Distributions
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 glchat_python-0.0.1b3-py3-none-any.whl.
File metadata
- Download URL: glchat_python-0.0.1b3-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88b59a21c0f480658bb9268c725e58766771636861e3cf3c97cb1ff14a914f6b
|
|
| MD5 |
42a14d9d53ccb8a156fc0f935c682eb3
|
|
| BLAKE2b-256 |
a39a54ec6d74d2041d050e26f4f4c8bd99a87116aac53f123ad3095a28483f08
|