Metadata-Version: 2.1
Name: llm-kira
Version: 0.0.6
Summary: chatbot client for llm
Home-page: https://github.com/sudoskys/llm_kira
License: LGPL-2.1-or-later
Author: sudoskys
Author-email: coldlando@hotmail.com
Maintainer: sudoskys
Maintainer-email: coldlando@hotmail.com
Requires-Python: >=3.8,<4.0
Classifier: License :: OSI Approved
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: beautifulsoup4 (>=4.11.1,<5.0.0)
Requires-Dist: elara (>=0.5.4,<0.6.0)
Requires-Dist: httpx (>=0.23.1,<0.24.0)
Requires-Dist: jieba (>=0.42.1,<0.43.0)
Requires-Dist: loguru (>=0.6.0,<0.7.0)
Requires-Dist: nltk (>=3.8,<4.0)
Requires-Dist: numpy (>=1.24.1,<2.0.0)
Requires-Dist: openai-async (>=0.0.2,<0.0.3)
Requires-Dist: pillow (>=9.3.0,<10.0.0)
Requires-Dist: pydantic (>=1.10.4,<2.0.0)
Requires-Dist: redis (>=4.4.0,<5.0.0)
Requires-Dist: tiktoken (>=0.1.2,<0.2.0)
Project-URL: Repository, https://github.com/sudoskys/llm_kira
Description-Content-Type: text/markdown

# llm-kira

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

Building ChatBot with LLMs.Using `async` requests.

There are comprehensive examples of use in `test/usage_tmp.py`.

> Contributors welcomed.

## 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

SEE `./test` for More Exp!

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

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.MemoryManger(profile=conversation)
chat_client = receiver.ChatBot(profile=conversation,
                               memory_manger=mem,
                               optimizer=Optimizer.SinglePoint,
                               llm_model=llm)


async def chat():
    promptManger = receiver.PromptManger(profile=conversation,
                                         connect_words="\n",
                                         )
    promptManger.insert(item=PromptItem(start=conversation.start_name, text="我的号码是 1596321"))
    response = await chat_client.predict(llm_param=OpenAiParam(model_name="text-davinci-003", n=2, best_of=2),
                                         prompt=promptManger,
                                         predict_tokens=500,
                                         increase="外部增强:每句话后面都要带 “喵”",
                                         )
    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}---")

    promptManger.clean()
    promptManger.insert(item=PromptItem(start=conversation.start_name, text="我的号码是多少？"))
    response = await chat_client.predict(llm_param=OpenAiParam(model_name="text-davinci-003"),
                                         prompt=promptManger,
                                         predict_tokens=500,
                                         increase="外部增强:每句话后面都要带 “喵”",
                                         # parse_reply=None
                                         )
    _info = "parse_reply 回调会处理 llm 的回复字段，比如 list 等，传入list，传出 str 的回复。必须是 str。",
    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

```

