Metadata-Version: 2.4
Name: rudlm
Version: 2.1.0
Summary: The simplest possible universal AI integration library — one function works with OpenAI, Anthropic, Groq, Gemini, Cohere, Hugging Face, and any OpenAI-compatible API.
Author: Rudra
License-Expression: MIT
Project-URL: Homepage, https://github.com/yourusername/rudlm
Keywords: ai,llm,openai,anthropic,groq,gemini,cohere,wrapper,api
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file
Dynamic: requires-python

# rudlm

The simplest possible universal AI integration library. One function, any provider.

## Install

```bash
pip install rudlm
```

## Usage

```python
import rudlm

# One-line call — auto-detects provider from the key/model
answer = rudlm.complete("sk-...", "What's 2+2?")

# Groq, Gemini, Cohere, Anthropic — same function
answer = rudlm.complete("gsk_...", "Hello", model="llama-3.1-8b-instant")

# Persistent, auto-summarizing chat history
rudlm.currentchathistory("chat.json")
rudlm.complete(api_key, "My name is Sam")
rudlm.complete(api_key, "What's my name?")   # remembers "Sam"

# Throwaway in-memory history (nothing written to disk, lost on exit)
rudlm.currentchathistory()

# Any OpenAI-compatible provider (Mistral, Together, DeepSeek, OpenRouter, local Ollama, etc.)
answer = rudlm.complete(
    api_key, "Hi",
    model="mistral-large-latest",
    base_url="https://api.mistral.ai/v1/chat/completions",
)
```

## Supported providers

**Native support** (auto-detected from your API key or model string):
- OpenAI
- Anthropic (Claude)
- Groq
- Google Gemini
- Cohere
- Hugging Face Inference API

**Via `base_url`**: any provider exposing an OpenAI-compatible `chat/completions`
endpoint — this covers most modern LLM APIs (Mistral, Together AI, Fireworks,
DeepSeek, xAI/Grok, OpenRouter, Perplexity, local runners like Ollama/vLLM/LM
Studio, and more).

**Not supported**: providers requiring non-Bearer-token auth (e.g. AWS Bedrock's
signed requests, OAuth-flow-based APIs), or providers with a genuinely different
request/response schema not listed above.

## API

### `complete(api_key, prompt, model="", base_url=None) -> str`

The core one-line call. `model` and `base_url` are optional — omit them and the
library guesses a sensible default per detected provider.

### `currentchathistory(file=None, max_chars=8000, keep_recent=4, summary_model=None)`

Opt-in chat memory for `complete()`.

- `currentchathistory()` keeps memory in RAM only (gone when the program exits).
- `currentchathistory("chat.json")` loads that file if it exists, otherwise starts
  fresh, and saves after every `complete()` call.
- Memory is a **rolling summary** of older conversation plus the **last few messages
  word-for-word**. Once they exceed `max_chars`, older messages are folded into the
  summary (the summarizer is told to copy names, numbers, dates and preferences
  exactly) and only the last `keep_recent` messages stay verbatim.
- `summary_model` optionally uses a different model just for summarizing (it must
  work with the same API key). Summaries are lossy, so a stronger model helps.
- The history file is JSON and is written atomically, so a crash can't corrupt it.
  Plain-text history files from older versions load as the starting summary.

### `remember(fact)`

Pin a fact that is never summarized away and is sent with every message, e.g.
`rudlm.remember("The user's name is Rudra")`. Call `currentchathistory()` first.

### `clear_memory()`

Wipes the summary, recent messages and pinned facts (on disk too, if a file is attached).

## Errors

If a request fails, `complete()` returns a string starting with `rudlm Error:` that
explains why (HTTP status and provider message, network problem, or unexpected
response). Failed requests are never saved into memory. If summarizing or saving
the history fails, you get a Python warning and the conversation carries on.

## A note on state

The chat-history feature uses module-level global state. This is fine for
scripts and notebooks, but **not safe for concurrent multi-user servers**
(e.g. a Flask app serving many users at once) — all callers would share the
same history. For per-user isolation, use a separate history file per user
and call `currentchathistory(file=...)` before each user's turn. Two processes
writing the same history file at once can overwrite each other's updates.

## License

MIT

## Author

Rudra
