Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat): add logout Command #414

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/sender/discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
save_credential,
dict2markdown,
learn_instruction,
logout,
)
from llmkira.openapi.trigger import get_trigger_loop
from ...components.credential import Credential, ProviderError
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion app/sender/discord/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
10 changes: 10 additions & 0 deletions app/sender/kook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
save_credential,
dict2markdown,
learn_instruction,
logout,
)
from llmkira.openapi.trigger import get_trigger_loop
from ...components.credential import ProviderError, Credential
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion app/sender/kook/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 11 additions & 0 deletions app/sender/slack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
login,
dict2markdown,
learn_instruction,
logout,
)
from app.setting.slack import BotSetting
from llmkira.kv_manager.env import EnvManager
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/sender/slack/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
17 changes: 14 additions & 3 deletions app/sender/telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -23,6 +23,7 @@
TimerObjectContainer,
dict2markdown,
learn_instruction,
logout,
)
from app.setting.telegram import BotSetting
from llmkira.kv_manager.env import EnvManager
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
28 changes: 16 additions & 12 deletions app/sender/telegram/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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~
"""
12 changes: 12 additions & 0 deletions app/sender/util_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
Loading