Package: openai-kira
openai-kiraOpenai GPT3 ChatBot 框架包，在未公开前快速实现类 ChatGPT接入（公开后就接入chatGPT），打包成依赖的玩具。提供 redis 和 文件数据库
两个选择。Usepip install -U openai-kirainitimportopenai_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=Falseopenai_kira.setting.webServerStopSentence=["广告","营销号"]ExpSEE./testfor More Exp!importasyncioimportopenai_kirafromopenai_kiraimportChatprint(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:",)asyncdefmain():response=awaitreceiver.get_chat_response(model="text-davinci-003",prompt="你好",max_tokens=500,role="你扮演...",web_enhance_server={"time":""})print(response)asyncio.run(main())importasyncioimportopenai_kiraprint(openai_kira.RedisConfig())openai_kira.setting.openaiApiKey=["key"]print(openai_kira.setting.openaiApiKey)asyncdefmain():try:response=awaitopenai_kira.Completion().create(model="text-davinci-003",prompt="Say this is a test",temperature=0,max_tokens=20)# TESTprint(response)print(type(response))exceptExceptionase:print(e)if"Incorrect API key provided"ine:print("OK")else:print("NO")asyncio.run(main())PluginTablepluginsdescvalue/serverusetimenow time"",no need明昨今天....weekweek time"",no need周几.....searchWeb Search["some.com?searchword={}"],must need查询你知道len<80 / end with?len<15duckgoWeb Search"",no need,but needpip install duckduckgo_search查询你知道len<80 / end with?len<15detailsanswer with steps"",no needAsk for helphow toPlugin devThere 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 InjectionUse""[]to emphasise content.ExpFirst create a file inopenai_kira/Chat/module/pluginwithout underscores (_) in the file name.Templatefrom..platformimportChatPlugin,PluginConfigfrom._plugin_toolimportPromptToolimportosfromloguruimportloggermodulename=os.path.basename(__file__).strip(".py")@ChatPlugin.plugin_register(modulename)classWeek(object):def__init__(self):self._server=Noneself._text=Noneself._time=["time","多少天","几天","时间","几点","今天","昨天","明天","几月","几月","几号","几个月","天前"]defrequirements(self):return[]asyncdefcheck(self,params:PluginConfig)->bool:ifPromptTool.isStrIn(prompt=params.text,keywords=self._time):returnTruereturnFalseasyncdefprocess(self,params:PluginConfig)->list:_return=[]self._text=params.text# 校验ifnotall([self._text]):return[]# GETfromdatetimeimportdatetime,timedelta,timezoneutc_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}")# LOGGERlogger.trace(_return)return_returnopenai_kira/Chat/module/plugin/_plugin_tool.pyprovides some tool classes, PR is welcomeTestingYou cannot test directly from within the module package, please run theopenai_kira/Chat/test_module.pyfile to test
the module, with the prompt matching check.Alternatively, you can safely usefrom 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.pyEULA(end-user-license-agreement)cn自行因为不当操作导致的损失。本项目并非官方项目。因为安全事故导致的损失我不负责。拒绝未经授权的专利/软著相关用途。enthe damage caused by improper operation on its own.This is not an official project.I am not responsible for any damage caused by safety incidents.