Metadata-Version: 2.5
Name: orkg-llm-logger
Version: 0.1.0
Summary: Log LLM calls (OpenAI, Gemini, OpenRouter, ...) to JSON/JSONL in the record format read by the @orkg/llm-logger dashboard.
Project-URL: Homepage, https://gitlab.com/TIBHannover/orkg/llm-logger
Project-URL: Repository, https://gitlab.com/TIBHannover/orkg/llm-logger
Project-URL: Issues, https://gitlab.com/TIBHannover/orkg/llm-logger/-/issues
Project-URL: Changelog, https://gitlab.com/TIBHannover/orkg/llm-logger/-/blob/main/CHANGELOG.md
Author: Yucel
Author-email: Amirreza Alasti <amirrezaalasti@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: gemini,llm,logging,observability,openai,openrouter
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Provides-Extra: dev
Requires-Dist: jsonschema>=4.20; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Provides-Extra: gemini
Requires-Dist: google-generativeai>=0.5; extra == 'gemini'
Provides-Extra: openai
Requires-Dist: openai>=1.0; extra == 'openai'
Description-Content-Type: text/markdown

# orkg-llm-logger

Part of [LLM Logger](https://gitlab.com/TIBHannover/orkg/llm-logger).

Log LLM calls from Python (OpenAI, Gemini, OpenRouter, or any client) to JSON or
JSONL. Records use the same `GenerationRecord` format as the TypeScript package
[`@orkg/llm-logger`](../typescript), defined in
[`schema/generation-record.schema.json`](../schema/generation-record.schema.json).

No runtime dependencies.

```sh
pip install orkg-llm-logger
```

```python
from llm_logger import llm_logger, LLMLoggerConfig

LLMLoggerConfig.configure(file_path="llm_logs.jsonl", project="my-agent")

# Decorate a function that calls a model
@llm_logger(name="extract")
def ask(prompt: str):
    return client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": prompt}],
    )

# Or wrap an SDK method directly
create = llm_logger.wrap(client.chat.completions.create, name="chat")

# Or capture manually inside an existing block
with llm_logger.context(name="batch") as ctx:
    resp = client.chat.completions.create(...)
    ctx.capture(resp, prompt="...")
```

Sync and async functions are both supported. Provider, model, prompt, output
and token usage are extracted from OpenAI-, Gemini- and OpenRouter-shaped
responses. Errors are logged with `status: "error"` and re-raised.

Output format follows the file extension: `.jsonl` appends one record per line,
anything else keeps a JSON array (written atomically).

See [`examples/`](examples) — `quickstart.py` runs without API keys.

## Development

```sh
python -m venv .venv && . .venv/bin/activate
pip install -e '.[dev]'
pytest
```

## License

MIT
