From 7fe0ccea8ec44a5a661bfb84dde56c38d2e20ecf Mon Sep 17 00:00:00 2001 From: hibobmaster <32976627+hibobmaster@users.noreply.github.com> Date: Sun, 17 Sep 2023 23:48:21 +0800 Subject: [PATCH] Fix docker build --- Dockerfile | 2 +- src/bot.py | 4 ++- src/chatgpt_bing.py | 81 --------------------------------------------- src/main.py | 28 ++++++++-------- 4 files changed, 18 insertions(+), 97 deletions(-) delete mode 100644 src/chatgpt_bing.py diff --git a/Dockerfile b/Dockerfile index 06794e3..d92d991 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.11-alpine as base FROM base as pybuilder # RUN sed -i 's|v3\.\d*|edge|' /etc/apk/repositories -RUN apk update && apk add --no-cache olm-dev gcc musl-dev libmagic libffi-dev +RUN apk update && apk add --no-cache olm-dev gcc musl-dev libmagic libffi-dev cmake make g++ git python3-dev COPY requirements.txt /requirements.txt RUN pip install -U pip setuptools wheel && pip install --user -r /requirements.txt && rm /requirements.txt diff --git a/src/bot.py b/src/bot.py index f4e3b1e..6af10f6 100644 --- a/src/bot.py +++ b/src/bot.py @@ -116,6 +116,8 @@ def __init__( self.base_path = Path(os.path.dirname(__file__)).parent + if lc_admin is not None: + lc_admin = list(filter(None, lc_admin.split(","))) self.lc_admin = lc_admin self.lc_cache = {} if self.lc_admin is not None: @@ -1372,7 +1374,7 @@ async def help(self, room_id, reply_to_event_id, sender_id, user_message): help_info = ( "!gpt [prompt], generate a one time response without context conversation\n" + "!chat [prompt], chat with context conversation\n" - + "!pic [prompt], Image generation by Microsoft Bing\n" + + "!pic [prompt], Image generation by DALLĀ·E or LocalAI or stable-diffusion-webui\n" # noqa: E501 + "!new + chat, start a new conversation \n" + "!lc [prompt], chat using langchain api\n" + "!help, help message" diff --git a/src/chatgpt_bing.py b/src/chatgpt_bing.py deleted file mode 100644 index 3feb879..0000000 --- a/src/chatgpt_bing.py +++ /dev/null @@ -1,81 +0,0 @@ -import aiohttp -from log import getlogger - -logger = getlogger() - - -class GPTBOT: - def __init__( - self, - api_endpoint: str, - session: aiohttp.ClientSession, - ) -> None: - self.api_endpoint = api_endpoint - self.session = session - - async def queryBing(self, payload: dict) -> dict: - resp = await self.session.post(url=self.api_endpoint, json=payload, timeout=300) - status_code = resp.status - if not status_code == 200: - logger.warning(str(resp.reason)) - raise Exception(str(resp.reason)) - return await resp.json() - - async def queryChatGPT(self, payload: dict) -> dict: - resp = await self.session.post(url=self.api_endpoint, json=payload, timeout=300) - status_code = resp.status - if not status_code == 200: - logger.warning(str(resp.reason)) - raise Exception(str(resp.reason)) - return await resp.json() - - -async def test_chatgpt(): - session = aiohttp.ClientSession() - gptbot = GPTBOT(api_endpoint="http://localhost:3000/conversation", session=session) - payload = {} - while True: - prompt = input("Bob: ") - payload["message"] = prompt - payload.update( - { - "clientOptions": { - "clientToUse": "chatgpt", - }, - }, - ) - resp = await gptbot.queryChatGPT(payload) - content = resp["response"] - payload["conversationId"] = resp["conversationId"] - payload["parentMessageId"] = resp["messageId"] - print("GPT: " + content) - - -async def test_bing(): - session = aiohttp.ClientSession() - gptbot = GPTBOT(api_endpoint="http://localhost:3000/conversation", session=session) - payload = {} - while True: - prompt = input("Bob: ") - payload["message"] = prompt - payload.update( - { - "clientOptions": { - "clientToUse": "bing", - }, - }, - ) - resp = await gptbot.queryBing(payload) - content = "".join( - [body["text"] for body in resp["details"]["adaptiveCards"][0]["body"]], - ) - payload["conversationSignature"] = resp["conversationSignature"] - payload["conversationId"] = resp["conversationId"] - payload["clientId"] = resp["clientId"] - payload["invocationId"] = resp["invocationId"] - print("Bing: " + content) - - -# if __name__ == "__main__": -# asyncio.run(test_chatgpt()) -# asyncio.run(test_bing()) diff --git a/src/main.py b/src/main.py index 1e1eed6..60bddf8 100644 --- a/src/main.py +++ b/src/main.py @@ -33,17 +33,17 @@ async def main(): openai_api_key=config.get("openai_api_key"), gpt_api_endpoint=config.get("gpt_api_endpoint"), gpt_model=config.get("gpt_model"), - max_tokens=int(config.get("max_tokens")), - top_p=float(config.get("top_p")), - presence_penalty=float(config.get("presence_penalty")), - frequency_penalty=float(config.get("frequency_penalty")), - reply_count=int(config.get("reply_count")), + max_tokens=config.get("max_tokens"), + top_p=config.get("top_p"), + presence_penalty=config.get("presence_penalty"), + frequency_penalty=config.get("frequency_penalty"), + reply_count=config.get("reply_count"), system_prompt=config.get("system_prompt"), - temperature=float(config.get("temperature")), + temperature=config.get("temperature"), lc_admin=config.get("lc_admin"), image_generation_endpoint=config.get("image_generation_endpoint"), image_generation_backend=config.get("image_generation_backend"), - timeout=float(config.get("timeout")), + timeout=config.get("timeout"), ) if ( config.get("import_keys_path") @@ -63,17 +63,17 @@ async def main(): openai_api_key=os.environ.get("OPENAI_API_KEY"), gpt_api_endpoint=os.environ.get("GPT_API_ENDPOINT"), gpt_model=os.environ.get("GPT_MODEL"), - max_tokens=int(os.environ.get("MAX_TOKENS")), - top_p=float(os.environ.get("TOP_P")), - presence_penalty=float(os.environ.get("PRESENCE_PENALTY")), - frequency_penalty=float(os.environ.get("FREQUENCY_PENALTY")), + max_tokens=os.environ.get("MAX_TOKENS"), + top_p=os.environ.get("TOP_P"), + presence_penalty=os.environ.get("PRESENCE_PENALTY"), + frequency_penalty=os.environ.get("FREQUENCY_PENALTY"), reply_count=int(os.environ.get("REPLY_COUNT")), system_prompt=os.environ.get("SYSTEM_PROMPT"), - temperature=float(os.environ.get("TEMPERATURE")), - lc_admin=list(filter(None, os.environ.get("LC_ADMIN").split(","))), + temperature=os.environ.get("TEMPERATURE"), + lc_admin=os.environ.get("LC_ADMIN"), image_generation_endpoint=os.environ.get("IMAGE_GENERATION_ENDPOINT"), image_generation_backend=os.environ.get("IMAGE_GENERATION_BACKEND"), - timeout=float(os.environ.get("TIMEOUT")), + timeout=os.environ.get("TIMEOUT"), ) if ( os.environ.get("IMPORT_KEYS_PATH")