openai-kira

A chat client


Keywords
chatgpt, gpt3, openai, openai-api
License
SSPL-1.0
Install
pip install openai-kira==0.3.5

Documentation

openai-kira

Openai GPT3 ChatBot ๆก†ๆžถๅŒ…๏ผŒๅœจๆœชๅ…ฌๅผ€ๅ‰ๅฟซ้€Ÿๅฎž็Žฐ็ฑป ChatGPTๆŽฅๅ…ฅ๏ผˆๅ…ฌๅผ€ๅŽๅฐฑๆŽฅๅ…ฅchatGPT๏ผ‰๏ผŒๆ‰“ๅŒ…ๆˆไพ่ต–็š„็Žฉๅ…ทใ€‚ๆไพ› redis ๅ’Œ ๆ–‡ไปถๆ•ฐๆฎๅบ“ ไธคไธช้€‰ๆ‹ฉใ€‚

Use

pip install -U openai-kira

init

import openai_kira

# 
openai_kira.setting.redisSetting = openai_kira.setting.RedisConfig()
openai_kira.setting.dbFile = "openai_msg.db"
openai_kira.setting.openaiApiKey = ["key", "key2"]
openai_kira.setting.proxyUrl = None  # "127.0.0.1"
# ๆ’ไปถ็š„่ฎพ็ฝฎ
openai_kira.setting.webServerUrlFilter = False
openai_kira.setting.webServerStopSentence = ["ๅนฟๅ‘Š", "่ฅ้”€ๅท"]

Exp

SEE ./test for More Exp!

import asyncio

import openai_kira
from openai_kira import Chat

print(openai_kira.RedisConfig())
openai_kira.setting.openaiApiKey = ["key"]

receiver = Chat.Chatbot(
    conversation_id=10086,
    call_func=None,  # Api_keys.pop_api_key,
    start_sequ="Ai:",
    restart_sequ="Human:",
)


async def main():
    response = await receiver.get_chat_response(model="text-davinci-003",
                                                prompt="ไฝ ๅฅฝ",
                                                max_tokens=500,
                                                role="ไฝ ๆ‰ฎๆผ”...",
                                                web_enhance_server={"time": ""}
                                                )
    print(response)


asyncio.run(main())
import asyncio
import openai_kira

print(openai_kira.RedisConfig())
openai_kira.setting.openaiApiKey = ["key"]
print(openai_kira.setting.openaiApiKey)


async def main():
    try:
        response = await openai_kira.Completion().create(model="text-davinci-003",
                                                         prompt="Say this is a test",
                                                         temperature=0,
                                                         max_tokens=20)
        # TEST
        print(response)
        print(type(response))
    except Exception as e:
        print(e)
        if "Incorrect API key provided" in e:
            print("OK")
        else:
            print("NO")


asyncio.run(main())

Plugin

Table

plugins desc value/server use
time now time "",no need ๆ˜Žๆ˜จไปŠๅคฉ....
week week time "",no need ๅ‘จๅ‡  .....
search Web Search ["some.com?searchword={}"],must need ๆŸฅ่ฏข ไฝ ็Ÿฅ้“ len<80 / end with?len<15
duckgo Web Search "",no need,but need pip install duckduckgo_search ๆŸฅ่ฏข ไฝ ็Ÿฅ้“ len<80 / end with?len<15
details answer with steps "",no need Ask for help how to

Plugin dev

There is a middleware between the memory pool and the analytics that provides some networked retrieval support and operational support. It can be spiked with services that interface to other Api's.

Prompt Injection

Use "" [] to emphasise content.

Exp

First create a file in openai_kira/Chat/module/plugin without underscores (_) in the file name.

Template

from ..platform import ChatPlugin, PluginConfig
from ._plugin_tool import PromptTool
import os
from loguru import logger

modulename = os.path.basename(__file__).strip(".py")


@ChatPlugin.plugin_register(modulename)
class Week(object):
    def __init__(self):
        self._server = None
        self._text = None
        self._time = ["time", "ๅคšๅฐ‘ๅคฉ", "ๅ‡ ๅคฉ", "ๆ—ถ้—ด", "ๅ‡ ็‚น", "ไปŠๅคฉ", "ๆ˜จๅคฉ", "ๆ˜Žๅคฉ", "ๅ‡ ๆœˆ", "ๅ‡ ๆœˆ", "ๅ‡ ๅท",
                      "ๅ‡ ไธชๆœˆ",
                      "ๅคฉๅ‰"]

    def requirements(self):
        return []

    async def check(self, params: PluginConfig) -> bool:
        if PromptTool.isStrIn(prompt=params.text, keywords=self._time):
            return True
        return False

    async def process(self, params: PluginConfig) -> list:
        _return = []
        self._text = params.text
        # ๆ ก้ชŒ
        if not all([self._text]):
            return []
        # GET
        from datetime import datetime, timedelta, timezone
        utc_dt = datetime.utcnow().replace(tzinfo=timezone.utc)
        bj_dt = utc_dt.astimezone(timezone(timedelta(hours=8)))
        now = bj_dt.strftime("%Y-%m-%d %H:%M")
        _return.append(f"Current Time UTC8 {now}")
        # LOGGER
        logger.trace(_return)
        return _return

openai_kira/Chat/module/plugin/_plugin_tool.py provides some tool classes, PR is welcome

Testing

You cannot test directly from within the module package, please run the openai_kira/Chat/test_module.py file to test the module, with the prompt matching check.

Alternatively, you can safely use from loguru import logger + logger.trace(_return) in the module to debug the module variables and the trace level logs will not be output by the production environment.

็ป“ๆž„

.
โ””โ”€โ”€ openai_kira
โ”œโ”€โ”€ api
โ”‚ โ”œโ”€โ”€ api_url.json
โ”‚ โ”œโ”€โ”€ api_utils.py
โ”‚ โ”œโ”€โ”€ network.py
โ”œโ”€โ”€ Chat
โ”‚ โ”œโ”€โ”€ __init__.py
โ”‚ โ”œโ”€โ”€ module
โ”‚ โ”œโ”€โ”€ Summer.py
โ”‚ โ”œโ”€โ”€ test_module.py
โ”‚ โ”œโ”€โ”€ text_analysis_tools
โ”‚ โ””โ”€โ”€ vocab.json
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ resouce
โ”‚ โ”œโ”€โ”€ completion.py
โ”‚ โ”œโ”€โ”€ __init__.py
โ””โ”€โ”€ utils
โ”œโ”€โ”€ data.py
โ”œโ”€โ”€ Network.py
โ””โ”€โ”€ Talk.py

EULA(end-user-license-agreement)

cn

  1. ่‡ช่กŒๅ› ไธบไธๅฝ“ๆ“ไฝœๅฏผ่‡ด็š„ๆŸๅคฑใ€‚
  2. ๆœฌ้กน็›ฎๅนถ้žๅฎ˜ๆ–น้กน็›ฎใ€‚
  3. ๅ› ไธบๅฎ‰ๅ…จไบ‹ๆ•…ๅฏผ่‡ด็š„ๆŸๅคฑๆˆ‘ไธ่ดŸ่ดฃใ€‚
  4. ๆ‹’็ปๆœช็ปๆŽˆๆƒ็š„ไธ“ๅˆฉ/่ฝฏ่‘—็›ธๅ…ณ็”จ้€”ใ€‚

en

  1. the damage caused by improper operation on its own.
  2. This is not an official project.
  3. I am not responsible for any damage caused by safety incidents.