Metadata-Version: 2.5
Name: llama-index-llms-gmicloud
Version: 0.1.0
Summary: LlamaIndex LLM integration for GMI Cloud's OpenAI-compatible inference API
Project-URL: Homepage, https://github.com/himanshu748/llama-index-llms-gmicloud
Project-URL: Repository, https://github.com/himanshu748/llama-index-llms-gmicloud
Project-URL: Issues, https://github.com/himanshu748/llama-index-llms-gmicloud/issues
Project-URL: Documentation, https://github.com/himanshu748/llama-index-llms-gmicloud#readme
Author-email: Himanshu Kumar <jhahimanshu653@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: gmi-cloud,gmicloud,llama-index,llm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: <4.0,>=3.11
Requires-Dist: llama-index-core<0.15,>=0.13.0
Requires-Dist: llama-index-llms-openai-like<0.10,>=0.8.0
Description-Content-Type: text/markdown

# LlamaIndex LLM Integration: GMI Cloud

Community LlamaIndex integration for [GMI Cloud](https://www.gmicloud.ai)'s OpenAI-compatible inference API. This is not an official GMI Cloud or LlamaIndex project.

Use any of the 70+ text models on GMI Cloud — GLM, DeepSeek, Qwen, Gemini, Llama and more — through the standard LlamaIndex `LLM` interface.

- Default model: `zai-org/GLM-5.3-Flash` (1,048,576-token context)
- API base: `https://api.gmi-serving.com/v1`
- Auth: `GMI_API_KEY` (create a key at [console.gmicloud.ai](https://console.gmicloud.ai))

## Installation

```bash
pip install llama-index-llms-gmicloud
```

Or, from a checkout of this repository:

```bash
pip install -e .
# or
uv sync --group dev
```

## Usage

```python
from llama_index.llms.gmicloud import GMICloud

# Reads GMI_API_KEY from the environment
llm = GMICloud()
```

You can also pass the key and model explicitly:

```python
llm = GMICloud(
    model="zai-org/GLM-5.3-Flash",
    api_key="your-api-key",
)
```

### Completion

```python
response = llm.complete("Explain the importance of low latency LLMs in two sentences.")
print(response)
```

### Chat

```python
from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(role="system", content="You are a concise assistant."),
    ChatMessage(role="user", content="Name one use of a 1M-token context window."),
]
response = llm.chat(messages)
print(response.message.content)
```

### Streaming

```python
for chunk in llm.stream_complete("Write a short haiku about clouds."):
    print(chunk.delta, end="", flush=True)
```

### Async

```python
import asyncio

async def main():
    response = await llm.acomplete("What is 17 * 19?")
    print(response)

asyncio.run(main())
```

### Function calling with a FunctionAgent

GMI Cloud's chat completions endpoint accepts OpenAI-style `tools`. `GMICloud` sets `is_function_calling_model=True` by default, so you can drop it into a LlamaIndex agent:

```python
import asyncio

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.gmicloud import GMICloud

def get_weather(city: str) -> str:
    """Return a short weather report for a city."""
    return f"Sunny and 22°C in {city}."

agent = FunctionAgent(
    tools=[get_weather],
    llm=GMICloud(),
    system_prompt="You are a helpful assistant. Use tools when they help.",
)

async def main():
    response = await agent.run("What's the weather in Paris?")
    print(response)

asyncio.run(main())
```

`ReActAgent` works the same way if you prefer a text-based reason-act loop:

```python
from llama_index.core.agent.workflow import ReActAgent

agent = ReActAgent(
    tools=[get_weather],
    llm=GMICloud(),
)
```

## Reasoning models and `max_tokens`

Some GMI Cloud models (including the default `zai-org/GLM-5.3-Flash`) put intermediate thinking in `reasoning_content` and only then write the user-visible reply in `content`. If `max_tokens` is too low, the model can spend the entire budget on thinking and return **empty `content`**.

`GMICloud` defaults `max_tokens` to 2048 to reduce this. If you lower it and get an empty response, raise `max_tokens` and retry. LlamaIndex already attaches `reasoning_content` as a thinking block on chat messages; this package also logs a warning when a call comes back reasoning-only.

```python
# Too low: may return empty visible text
llm = GMICloud(max_tokens=16)

# Enough budget for thinking + the visible reply
llm = GMICloud(max_tokens=2048)
```

## Models and context windows

Any model id from `GET /v1/models` works via the `model` argument. Context windows for the catalog as of 2026-11-27 are bundled in the package (unknown ids fall back to 1,048,576 tokens). Override with `context_window=...` if needed.

Examples:

| Model id | Context window |
|---|---:|
| `zai-org/GLM-5.3-Flash` (default) | 1,048,576 |
| `zai-org/GLM-5.3` | 1,048,576 |
| `deepseek-ai/deepseek-v4.1-flash-1017` | 1,048,575 |
| `google/gemini-3.8-flash` | 1,048,576 |
| `Qwen/Qwen3.8-27B` | 1,000,000 |

Prices change; check the [GMI Cloud model library](https://docs.gmicloud.ai) before budgeting.

## Configuration

| Parameter | Default | Description |
|---|---|---|
| `model` | `zai-org/GLM-5.3-Flash` | Any GMI Cloud text model id |
| `api_key` | `GMI_API_KEY` env var | GMI Cloud API key |
| `api_base` | `https://api.gmi-serving.com/v1` | OpenAI-compatible base URL |
| `is_chat_model` | `True` | Use the chat completions endpoint |
| `is_function_calling_model` | `True` | Advertise OpenAI-style tool calling |
| `context_window` | looked up for the model | Tokens of context |
| `max_tokens` | `2048` | Max generated tokens (raise this for reasoning models) |

Additional `OpenAILike` / `OpenAI` kwargs (`temperature`, `timeout`, `additional_kwargs`, …) are passed through.

## Development

```bash
uv sync --group dev
uv run ruff check .
uv run pytest
```

Live API checks are skipped unless both `GMI_API_KEY` and `GMI_LIVE_TEST=1` are set:

```bash
GMI_LIVE_TEST=1 uv run pytest tests -m live
# or
GMI_LIVE_TEST=1 python examples/live_check.py
```

## Live verification

Verified on 27 November 2026 (Asia/Calcutta) against the live GMI Cloud API, default model `zai-org/GLM-5.3-Flash`, LlamaIndex 0.14.26 / llama-index-llms-openai-like 0.9.0:

| Call | Output |
|---|---|
| `complete` | `pong` |
| `stream_complete` | `pong` |
| `chat` | `pong` |
| `acomplete` | `pong` |
| `FunctionAgent` (tool: `add`) | `17 plus 19 equals **36**.` |
| `ReActAgent` (tool: `add`) | `17 plus 19 equals 36.` |

A direct tools request also returned `tool_calls: get_weather(city="Paris")`. With `max_tokens=16`, the same model returned empty `content` and a truncated `reasoning_content` (`finish_reason=length`), which is why this package defaults `max_tokens` to 2048 and logs a warning in that case.

## License

MIT. See [LICENSE](LICENSE).
