From 84c29a5496afe72fa104ebc1ce5964a4dfe44408 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Fri, 31 May 2024 11:25:44 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20logout=20command?= =?UTF-8?q?=20to=20clear=20credentials=20in=20discord=20event=20sender?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/sender/discord/__init__.py | 14 ++++++++++++++ app/sender/discord/event.py | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/sender/discord/__init__.py b/app/sender/discord/__init__.py index 11d4552e..1bc533d6 100644 --- a/app/sender/discord/__init__.py +++ b/app/sender/discord/__init__.py @@ -37,6 +37,7 @@ save_credential, dict2markdown, learn_instruction, + logout, ) from llmkira.openapi.trigger import get_trigger_loop from ...components.credential import Credential, ProviderError @@ -319,6 +320,19 @@ async def listen_endpoint_command( ephemeral=True, ) + @client.include + @crescent.command( + dm_enabled=True, name="logout", description="clear your credential" + ) + async def listen_logout_command(ctx: crescent.Context): + reply = await logout( + uid=uid_make(__sender__, ctx.user.id), + ) + return await ctx.respond( + ephemeral=True, + content=reply, + ) + @client.include @crescent.command( dm_enabled=True, name="clear", description="clear your message history" diff --git a/app/sender/discord/event.py b/app/sender/discord/event.py index 965f9f3c..c3441dbd 100644 --- a/app/sender/discord/event.py +++ b/app/sender/discord/event.py @@ -16,7 +16,8 @@ def help_message(): `/tool` - Check all useful tools `/clear` - wipe memory of your chat `/auth` - activate a task (my power) - `/login` - login + `/login` - set credential + `/logout` - clear credential `/login_via_url` - login via url `/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env. `/learn` - set your system prompt, reset by `/learn reset` From 7fa9efa051cade4ecf168603983fe74d552e990b Mon Sep 17 00:00:00 2001 From: sudoskys Date: Fri, 31 May 2024 11:26:01 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=A7=20feat:=20add=20logout=20funct?= =?UTF-8?q?ionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added logout command to clear user credentials. --- app/sender/kook/__init__.py | 10 ++++++++++ app/sender/kook/event.py | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/sender/kook/__init__.py b/app/sender/kook/__init__.py index afecc2d1..1af93fdb 100644 --- a/app/sender/kook/__init__.py +++ b/app/sender/kook/__init__.py @@ -34,6 +34,7 @@ save_credential, dict2markdown, learn_instruction, + logout, ) from llmkira.openapi.trigger import get_trigger_loop from ...components.credential import ProviderError, Credential @@ -331,6 +332,15 @@ async def listen_login_command( type=MessageTypes.KMD, ) + @bot.command(name="logout") + async def listen_logout_command(msg: Message): + reply = await logout(uid=uid_make(__sender__, msg.author_id)) + return await msg.reply( + content=convert(reply), + is_temp=True, + type=MessageTypes.KMD, + ) + @bot.command(name="clear") async def listen_clear_command(msg: Message): await global_message_runtime.update_session( diff --git a/app/sender/kook/event.py b/app/sender/kook/event.py index 406df916..2802c999 100644 --- a/app/sender/kook/event.py +++ b/app/sender/kook/event.py @@ -35,7 +35,8 @@ def help_message(): `/tool` - Check all useful tools `/clear` - wipe memory of your chat `/auth` - activate a task (my power) - `/login` - login openai + `/login` - set credential + `/logout` - clear credential `/login_via_url` - login via provider url `/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env. `/learn` - set your system prompt, reset by `/learn reset` From a4ed6e91cac0217f49e243af81a7439e36b62e29 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Fri, 31 May 2024 11:26:17 +0800 Subject: [PATCH 3/5] :art: fix: add logout command to slack sender init file --- app/sender/slack/__init__.py | 11 +++++++++++ app/sender/slack/event.py | 1 + 2 files changed, 12 insertions(+) diff --git a/app/sender/slack/__init__.py b/app/sender/slack/__init__.py index 0714f4ce..9cf2146d 100644 --- a/app/sender/slack/__init__.py +++ b/app/sender/slack/__init__.py @@ -25,6 +25,7 @@ login, dict2markdown, learn_instruction, + logout, ) from app.setting.slack import BotSetting from llmkira.kv_manager.env import EnvManager @@ -248,6 +249,16 @@ async def listen_login_command(ack: AsyncAck, respond: AsyncRespond, command): ) return await respond(text=reply) + @bot.command(command="/logout") + async def listen_logout_command(ack: AsyncAck, respond: AsyncRespond, command): + command: SlashCommand = SlashCommand.model_validate(command) + await ack() + if not command.text: + return + _arg = command.text + reply = await logout(uid=uid_make(__sender__, command.user_id)) + return await respond(text=reply) + @bot.command(command="/env") async def listen_env_command(ack: AsyncAck, respond: AsyncRespond, command): command: SlashCommand = SlashCommand.model_validate(command) diff --git a/app/sender/slack/event.py b/app/sender/slack/event.py index 4876b8ad..2484f0f1 100644 --- a/app/sender/slack/event.py +++ b/app/sender/slack/event.py @@ -24,6 +24,7 @@ def help_message(): `/clear` - forget...you `/auth` - activate a task (my power),but outside the thread `/login` - login via url or raw +`/logout` - clear credential `/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env. `/learn` - set your system prompt, reset by `/learn reset` From e8353cd05f095379dc49c21168d5873e34dd5f15 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Fri, 31 May 2024 11:26:51 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E2=84=B9=EF=B8=8F=20fix:=20fix=20logout=20?= =?UTF-8?q?command=20not=20being=20handled=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Handle logout command in private chat - Add functionality to clear user credentials - Update help message in the chat history clearing section --- app/sender/telegram/__init__.py | 17 ++++++++++++++--- app/sender/telegram/event.py | 28 ++++++++++++++++------------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/app/sender/telegram/__init__.py b/app/sender/telegram/__init__.py index dbbb6599..9045e11e 100644 --- a/app/sender/telegram/__init__.py +++ b/app/sender/telegram/__init__.py @@ -5,12 +5,12 @@ # @Software: PyCharm from typing import Optional, Union, List +import telegramify_markdown from loguru import logger from telebot import formatting, util from telebot import types from telebot.async_telebot import AsyncTeleBot from telebot.asyncio_storage import StateMemoryStorage -from telebot.formatting import escape_markdown from telegramify_markdown import convert from app.sender.util_func import ( @@ -23,6 +23,7 @@ TimerObjectContainer, dict2markdown, learn_instruction, + logout, ) from app.setting.telegram import BotSetting from llmkira.kv_manager.env import EnvManager @@ -251,6 +252,17 @@ async def listen_login_command(message: types.Message): parse_mode="MarkdownV2", ) + @bot.message_handler(commands="logout", chat_types=["private"]) + async def listen_logout_command(message: types.Message): + logger.debug("Debug:logout command") + _cmd, _arg = parse_command(command=message.text) + reply = await logout(uid=uid_make(__sender__, message.from_user.id)) + await bot.reply_to( + message, + text=reply, + parse_mode="MarkdownV2", + ) + @bot.message_handler(commands="env", chat_types=["private"]) async def listen_env_command(message: types.Message): _cmd, _arg = parse_command(command=message.text) @@ -299,8 +311,7 @@ async def listen_help_command(message: types.Message): _message = await bot.reply_to( message, text=formatting.format_text( - formatting.mbold("🥕 Help"), - escape_markdown(help_message()), + telegramify_markdown.convert(help_message()), separator="\n", ), parse_mode="MarkdownV2", diff --git a/app/sender/telegram/event.py b/app/sender/telegram/event.py index b327f522..09d6d475 100644 --- a/app/sender/telegram/event.py +++ b/app/sender/telegram/event.py @@ -7,18 +7,22 @@ def help_message(): return """ - /help - show help message - /chat - just want to chat with me - /task - chat with function_enable - /ask - chat with function_disable - /tool - check all useful tools - /clear - clear the chat history - /auth - auth the tool_call - /learn - set your system prompt, reset by `/learn reset` +# Command List -Private Chat Only: - /login - login via url or something - /env - set v-env split by ; , use `/env ENV=NONE` to disable a env. +`/help` - show help message +`/chat` - just want to chat with me +`/task` - chat with function_enable +`/ask` - chat with function_disable +`/tool` - check all useful tools +`/clear` - clear the chat history +`/auth` - auth the tool_call +`/learn` - set your system prompt, reset by `/learn reset` -!Please confirm that that bot instance is secure, some plugins may be dangerous on unsafe instance. +**Private Chat Only** + +`/login` - login via url or something +`/logout` - clear credential +`/env` - set v-env split by ; , use `/env ENV=NONE` to disable a env. + +> Please confirm that that bot instance is secure, some plugins may be dangerous on unsafe instance, wink~ """ From d7966ea40a1befb3a0f950fb43057084d3fee127 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Fri, 31 May 2024 11:27:09 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E2=84=B9=EF=B8=8F=20fix:=20adjust=20indent?= =?UTF-8?q?ation=20in=20is=5Fcommand=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔒 feat: add logout function for user logout functionality --- app/sender/util_func.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/sender/util_func.py b/app/sender/util_func.py index cb835de1..37d67252 100644 --- a/app/sender/util_func.py +++ b/app/sender/util_func.py @@ -220,6 +220,18 @@ async def login(uid: str, arg_string) -> str: return error +async def logout(uid: str) -> str: + """ + Logout + :param uid: uid_make + :return: str message + """ + user = await USER_MANAGER.read(user_id=uid) + user.credential = None + await USER_MANAGER.save(user_model=user) + return telegramify_markdown.convert("Logout success! Welcome back master!") + + class TimerObjectContainer: def __init__(self): self.users = {}