Metadata-Version: 2.4
Name: infinity_llm_client
Version: 0.1.0
Summary: 强类型、可扩展的 LLM 异步客户端库，支持 OpenAI 兼容 API、流式对话、工具调用与多模型消息格式
Author: infinity_system: yin_bailiang
License: MIT
Project-URL: Repository, https://github.com/yinbailiang/infinity_llm
Keywords: llm,openai,async,asyncio,function-calling,tool-calling,streaming,chat
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Framework :: AsyncIO
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: pydantic
Requires-Dist: aiohttp
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: pytest-asyncio; extra == "test"
Provides-Extra: dev
Requires-Dist: interrogate; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pyright; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: infinity_llm_client[test]; extra == "dev"
Dynamic: license-file

# InfinityLLM — Async LLM Client

[![Test](https://github.com/yinbailiang/infinity_llm/actions/workflows/test.yml/badge.svg)](https://github.com/yinbailiang/infinity_llm/actions/workflows/test.yml)
[![Pyright](https://img.shields.io/badge/pyright-strict-blue)](ENGINEERING.md)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE.md)
[![Supported Python](https://img.shields.io/badge/python-3.12%2B-blue)](https://pypi.org/project/infinity_llm/)

**强类型、可扩展的 LLM 异步客户端库 — 支持 OpenAI 兼容 API、流式对话、工具调用。**

## ✨ Features

| 类别 | 能力 |
| - | - |
| 类型安全 | Pydantic 负载校验 · pyright **strict** |
| 多 Provider | 工厂注册模式，轻松扩展新 LLM 服务商 |
| OpenAI 兼容 | 完整实现 OpenAI Chat Completions 流式 API |
| 工具调用 | ToolRegistry 自动从 Python 函数推断 Tool Schema |
| 流式对话 | `stream_chat()` 异步生成器，支持 Text / ToolCall / Usage chunk |
| 多模态消息 | 文本 + 图片 URL 混合内容 |
| 连接管理 | 指数退避重试 + 抖动 + 连接池复用 |

## 📦 Installation

```bash
pip install infinity_llm
```

## 🚀 Quick Start

```python
from llm import (
    Message, Messages,
    OpenAIConfig, create_client,
    ToolRegistry,
)

# 创建客户端
config = OpenAIConfig(
    model="gpt-4o-mini",
    api_key="sk-...",
)
client = create_client(config)

# 流式对话
messages = Messages([
    Message.system("你是一个有用的助手"),
    Message.user("你好"),
])

async with client:
    async for chunk in client.stream_chat(messages):
        print(chunk)
```

## 🧱 Architecture

```
llm/
├── clients/          # 客户端抽象 + provider 实现
│   ├── base.py       #   LLMClient 抽象基类
│   ├── config.py     #   ConnectionConfig / LLMConfig
│   ├── exceptions.py #   异常层级
│   ├── provider.py   #   工厂注册表
│   └── open_ai/      #   OpenAI 兼容实现
├── models/           # 消息 / Chunk / 工具定义
│   ├── messages.py   #   Message, Messages, ToolCall
│   ├── chunks.py     #   StreamChunk 子类
│   └── tools.py      #   ToolDefinition, ParameterProperty
└── tools/            # 工具注册与类型推断
    ├── registry.py   #   ToolRegistry
    └── introspection.py  #   函数 → ToolDefinition 自动推断
```

## 📄 License

MIT
