llm-kira


Namellm-kira JSON
Version 0.2.4 PyPI version JSON
download
home_pagehttps://github.com/sudoskys/llm_kira
Summarychatbot client for llm
upload_time2023-02-03 16:45:15
maintainersudoskys
docs_urlNone
authorsudoskys
requires_python>=3.8,<4.0
licenseLGPL-2.1-or-later
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # llm-kira

A refactored version of the `openai-kira` specification. Use redis or a file database.

Building ChatBot with LLMs.Using `async` requests.

> Contributors welcomed.

## Features

* safely cut context
* usage
* async request api / curl
* multi-Api Key load
* self-design callback

## Basic Use

`pip install -U llm-kira`

**Init**

```python
import llm_kira

llm_kira.setting.redisSetting = llm_kira.setting.RedisConfig(host="localhost",
                                                             port=6379,
                                                             db=0,
                                                             password=None)
llm_kira.setting.dbFile = "client_memory.db"
llm_kira.setting.proxyUrl = None  # "127.0.0.1"

# Plugin
llm_kira.setting.webServerUrlFilter = False
llm_kira.setting.webServerStopSentence = ["广告", "营销号"]  # 有默认值
```

## Demo

**More examples of use in `test/test.py`.**

Take `openai` as an example

```python
import asyncio
import random
import llm_kira
from llm_kira.client import Optimizer
from llm_kira.client.types import PromptItem
from llm_kira.client.llms.openai import OpenAiParam
from typing import List

openaiApiKey = ["key1", "key2"]
openaiApiKey: List[str]

receiver = llm_kira.client
conversation = receiver.Conversation(
    start_name="Human:",
    restart_name="AI:",
    conversation_id=10093,  # random.randint(1, 10000000),
)

llm = llm_kira.client.llms.OpenAi(
    profile=conversation,
    api_key=openaiApiKey,
    token_limit=3700,
    auto_penalty=False,
    call_func=None,
)

mem = receiver.MemoryManager(profile=conversation)
chat_client = receiver.ChatBot(profile=conversation,
                               memory_manger=mem,
                               optimizer=Optimizer.SinglePoint,
                               llm_model=llm)


async def chat():
    promptManager = receiver.PromptManager(profile=conversation,
                                         connect_words="\n",
                                         template="Templates, custom prefixes"
                                         )
    promptManager.insert(item=PromptItem(start=conversation.start_name, text="My id is 1596321"))
    response = await chat_client.predict(llm_param=OpenAiParam(model_name="text-davinci-003", n=2, best_of=2),
                                         prompt=promptManager,
                                         predict_tokens=500,
                                         increase="External enhancements, or searched result",
                                         )
    print(f"id {response.conversation_id}")
    print(f"ask {response.ask}")
    print(f"reply {response.reply}")
    print(f"usage:{response.llm.usage}")
    print(f"usage:{response.llm.raw}")
    print(f"---{response.llm.time}---")

    promptManager.clean()
    promptManager.insert(item=PromptItem(start=conversation.start_name, text="Whats my id?"))
    response = await chat_client.predict(llm_param=OpenAiParam(model_name="text-davinci-003"),
                                         prompt=promptManager,
                                         predict_tokens=500,
                                         increase="外部增强:每句话后面都要带 “喵”",
                                         # parse_reply=None
                                         )
    _info = "parse_reply 函数回调会处理 llm 的回复字段,比如 list 等,传入list,传出 str 的回复。必须是 str。"
    _info2 = "The parse_reply function callback handles the reply fields of llm, such as list, etc. Pass in list and pass out str for the reply."
    print(f"id {response.conversation_id}")
    print(f"ask {response.ask}")
    print(f"reply {response.reply}")
    print(f"usage:{response.llm.usage}")
    print(f"usage:{response.llm.raw}")
    print(f"---{response.llm.time}---")


asyncio.run(chat())
```

## Frame

```
├── client
│      ├── agent.py  //profile class
│      ├── anchor.py // client etc.
│      ├── enhance.py // web search etc.
│      ├── __init__.py
│      ├── llm.py // llm func.
│      ├── module  // plugin for enhance
│      ├── Optimizer.py // memory Optimizer (cutter
│      ├── pot.py // test cache
│      ├── test_module.py // test plugin
│      ├── text_analysis_tools // nlp support
│      ├── types.py // data class
│      └── vocab.json // cache?
├── __init__.py
├── openai  // func
│      ├── api // data
│      ├── __init__.py
│      └── resouce  // func
├── requirements.txt
└── utils  // utils... tools...
    ├── chat.py
    ├── data.py
    ├── fatlangdetect //lang detect
    ├── langdetect
    ├── network.py
    └── setting.py

```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sudoskys/llm_kira",
    "name": "llm-kira",
    "maintainer": "sudoskys",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "coldlando@hotmail.com",
    "keywords": "",
    "author": "sudoskys",
    "author_email": "coldlando@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cb/e8/740bec791f6eb72ca03addba189d5e0b347a64fa0fce5a23e1c38f7cfbe2/llm_kira-0.2.4.tar.gz",
    "platform": null,
    "description": "# llm-kira\n\nA refactored version of the `openai-kira` specification. Use redis or a file database.\n\nBuilding ChatBot with LLMs.Using `async` requests.\n\n> Contributors welcomed.\n\n## Features\n\n* safely cut context\n* usage\n* async request api / curl\n* multi-Api Key load\n* self-design callback\n\n## Basic Use\n\n`pip install -U llm-kira`\n\n**Init**\n\n```python\nimport llm_kira\n\nllm_kira.setting.redisSetting = llm_kira.setting.RedisConfig(host=\"localhost\",\n                                                             port=6379,\n                                                             db=0,\n                                                             password=None)\nllm_kira.setting.dbFile = \"client_memory.db\"\nllm_kira.setting.proxyUrl = None  # \"127.0.0.1\"\n\n# Plugin\nllm_kira.setting.webServerUrlFilter = False\nllm_kira.setting.webServerStopSentence = [\"\u5e7f\u544a\", \"\u8425\u9500\u53f7\"]  # \u6709\u9ed8\u8ba4\u503c\n```\n\n## Demo\n\n**More examples of use in `test/test.py`.**\n\nTake `openai` as an example\n\n```python\nimport asyncio\nimport random\nimport llm_kira\nfrom llm_kira.client import Optimizer\nfrom llm_kira.client.types import PromptItem\nfrom llm_kira.client.llms.openai import OpenAiParam\nfrom typing import List\n\nopenaiApiKey = [\"key1\", \"key2\"]\nopenaiApiKey: List[str]\n\nreceiver = llm_kira.client\nconversation = receiver.Conversation(\n    start_name=\"Human:\",\n    restart_name=\"AI:\",\n    conversation_id=10093,  # random.randint(1, 10000000),\n)\n\nllm = llm_kira.client.llms.OpenAi(\n    profile=conversation,\n    api_key=openaiApiKey,\n    token_limit=3700,\n    auto_penalty=False,\n    call_func=None,\n)\n\nmem = receiver.MemoryManager(profile=conversation)\nchat_client = receiver.ChatBot(profile=conversation,\n                               memory_manger=mem,\n                               optimizer=Optimizer.SinglePoint,\n                               llm_model=llm)\n\n\nasync def chat():\n    promptManager = receiver.PromptManager(profile=conversation,\n                                         connect_words=\"\\n\",\n                                         template=\"Templates, custom prefixes\"\n                                         )\n    promptManager.insert(item=PromptItem(start=conversation.start_name, text=\"My id is 1596321\"))\n    response = await chat_client.predict(llm_param=OpenAiParam(model_name=\"text-davinci-003\", n=2, best_of=2),\n                                         prompt=promptManager,\n                                         predict_tokens=500,\n                                         increase=\"External enhancements, or searched result\",\n                                         )\n    print(f\"id {response.conversation_id}\")\n    print(f\"ask {response.ask}\")\n    print(f\"reply {response.reply}\")\n    print(f\"usage:{response.llm.usage}\")\n    print(f\"usage:{response.llm.raw}\")\n    print(f\"---{response.llm.time}---\")\n\n    promptManager.clean()\n    promptManager.insert(item=PromptItem(start=conversation.start_name, text=\"Whats my id\uff1f\"))\n    response = await chat_client.predict(llm_param=OpenAiParam(model_name=\"text-davinci-003\"),\n                                         prompt=promptManager,\n                                         predict_tokens=500,\n                                         increase=\"\u5916\u90e8\u589e\u5f3a:\u6bcf\u53e5\u8bdd\u540e\u9762\u90fd\u8981\u5e26 \u201c\u55b5\u201d\",\n                                         # parse_reply=None\n                                         )\n    _info = \"parse_reply \u51fd\u6570\u56de\u8c03\u4f1a\u5904\u7406 llm \u7684\u56de\u590d\u5b57\u6bb5\uff0c\u6bd4\u5982 list \u7b49\uff0c\u4f20\u5165list\uff0c\u4f20\u51fa str \u7684\u56de\u590d\u3002\u5fc5\u987b\u662f str\u3002\"\n    _info2 = \"The parse_reply function callback handles the reply fields of llm, such as list, etc. Pass in list and pass out str for the reply.\"\n    print(f\"id {response.conversation_id}\")\n    print(f\"ask {response.ask}\")\n    print(f\"reply {response.reply}\")\n    print(f\"usage:{response.llm.usage}\")\n    print(f\"usage:{response.llm.raw}\")\n    print(f\"---{response.llm.time}---\")\n\n\nasyncio.run(chat())\n```\n\n## Frame\n\n```\n\u251c\u2500\u2500 client\n\u2502      \u251c\u2500\u2500 agent.py  //profile class\n\u2502      \u251c\u2500\u2500 anchor.py // client etc.\n\u2502      \u251c\u2500\u2500 enhance.py // web search etc.\n\u2502      \u251c\u2500\u2500 __init__.py\n\u2502      \u251c\u2500\u2500 llm.py // llm func.\n\u2502      \u251c\u2500\u2500 module  // plugin for enhance\n\u2502      \u251c\u2500\u2500 Optimizer.py // memory Optimizer (cutter\n\u2502      \u251c\u2500\u2500 pot.py // test cache\n\u2502      \u251c\u2500\u2500 test_module.py // test plugin\n\u2502      \u251c\u2500\u2500 text_analysis_tools // nlp support\n\u2502      \u251c\u2500\u2500 types.py // data class\n\u2502      \u2514\u2500\u2500 vocab.json // cache?\n\u251c\u2500\u2500 __init__.py\n\u251c\u2500\u2500 openai  // func\n\u2502      \u251c\u2500\u2500 api // data\n\u2502      \u251c\u2500\u2500 __init__.py\n\u2502      \u2514\u2500\u2500 resouce  // func\n\u251c\u2500\u2500 requirements.txt\n\u2514\u2500\u2500 utils  // utils... tools...\n    \u251c\u2500\u2500 chat.py\n    \u251c\u2500\u2500 data.py\n    \u251c\u2500\u2500 fatlangdetect //lang detect\n    \u251c\u2500\u2500 langdetect\n    \u251c\u2500\u2500 network.py\n    \u2514\u2500\u2500 setting.py\n\n```\n\n",
    "bugtrack_url": null,
    "license": "LGPL-2.1-or-later",
    "summary": "chatbot client for llm",
    "version": "0.2.4",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a09f4e25ecaaffeb6ed2be340fc3ea74096c5a7a203edba57806ce98d69d4592",
                "md5": "9c1459e1ee4617c3efca479c6fa188fd",
                "sha256": "60df0e919ca4a166d10dae8d4cc7f2621673c87f9768aa667f06339964e47f23"
            },
            "downloads": -1,
            "filename": "llm_kira-0.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9c1459e1ee4617c3efca479c6fa188fd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 6938149,
            "upload_time": "2023-02-03T16:45:13",
            "upload_time_iso_8601": "2023-02-03T16:45:13.625974Z",
            "url": "https://files.pythonhosted.org/packages/a0/9f/4e25ecaaffeb6ed2be340fc3ea74096c5a7a203edba57806ce98d69d4592/llm_kira-0.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cbe8740bec791f6eb72ca03addba189d5e0b347a64fa0fce5a23e1c38f7cfbe2",
                "md5": "a707295afae65124d8b2c227cd5324fa",
                "sha256": "5305afd77f4a3ef66b52c5d875212e2f846b347275c8a8f52b9d0052a5f30975"
            },
            "downloads": -1,
            "filename": "llm_kira-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "a707295afae65124d8b2c227cd5324fa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 6810660,
            "upload_time": "2023-02-03T16:45:15",
            "upload_time_iso_8601": "2023-02-03T16:45:15.915918Z",
            "url": "https://files.pythonhosted.org/packages/cb/e8/740bec791f6eb72ca03addba189d5e0b347a64fa0fce5a23e1c38f7cfbe2/llm_kira-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-03 16:45:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "sudoskys",
    "github_project": "llm_kira",
    "lcname": "llm-kira"
}
        
Elapsed time: 0.11674s