Skip to main content

GLChat Python Client

Project description

GLAIR

GLChat Python SDK

Latest Release License

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 authentication
  • base_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 identifier
  • message: Required user message
  • files: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glchat_sdk-0.0.1b1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file glchat_sdk-0.0.1b1-py3-none-any.whl.

File metadata

File hashes

Hashes for glchat_sdk-0.0.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 489e2ab1aba7cdad5c8857dd9c7d2be147c330d01de6e5aec6740ab8ede99ab5
MD5 09fb10efddad1c1f183e2d607be80f51
BLAKE2b-256 d9bd3dacd2f36a6114ecab896f7b37dc8891772a62ad71ef91c639467791c441

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page