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` 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` 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` 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~ """ 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 = {}