Skip to content

Commit

Permalink
feat:重整依赖库
Browse files Browse the repository at this point in the history
  • Loading branch information
sudoskys committed Dec 15, 2022
1 parent 36820db commit aaa03ea
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 310 deletions.
15 changes: 7 additions & 8 deletions App/Event.py
Expand Up @@ -128,16 +128,15 @@ async def load_response(user, group,
# 请求
try:
import openai_async
openai_async.api_key = key
# Openai_python
# import openai
# openai.api_key = key
# response = openai.Completion.create(model="text-davinci-003", prompt=str(prompt), temperature=0,
# max_tokens=int(_csonfig["token_limit"]))
if method == "write":
# OPENAI
response = await openai_async.Completion(api_key=key,
call_func=Api_keys.pop_api_key
).create(
response = await openai_async.Completion(call_func=Api_keys.pop_api_key).create(
model="text-davinci-003",
prompt=str(prompt),
temperature=0.2,
Expand All @@ -153,8 +152,8 @@ async def load_response(user, group,
start_name = start_name[-10:]
if len(restart_name) > 12:
restart_name = restart_name[-10:]
receiver = Chat.Chatbot(api_key=key,
conversation_id=_cid,
receiver = Chat.Chatbot(
conversation_id=int(_cid),
call_func=Api_keys.pop_api_key,
start_sequ=start_name,
restart_sequ=restart_name,
Expand Down Expand Up @@ -297,7 +296,7 @@ async def Text(bot, message, config, reset: bool = False):
_name = f"{message.from_user.last_name}"
_req = await Reply.load_response(user=message.from_user.id,
group=message.chat.id,
key=Api_keys.get_key()["OPENAI_API_KEY"],
key=Api_keys.get_key("./Config/api_keys.json")["OPENAI_API_KEY"],
prompt=_prompt,
method=types,
restart_name=_name,
Expand Down Expand Up @@ -334,7 +333,7 @@ async def private_Chat(bot, message, config):
_name = f"{message.from_user.last_name}"
_req = await Reply.load_response(user=message.from_user.id,
group=message.chat.id,
key=Api_keys.get_key()["OPENAI_API_KEY"],
key=Api_keys.get_key("./Config/api_keys.json")["OPENAI_API_KEY"],
prompt=_prompt,
restart_name=_name,
start_name="Reply:"
Expand Down Expand Up @@ -594,7 +593,7 @@ async def Master(bot, message, config):
logger.info("SETTING:whiteGroup OFF")

if command == "/see_api_key":
keys = Api_keys.get_key()
keys = Api_keys.get_key("./Config/api_keys.json")
# 脱敏
_key = []
for i in keys["OPENAI_API_KEY"]:
Expand Down
24 changes: 18 additions & 6 deletions openai_async/Chat/__init__.py
Expand Up @@ -8,14 +8,15 @@

import json
import os
import random
import re

import openai_async
# import loguru
# import jiagu


# 基于 Completion 上层
from openai_async import Completion
from ..resouce import Completion
from .text_analysis_tools.api.keywords.tfidf import TfidfKeywords
from .text_analysis_tools.api.summarization.tfidf_summarization import TfidfSummarization
from .text_analysis_tools.api.text_similarity.simhash import SimHashSimilarity
Expand Down Expand Up @@ -200,7 +201,8 @@ def cut_ai_prompt(self, prompt: str) -> list:


class Chatbot(object):
def __init__(self, api_key, conversation_id, token_limit: int = 3500, restart_sequ: str = "\nSomeone:",
def __init__(self, api_key: str = None, conversation_id: int = 1, token_limit: int = 3500,
restart_sequ: str = "\nSomeone:",
start_sequ: str = "\nReply: ",
call_func=None):
"""
Expand All @@ -209,7 +211,17 @@ def __init__(self, api_key, conversation_id, token_limit: int = 3500, restart_se
:param conversation_id: 独立ID,每个场景需要独一个
:param call_func: 回调
"""
self._api_key = api_key
if api_key is None:
api_key = openai_async.api_key
if isinstance(api_key, list):
api_key: list
if not api_key:
raise RuntimeError("NO KEY")
api_key = random.choice(api_key)
api_key: str
self.__api_key = api_key
if not api_key:
raise RuntimeError("NO KEY")
self.conversation_id = str(conversation_id)
self._MsgFlow = MsgFlow(uid=self.conversation_id)
self._start_sequence = start_sequ
Expand Down Expand Up @@ -472,8 +484,8 @@ async def get_chat_response(self, prompt: str, max_tokens: int = 150, model: str
_prompt = _prompt[1:]
if _mk > 0:
_prompt = _header + _prompt
print(_prompt)
response = await Completion(api_key=self._api_key, call_func=self.__call_func).create(
# print(_prompt)
response = await Completion(api_key=self.__api_key, call_func=self.__call_func).create(
model=model,
prompt=_prompt,
temperature=0.9,
Expand Down
201 changes: 0 additions & 201 deletions openai_async/Chat/text_analysis_tools/LICENSE

This file was deleted.

0 comments on commit aaa03ea

Please sign in to comment.