openlimitHW


NameopenlimitHW JSON
Version 0.5.4 PyPI version JSON
download
home_pagehttps://github.com/williamxhero/openlimitHW
SummaryRate limiter for the OpenAI API (modified by HW)
upload_time2023-07-14 08:33:54
maintainer
docs_urlNone
authorwilliamxhero
requires_python>=3
licenseMIT
keywords openai rate-limit limit api request token leaky-bucket gcra redis asyncio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # openlimitHW

简单高效的 OpenAI API 速率限制器。它可以:

- 处理 _请求_ 和 _令牌_ 限制
- 协调多个 API KEY

## 安装

您可以使用 pip 安装 `openlimitHW`:

```bash
$ pip install openlimitHW
```

## 使用

### 定义速率限制

首先,为您使用的 OpenAI 模型定义速率限制。例如:

```python
from openlimit import ChatRateLimiter

rate_limiter = ChatRateLimiter(request_limit=3, token_limit=50000)
```
这为chat completion model(例如 gpt-4,gpt-3.5-turbo)设置了速率限制。`openlimit` 提供了不同的速率限制器对象,用于不同的 OpenAI 模型,所有对象都具有相同的参数:`request_limit` 和 `token_limit`。两种限制都是 每分钟 的量,可能因用户而异。

### 异步请求

速率限制也可以用于异步请求:

```python
async def call_openai():
    chat_params = { 
        "model": "gpt-4", 
        "messages": [{"role": "user", "content": "Hello!"}]
    }

    async with rate_limiter.limit(**chat_params):
        response = await openai.ChatCompletion.acreate(**chat_params)
        rate_limiter.update(response)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/williamxhero/openlimitHW",
    "name": "openlimitHW",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "openai,rate-limit,limit,api,request,token,leaky-bucket,gcra,redis,asyncio",
    "author": "williamxhero",
    "author_email": "williamxhero <williamxhero@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/2c/94/0f648fc5e04fc9cbbdf28c7b876d50d00cfe75c7f17453d526304e545715/openlimitHW-0.5.4.tar.gz",
    "platform": null,
    "description": "# openlimitHW\r\n\r\n\u7b80\u5355\u9ad8\u6548\u7684 OpenAI API \u901f\u7387\u9650\u5236\u5668\u3002\u5b83\u53ef\u4ee5\uff1a\r\n\r\n- \u5904\u7406 _\u8bf7\u6c42_ \u548c _\u4ee4\u724c_ \u9650\u5236\r\n- \u534f\u8c03\u591a\u4e2a API KEY\r\n\r\n## \u5b89\u88c5\r\n\r\n\u60a8\u53ef\u4ee5\u4f7f\u7528 pip \u5b89\u88c5 `openlimitHW`\uff1a\r\n\r\n```bash\r\n$ pip install openlimitHW\r\n```\r\n\r\n## \u4f7f\u7528\r\n\r\n### \u5b9a\u4e49\u901f\u7387\u9650\u5236\r\n\r\n\u9996\u5148\uff0c\u4e3a\u60a8\u4f7f\u7528\u7684 OpenAI \u6a21\u578b\u5b9a\u4e49\u901f\u7387\u9650\u5236\u3002\u4f8b\u5982\uff1a\r\n\r\n```python\r\nfrom openlimit import ChatRateLimiter\r\n\r\nrate_limiter = ChatRateLimiter(request_limit=3, token_limit=50000)\r\n```\r\n\u8fd9\u4e3achat completion model\uff08\u4f8b\u5982 gpt-4\uff0cgpt-3.5-turbo\uff09\u8bbe\u7f6e\u4e86\u901f\u7387\u9650\u5236\u3002`openlimit` \u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u901f\u7387\u9650\u5236\u5668\u5bf9\u8c61\uff0c\u7528\u4e8e\u4e0d\u540c\u7684 OpenAI \u6a21\u578b\uff0c\u6240\u6709\u5bf9\u8c61\u90fd\u5177\u6709\u76f8\u540c\u7684\u53c2\u6570\uff1a`request_limit` \u548c `token_limit`\u3002\u4e24\u79cd\u9650\u5236\u90fd\u662f \u6bcf\u5206\u949f \u7684\u91cf\uff0c\u53ef\u80fd\u56e0\u7528\u6237\u800c\u5f02\u3002\r\n\r\n### \u5f02\u6b65\u8bf7\u6c42\r\n\r\n\u901f\u7387\u9650\u5236\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5f02\u6b65\u8bf7\u6c42\uff1a\r\n\r\n```python\r\nasync def call_openai():\r\n    chat_params = { \r\n        \"model\": \"gpt-4\", \r\n        \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]\r\n    }\r\n\r\n    async with rate_limiter.limit(**chat_params):\r\n        response = await openai.ChatCompletion.acreate(**chat_params)\r\n        rate_limiter.update(response)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Rate limiter for the OpenAI API (modified by HW)",
    "version": "0.5.4",
    "project_urls": {
        "Homepage": "https://github.com/williamxhero/openlimitHW"
    },
    "split_keywords": [
        "openai",
        "rate-limit",
        "limit",
        "api",
        "request",
        "token",
        "leaky-bucket",
        "gcra",
        "redis",
        "asyncio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3762a60884a16bf30f9921abb0b3da0e68d3391ab985b8312172a5c3412c16bf",
                "md5": "e93f72ed4aa323101b7db04816ca9b72",
                "sha256": "9b455335471c899e85b88ba5f7ee2eecc4afb72ae1e6417da77d5db996584afa"
            },
            "downloads": -1,
            "filename": "openlimitHW-0.5.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e93f72ed4aa323101b7db04816ca9b72",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 20747,
            "upload_time": "2023-07-14T08:33:50",
            "upload_time_iso_8601": "2023-07-14T08:33:50.891256Z",
            "url": "https://files.pythonhosted.org/packages/37/62/a60884a16bf30f9921abb0b3da0e68d3391ab985b8312172a5c3412c16bf/openlimitHW-0.5.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c940f648fc5e04fc9cbbdf28c7b876d50d00cfe75c7f17453d526304e545715",
                "md5": "d9e3271214ae33271b3cc07c26bffca1",
                "sha256": "9a667dddf8a5bfd4a9310f62edb724dfed2b69a8994b1958cbbc45469350bad1"
            },
            "downloads": -1,
            "filename": "openlimitHW-0.5.4.tar.gz",
            "has_sig": false,
            "md5_digest": "d9e3271214ae33271b3cc07c26bffca1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 19718,
            "upload_time": "2023-07-14T08:33:54",
            "upload_time_iso_8601": "2023-07-14T08:33:54.113758Z",
            "url": "https://files.pythonhosted.org/packages/2c/94/0f648fc5e04fc9cbbdf28c7b876d50d00cfe75c7f17453d526304e545715/openlimitHW-0.5.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-14 08:33:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "williamxhero",
    "github_project": "openlimitHW",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "openlimithw"
}
        
Elapsed time: 0.08695s