Metadata-Version: 2.4
Name: llama-index-llms-idemcore
Version: 0.1.3
Summary: LlamaIndex LLM for Idemcore, with signed verifiable receipts in response metadata.
Author-email: Don Wick <don.wick@idemcore.net>
License-Expression: Apache-2.0
Project-URL: Homepage, https://idemcore.net/integrations/llamaindex
Project-URL: Documentation, https://idemcore.net/integrations/llamaindex
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: idemcore<0.4,>=0.3.0
Requires-Dist: idemcore-verify<0.4,>=0.3.6
Requires-Dist: llama-index-core>=0.12.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"

# llama-index-llms-idemcore

LlamaIndex LLM for the [Idemcore](https://idemcore.net) API. Every answer comes
with a signed, independently verifiable, bit-exact receipt, stored on
`ChatResponse.additional_kwargs` and `message.additional_kwargs["idemcore"]`.

Install guide: https://idemcore.net/integrations/llamaindex

## Install

```bash
pip install llama-index-llms-idemcore
export IDEMCORE_API_KEY=ick_...
```

Requires `idemcore>=0.3` (r2 receipts) and `idemcore-verify>=0.3.6`.

## Quickstart

```python
from llama_index.core.base.llms.types import ChatMessage, MessageRole
from llama_index.llms.idemcore import IdemcoreLLM, verify_llamaindex_receipt

llm = IdemcoreLLM(model="your-model-id", max_tokens=64)
response = llm.chat([
    ChatMessage(role=MessageRole.USER, content="Name the three primary colours."),
])
print(response.message.content)
print(response.additional_kwargs["receipt_id"])  # rcpt_...

# bundle = verify_llamaindex_receipt(response, log_text=log_text)
# print(bundle.ok)
```

`complete(prompt)` sends the prompt as a single user message. Streaming
(`stream_chat`, `stream_complete`) yields text deltas and attaches the receipt
on the final item, once the answer is complete.

## Tool calling

Since 0.1.3, `IdemcoreLLM` is a `FunctionCallingLLM`: `chat_with_tools`,
`predict_and_call` and LlamaIndex agents send OpenAI-format tools to every
hosted model. Tool calls are on `response.message.additional_kwargs["tool_calls"]`
(read them with `get_tool_calls_from_response`), and every answer, including
one that calls a tool, still carries a signed receipt.

```python
from llama_index.core.base.llms.types import ChatMessage, MessageRole
from llama_index.core.tools import FunctionTool
from llama_index.llms.idemcore import IdemcoreLLM, verify_llamaindex_receipt

def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return '{"city": "Hanoi", "temp_c": 24, "condition": "light rain"}'

weather = FunctionTool.from_defaults(fn=get_weather)
llm = IdemcoreLLM(model="qwen3.6-35b-a3b-idna", max_tokens=128)

history = [ChatMessage(role=MessageRole.USER, content="What is the weather in Hanoi right now?")]
first = llm.chat_with_tools([weather], chat_history=history)
call = llm.get_tool_calls_from_response(first)[0]  # get_weather {'city': 'Hanoi'}

history += [first.message, ChatMessage(role=MessageRole.TOOL, content=get_weather(**call.tool_kwargs),
                                       additional_kwargs={"tool_call_id": call.tool_id})]
final = llm.chat_with_tools([weather], chat_history=history)
print(final.message.content)
print(verify_llamaindex_receipt(final).ok)  # True
```

- `tool_required=True` sends `tool_choice: "required"`; `tool_choice` also
  accepts `"none"` or a tool name.
- `stream_chat_with_tools` accumulates the tool calls; the receipt arrives on
  the final item.
- For requests sent with tools, the receipt payload also holds
  `prompt_messages` and `output_token_ids`; the verify helper uses them.
- In `auto` mode a model may occasionally answer a live-data question itself
  instead of calling your tool. Use `tool_required=True` when a call must
  happen.

## Sampling

Idemcore decoding is greedy: **temperature is fixed at 0**. Other sampling
settings (`top_p`, `top_k`, penalties, `seed`, `n`, stop sequences) and the
legacy `functions` API are rejected. `max_tokens` must be a whole number from 1 to 2048.
Auth is `IDEMCORE_API_KEY`. Billing is measured server-side in tokens.

## Tests

```bash
pip install -e ".[dev]"
pytest
```

Unit tests mock the SDK. A live smoke test runs only when `IDEMCORE_API_KEY`
is set in the environment.
