Skip to main content

All popular Framework HF integration kit

Project description

Litegen

Litegen is a lightweight Python wrapper for managing LLM interactions, supporting both local Ollama models and OpenAI API. It provides a simple, unified interface for chat completions with streaming capabilities.

Installation

pip install litegen

Features

  • 🚀 Simple unified interface for LLM interactions
  • 🤖 Support for both local Ollama models and OpenAI
  • 📡 Built-in streaming capabilities
  • 🛠 Function calling support
  • 🔄 Context management for conversations
  • 🎯 GPU support for enhanced performance

Quick Start

from litegen import completion, pp_completion

# Simple completion
response = completion(
    model="mistral",  # or any Ollama/OpenAI model
    prompt="What is the capital of France?"
)
print(response.choices[0].message.content)

# Streaming completion with pretty print
pp_completion(
    model="llama2",
    prompt="Write a short story about a robot",
    temperature=0.7
)

Advanced Usage

System Prompts and Context

response = completion(
    model="mistral",
    system_prompt="You are a helpful math tutor",
    prompt="Explain the Pythagorean theorem",
    context=[
        {"role": "user", "content": "Can you help me with math?"},
        {"role": "assistant", "content": "Of course! What would you like to know?"}
    ]
)

Function Calling

def get_weather(location: str, unit: str = "celsius"):
    """Get weather for a location"""
    pass

response = completion(
    model="gpt-3.5-turbo",
    prompt="What's the weather in Paris?",
    tools=[get_weather]
)

GPU Support

response = completion(
    model="mistral",
    prompt="Complex calculation task",
    gpu=True  # Enable GPU acceleration
)

Configuration

The client can be configured with custom settings:

from litegen import get_client

client = get_client(gpu=True)  # Enable GPU support
# Use client directly for more control

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key (optional, for OpenAI models)

API Reference

completion(...)

Main function for chat completions.

completion(
    model: str,                    # Model name
    messages: Optional[List[Dict[str, str]]] | str = None,  # Raw messages or prompt string
    system_prompt: str = "You are helpful Assistant",  # System prompt
    prompt: str = "",              # User prompt
    context: Optional[List[Dict[str, str]]] = None,  # Conversation history
    temperature: Optional[float] = None,  # Temperature for response randomness
    max_tokens: Optional[int] = None,  # Max tokens in response
    stream: bool = False,          # Enable streaming
    stop: Optional[List[str]] = None,  # Stop sequences
    tools: Optional[List] = None,  # Function calling tools
    gpu: bool = False,            # Enable GPU
    **kwargs                      # Additional parameters
)

pp_completion(...)

Streaming-enabled completion with pretty printing. Takes the same parameters as completion().

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License

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

litegen-0.0.49.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

litegen-0.0.49-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file litegen-0.0.49.tar.gz.

File metadata

  • Download URL: litegen-0.0.49.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.0rc1 Linux/6.8.0-52-generic

File hashes

Hashes for litegen-0.0.49.tar.gz
Algorithm Hash digest
SHA256 c5a8ff8b34feb8d0959cc0b9e063c5e6c034ce323106509bb58034574dcc243f
MD5 892f8248d9e8a89f0603c95ecf5a66f8
BLAKE2b-256 598c404da1f7d6dc96bdba0d403fb161471ec4cb4f0f4d4e4540557366f6e630

See more details on using hashes here.

File details

Details for the file litegen-0.0.49-py3-none-any.whl.

File metadata

  • Download URL: litegen-0.0.49-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.0rc1 Linux/6.8.0-52-generic

File hashes

Hashes for litegen-0.0.49-py3-none-any.whl
Algorithm Hash digest
SHA256 e1bff3722eadfa51f7da10d807044f5727dda4418b08c8113671c8f3befcbb3f
MD5 74e97a0ef9e2eb8078d07fc6718045c0
BLAKE2b-256 36618bcfaf33ae8add3d96784fc43397d5c2e4a635ace9855b53f5fa4d5e30b2

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