majmu


Namemajmu JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/amarzook/majmu-library
SummaryA Python library for chat completions using multiple LLMs with just single API
upload_time2025-08-16 22:12:33
maintainerNone
docs_urlNone
authoramarzook
requires_python>=3.7
licenseMIT
keywords chat completion ai llm api litellm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Majmu ๐Ÿš€

A Python library for chat completions using using multiple LLMs with just single API. Majmu provides a simple and elegant interface to interact with the LiteLLM chat completions endpoint.

## Features

- ๐ŸŽฏ Simple and intuitive API
- ๐Ÿ” Built-in authentication handling
- ๐Ÿ”„ Automatic retry logic with exponential backoff
- ๐Ÿ“ Type hints for better development experience
- ๐Ÿ›ก๏ธ Comprehensive error handling
- ๐Ÿงช Well-tested and reliable
- ๐Ÿ“– Full documentation

## Installation

Install Majmu using pip:

```bash
pip install majmu
```

For development features:

```bash
pip install majmu[dev]
```

## Quick Start

```python
from majmu import MajmuClient, ChatMessage

# Initialize the client
client = MajmuClient(api_key="your-api-key-here")

# Create a simple chat completion
messages = [
    ChatMessage(role="user", content="Hello, how are you?")
]

completion = client.chat_completion(
    model="mistral-small-latest",
    messages=messages,
    max_tokens=100
)

print(completion.content)  # Access the response content easily
```

## Advanced Usage

### Using Dictionary Format

```python
# You can also use dictionaries for messages
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Explain quantum computing in simple terms."}
]

completion = client.chat_completion(
    model="mistral-small-latest",
    messages=messages,
    max_tokens=150
)
```

### Context Manager

```python
# Use as a context manager for automatic resource cleanup
with MajmuClient(api_key="your-api-key") as client:
    completion = client.chat_completion(
        model="mistral-small-latest",
        messages=[{"role": "user", "content": "Hello!"}]
    )
    print(completion.content)
```

### Custom Configuration

```python
client = MajmuClient(
    api_key="your-api-key",
    base_url="https://custom-endpoint.com/v1",  # Custom endpoint
    timeout=60,  # Custom timeout
    max_retries=5  # Custom retry count
)
```

### Accessing Detailed Response

```python
completion = client.chat_completion(
    model="mistral-small-latest",
    messages=[{"role": "user", "content": "Hello!"}]
)

# Access various parts of the response
print(f"Model used: {completion.model}")
print(f"Completion ID: {completion.id}")
print(f"Total tokens: {completion.usage.total_tokens}")
print(f"Finish reason: {completion.choices[0].finish_reason}")

# Convert to dictionary if needed
response_dict = completion.to_dict()
```

## API Reference

### MajmuClient

The main client class for interacting with the API.

#### Parameters

- `api_key` (str): Your API key for authentication
- `base_url` (str, optional): Custom base URL (default: "https://litellm.maatier.com/v1")
- `timeout` (int, optional): Request timeout in seconds (default: 30)
- `max_retries` (int, optional): Maximum retry attempts (default: 3)
- `session` (requests.Session, optional): Custom requests session

#### Methods

##### `chat_completion(model, messages, max_tokens=100, **kwargs)`

Create a chat completion.

**Parameters:**
- `model` (str): The model to use for completion
- `messages` (List[ChatMessage | dict]): List of conversation messages
- `max_tokens` (int, optional): Maximum tokens to generate (default: 100)
- `**kwargs`: Additional parameters for the API

**Returns:**
- `ChatCompletion`: The completion response

### Models

#### ChatMessage

Represents a chat message.

```python
message = ChatMessage(role="user", content="Hello!")
```

#### ChatCompletion

Represents the API response with methods and properties:

- `content`: Quick access to the first choice's content
- `to_dict()`: Convert to dictionary
- `choices`: List of completion choices
- `usage`: Token usage information

## Error Handling

Majmu provides specific exception types for different error scenarios:

```python
from majmu import MajmuClient
from majmu.exceptions import AuthenticationError, RateLimitError, APIError

try:
    client = MajmuClient(api_key="invalid-key")
    completion = client.chat_completion(
        model="mistral-small-latest",
        messages=[{"role": "user", "content": "Hello!"}]
    )
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limit exceeded, please try again later")
except APIError as e:
    print(f"API error: {e}")
```

## Supported Models

The library supports any model available through the LiteLLM endpoint. Popular options include:

- `mistral-small-latest`
- `mistral-medium-latest`
- `mistral-large-latest`
- And many others...

Check your API provider's documentation for the full list of available models.

## Development

### Setting Up Development Environment

```bash
# Clone the repository
git clone https://github.com/amarzook/majmu-library.git
cd majmu

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install
```

### Running Tests

```bash
# Run all tests
pytest

# Run with coverage
pytest --cov=majmu

# Run specific test file
pytest tests/test_client.py
```

### Code Formatting

```bash
# Format code with black
black majmu/ tests/

# Check with flake8
flake8 majmu/ tests/

# Type checking with mypy
mypy majmu/
```

## Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests for your changes
5. Ensure all tests pass
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Changelog

### v0.1.0 (2025-08-16

- Initial release
- Basic chat completion functionality
- Authentication support
- Error handling
- Type hints and documentation

## Support

If you encounter any issues or have questions:

1. Check the [documentation](https://github.com/amarzook/majmu-library/blob/master/README.md)
2. Search [existing issues](https://github.com/amarzook/majmu-library/issues)
3. Create a [new issue](https://github.com/amarzook/majmu-library/issues/new)

## Acknowledgments

- Thanks to the LiteLLM team for providing the API endpoint
- Inspired by the OpenAI Python library design
- Built with โค๏ธ for the Python community

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/amarzook/majmu-library",
    "name": "majmu",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "chat, completion, ai, llm, api, litellm",
    "author": "amarzook",
    "author_email": "amarzook <ahmed.marzook321@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/28/e7/952cdc9ec785f659c60d197bd93201900d20c338999ae5d1b6cfffc9f3a5/majmu-0.1.1.tar.gz",
    "platform": null,
    "description": "# Majmu \ud83d\ude80\n\nA Python library for chat completions using using multiple LLMs with just single API. Majmu provides a simple and elegant interface to interact with the LiteLLM chat completions endpoint.\n\n## Features\n\n- \ud83c\udfaf Simple and intuitive API\n- \ud83d\udd10 Built-in authentication handling\n- \ud83d\udd04 Automatic retry logic with exponential backoff\n- \ud83d\udcdd Type hints for better development experience\n- \ud83d\udee1\ufe0f Comprehensive error handling\n- \ud83e\uddea Well-tested and reliable\n- \ud83d\udcd6 Full documentation\n\n## Installation\n\nInstall Majmu using pip:\n\n```bash\npip install majmu\n```\n\nFor development features:\n\n```bash\npip install majmu[dev]\n```\n\n## Quick Start\n\n```python\nfrom majmu import MajmuClient, ChatMessage\n\n# Initialize the client\nclient = MajmuClient(api_key=\"your-api-key-here\")\n\n# Create a simple chat completion\nmessages = [\n    ChatMessage(role=\"user\", content=\"Hello, how are you?\")\n]\n\ncompletion = client.chat_completion(\n    model=\"mistral-small-latest\",\n    messages=messages,\n    max_tokens=100\n)\n\nprint(completion.content)  # Access the response content easily\n```\n\n## Advanced Usage\n\n### Using Dictionary Format\n\n```python\n# You can also use dictionaries for messages\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"Explain quantum computing in simple terms.\"}\n]\n\ncompletion = client.chat_completion(\n    model=\"mistral-small-latest\",\n    messages=messages,\n    max_tokens=150\n)\n```\n\n### Context Manager\n\n```python\n# Use as a context manager for automatic resource cleanup\nwith MajmuClient(api_key=\"your-api-key\") as client:\n    completion = client.chat_completion(\n        model=\"mistral-small-latest\",\n        messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n    )\n    print(completion.content)\n```\n\n### Custom Configuration\n\n```python\nclient = MajmuClient(\n    api_key=\"your-api-key\",\n    base_url=\"https://custom-endpoint.com/v1\",  # Custom endpoint\n    timeout=60,  # Custom timeout\n    max_retries=5  # Custom retry count\n)\n```\n\n### Accessing Detailed Response\n\n```python\ncompletion = client.chat_completion(\n    model=\"mistral-small-latest\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n)\n\n# Access various parts of the response\nprint(f\"Model used: {completion.model}\")\nprint(f\"Completion ID: {completion.id}\")\nprint(f\"Total tokens: {completion.usage.total_tokens}\")\nprint(f\"Finish reason: {completion.choices[0].finish_reason}\")\n\n# Convert to dictionary if needed\nresponse_dict = completion.to_dict()\n```\n\n## API Reference\n\n### MajmuClient\n\nThe main client class for interacting with the API.\n\n#### Parameters\n\n- `api_key` (str): Your API key for authentication\n- `base_url` (str, optional): Custom base URL (default: \"https://litellm.maatier.com/v1\")\n- `timeout` (int, optional): Request timeout in seconds (default: 30)\n- `max_retries` (int, optional): Maximum retry attempts (default: 3)\n- `session` (requests.Session, optional): Custom requests session\n\n#### Methods\n\n##### `chat_completion(model, messages, max_tokens=100, **kwargs)`\n\nCreate a chat completion.\n\n**Parameters:**\n- `model` (str): The model to use for completion\n- `messages` (List[ChatMessage | dict]): List of conversation messages\n- `max_tokens` (int, optional): Maximum tokens to generate (default: 100)\n- `**kwargs`: Additional parameters for the API\n\n**Returns:**\n- `ChatCompletion`: The completion response\n\n### Models\n\n#### ChatMessage\n\nRepresents a chat message.\n\n```python\nmessage = ChatMessage(role=\"user\", content=\"Hello!\")\n```\n\n#### ChatCompletion\n\nRepresents the API response with methods and properties:\n\n- `content`: Quick access to the first choice's content\n- `to_dict()`: Convert to dictionary\n- `choices`: List of completion choices\n- `usage`: Token usage information\n\n## Error Handling\n\nMajmu provides specific exception types for different error scenarios:\n\n```python\nfrom majmu import MajmuClient\nfrom majmu.exceptions import AuthenticationError, RateLimitError, APIError\n\ntry:\n    client = MajmuClient(api_key=\"invalid-key\")\n    completion = client.chat_completion(\n        model=\"mistral-small-latest\",\n        messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\n    )\nexcept AuthenticationError:\n    print(\"Invalid API key\")\nexcept RateLimitError:\n    print(\"Rate limit exceeded, please try again later\")\nexcept APIError as e:\n    print(f\"API error: {e}\")\n```\n\n## Supported Models\n\nThe library supports any model available through the LiteLLM endpoint. Popular options include:\n\n- `mistral-small-latest`\n- `mistral-medium-latest`\n- `mistral-large-latest`\n- And many others...\n\nCheck your API provider's documentation for the full list of available models.\n\n## Development\n\n### Setting Up Development Environment\n\n```bash\n# Clone the repository\ngit clone https://github.com/amarzook/majmu-library.git\ncd majmu\n\n# Create virtual environment\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n\n# Install development dependencies\npip install -e \".[dev]\"\n\n# Install pre-commit hooks\npre-commit install\n```\n\n### Running Tests\n\n```bash\n# Run all tests\npytest\n\n# Run with coverage\npytest --cov=majmu\n\n# Run specific test file\npytest tests/test_client.py\n```\n\n### Code Formatting\n\n```bash\n# Format code with black\nblack majmu/ tests/\n\n# Check with flake8\nflake8 majmu/ tests/\n\n# Type checking with mypy\nmypy majmu/\n```\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Make your changes\n4. Add tests for your changes\n5. Ensure all tests pass\n6. Commit your changes (`git commit -m 'Add amazing feature'`)\n7. Push to the branch (`git push origin feature/amazing-feature`)\n8. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\n### v0.1.0 (2025-08-16\n\n- Initial release\n- Basic chat completion functionality\n- Authentication support\n- Error handling\n- Type hints and documentation\n\n## Support\n\nIf you encounter any issues or have questions:\n\n1. Check the [documentation](https://github.com/amarzook/majmu-library/blob/master/README.md)\n2. Search [existing issues](https://github.com/amarzook/majmu-library/issues)\n3. Create a [new issue](https://github.com/amarzook/majmu-library/issues/new)\n\n## Acknowledgments\n\n- Thanks to the LiteLLM team for providing the API endpoint\n- Inspired by the OpenAI Python library design\n- Built with \u2764\ufe0f for the Python community\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for chat completions using multiple LLMs with just single API",
    "version": "0.1.1",
    "project_urls": {
        "Bug Reports": "https://github.com/amarzook/majmu-library/issues",
        "Documentation": "https://github.com/amarzook/majmu-library/blob/master/README.md",
        "Homepage": "https://github.com/amarzook/majmu-library",
        "Source": "https://github.com/amarzook-library/majmu"
    },
    "split_keywords": [
        "chat",
        " completion",
        " ai",
        " llm",
        " api",
        " litellm"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1be367ddd820a677be3c9ff6cb1aa8c2349e8653415c18c2e4b8a2a9cdc55235",
                "md5": "1bcde0f73a2b8d11b7cf44de58bbff72",
                "sha256": "abb232f977552a2a500fcf31870850465600075748c930ec78412245d1789259"
            },
            "downloads": -1,
            "filename": "majmu-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1bcde0f73a2b8d11b7cf44de58bbff72",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 9766,
            "upload_time": "2025-08-16T22:12:32",
            "upload_time_iso_8601": "2025-08-16T22:12:32.377750Z",
            "url": "https://files.pythonhosted.org/packages/1b/e3/67ddd820a677be3c9ff6cb1aa8c2349e8653415c18c2e4b8a2a9cdc55235/majmu-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "28e7952cdc9ec785f659c60d197bd93201900d20c338999ae5d1b6cfffc9f3a5",
                "md5": "2bfb887f9759467dd64feec2d1e81d3b",
                "sha256": "2e44bf25b75861a54c066e9d3684f6c4f3be4cd58c9564630b7a2237beab66c4"
            },
            "downloads": -1,
            "filename": "majmu-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2bfb887f9759467dd64feec2d1e81d3b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19461,
            "upload_time": "2025-08-16T22:12:33",
            "upload_time_iso_8601": "2025-08-16T22:12:33.975564Z",
            "url": "https://files.pythonhosted.org/packages/28/e7/952cdc9ec785f659c60d197bd93201900d20c338999ae5d1b6cfffc9f3a5/majmu-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-16 22:12:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "amarzook",
    "github_project": "majmu-library",
    "github_not_found": true,
    "lcname": "majmu"
}
        
Elapsed time: 1.35593s