Skip to main content

强类型、可扩展的 LLM 异步客户端库,支持 OpenAI 兼容 API、流式对话、工具调用与多模型消息格式

Project description

InfinityLLM — Async LLM Client

Test Pyright License Supported Python

强类型、可扩展的 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

pip install infinity_llm

🚀 Quick Start

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

infinity_llm_client-0.1.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

infinity_llm_client-0.1.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file infinity_llm_client-0.1.0.tar.gz.

File metadata

  • Download URL: infinity_llm_client-0.1.0.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for infinity_llm_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eca22f198f9062205bcf8c8ab74226570c99faa3c2c159f12cd4f744c6d3de70
MD5 6df871896733c45ed8dd09eb978afd05
BLAKE2b-256 96f5e936573ecc28dc687a825b4990ff0ff143a8654d1ae8a3960ab10c76b27d

See more details on using hashes here.

File details

Details for the file infinity_llm_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: infinity_llm_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for infinity_llm_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18b2abaa20527dda7d5e923447d46ace1c98d6fe294a75376500d8a5ab1b11cd
MD5 9bca85f2c53f9141904c23656cc69105
BLAKE2b-256 a9f6e2ce9b06b7f42f172e1276b7e3a3d33db99ee5eee81a594dc15b80b604ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page