Skip to content

Commit b918510

Browse files
authored
Merge pull request #424 from LlmKira/main
release image
2 parents e8b6226 + ccecd13 commit b918510

File tree

16 files changed

+1310
-1154
lines changed

16 files changed

+1310
-1154
lines changed

.nerve.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
contributor = "b4e0cd99-289b-4586-992c-6f159c436101"
2+
# https://github.com/LlmKira/contributor/blob/main/.nerve.toml
3+
4+
language = "English"
5+
issue_auto_label = true
6+
# Whether to automatically label issues
7+
issue_title_format = true
8+
# Whether to use the default issue title format
9+
issue_body_format = false
10+
# Whether to use the default issue body format
11+
issue_close_with_report = true
12+
# Whether to close the issue with a report

app/components/credential.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Credential(BaseModel):
1414
api_key: str
1515
api_endpoint: str
1616
api_model: str
17-
api_tool_model: str = "gpt-3.5-turbo"
17+
api_tool_model: str = "gpt-4o-mini"
1818

1919
@classmethod
2020
def from_provider(cls, token, provider_url):
@@ -36,7 +36,7 @@ def from_provider(cls, token, provider_url):
3636
api_key=user_data["api_key"],
3737
api_endpoint=user_data["api_endpoint"],
3838
api_model=user_data["api_model"],
39-
api_tool_model=user_data.get("api_tool_model", "gpt-3.5-turbo"),
39+
api_tool_model=user_data.get("api_tool_model", "gpt-4o-mini"),
4040
)
4141

4242

@@ -47,8 +47,8 @@ def from_provider(cls, token, provider_url):
4747
global_credential = Credential(
4848
api_key=os.getenv("GLOBAL_OAI_KEY"),
4949
api_endpoint=os.getenv("GLOBAL_OAI_ENDPOINT"),
50-
api_model=os.getenv("GLOBAL_OAI_MODEL", "gpt-3.5-turbo"),
51-
api_tool_model=os.getenv("GLOBAL_OAI_TOOL_MODEL", "gpt-3.5-turbo"),
50+
api_model=os.getenv("GLOBAL_OAI_MODEL", "gpt-4o-mini"),
51+
api_tool_model=os.getenv("GLOBAL_OAI_TOOL_MODEL", "gpt-4o-mini"),
5252
)
5353
else:
5454
global_credential = None

app/sender/discord/__init__.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
save_credential,
3838
dict2markdown,
3939
learn_instruction,
40+
logout,
4041
)
4142
from llmkira.openapi.trigger import get_trigger_loop
4243
from ...components.credential import Credential, ProviderError
@@ -286,7 +287,7 @@ async def listen_endpoint_command(
286287
api_endpoint: str,
287288
api_key: str,
288289
api_model: str,
289-
api_tool_model: str = "gpt-3.5-turbo",
290+
api_tool_model: str = "gpt-4o-mini",
290291
):
291292
try:
292293
credential = Credential(
@@ -319,6 +320,19 @@ async def listen_endpoint_command(
319320
ephemeral=True,
320321
)
321322

323+
@client.include
324+
@crescent.command(
325+
dm_enabled=True, name="logout", description="clear your credential"
326+
)
327+
async def listen_logout_command(ctx: crescent.Context):
328+
reply = await logout(
329+
uid=uid_make(__sender__, ctx.user.id),
330+
)
331+
return await ctx.respond(
332+
ephemeral=True,
333+
content=reply,
334+
)
335+
322336
@client.include
323337
@crescent.command(
324338
dm_enabled=True, name="clear", description="clear your message history"

app/sender/discord/event.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def help_message():
1616
`/tool` - Check all useful tools
1717
`/clear` - wipe memory of your chat
1818
`/auth` - activate a task (my power)
19-
`/login` - login
19+
`/login` - set credential
20+
`/logout` - clear credential
2021
`/login_via_url` - login via url
2122
`/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env.
2223
`/learn` - set your system prompt, reset by `/learn reset`

app/sender/kook/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
save_credential,
3535
dict2markdown,
3636
learn_instruction,
37+
logout,
3738
)
3839
from llmkira.openapi.trigger import get_trigger_loop
3940
from ...components.credential import ProviderError, Credential
@@ -296,8 +297,8 @@ async def listen_login_command(
296297
msg: Message,
297298
api_endpoint: str,
298299
api_key: str,
299-
api_model: str = "gpt-3.5-turbo",
300-
api_tool_model: str = "gpt-3.5-turbo",
300+
api_model: str = "gpt-4o-mini",
301+
api_tool_model: str = "gpt-4o-mini",
301302
):
302303
try:
303304
credential = Credential(
@@ -331,6 +332,15 @@ async def listen_login_command(
331332
type=MessageTypes.KMD,
332333
)
333334

335+
@bot.command(name="logout")
336+
async def listen_logout_command(msg: Message):
337+
reply = await logout(uid=uid_make(__sender__, msg.author_id))
338+
return await msg.reply(
339+
content=convert(reply),
340+
is_temp=True,
341+
type=MessageTypes.KMD,
342+
)
343+
334344
@bot.command(name="clear")
335345
async def listen_clear_command(msg: Message):
336346
await global_message_runtime.update_session(

app/sender/kook/event.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def help_message():
3535
`/tool` - Check all useful tools
3636
`/clear` - wipe memory of your chat
3737
`/auth` - activate a task (my power)
38-
`/login` - login openai
38+
`/login` - set credential
39+
`/logout` - clear credential
3940
`/login_via_url` - login via provider url
4041
`/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env.
4142
`/learn` - set your system prompt, reset by `/learn reset`

app/sender/slack/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
login,
2626
dict2markdown,
2727
learn_instruction,
28+
logout,
2829
)
2930
from app.setting.slack import BotSetting
3031
from llmkira.kv_manager.env import EnvManager
@@ -248,6 +249,16 @@ async def listen_login_command(ack: AsyncAck, respond: AsyncRespond, command):
248249
)
249250
return await respond(text=reply)
250251

252+
@bot.command(command="/logout")
253+
async def listen_logout_command(ack: AsyncAck, respond: AsyncRespond, command):
254+
command: SlashCommand = SlashCommand.model_validate(command)
255+
await ack()
256+
if not command.text:
257+
return
258+
_arg = command.text
259+
reply = await logout(uid=uid_make(__sender__, command.user_id))
260+
return await respond(text=reply)
261+
251262
@bot.command(command="/env")
252263
async def listen_env_command(ack: AsyncAck, respond: AsyncRespond, command):
253264
command: SlashCommand = SlashCommand.model_validate(command)

app/sender/slack/event.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def help_message():
2424
`/clear` - forget...you
2525
`/auth` - activate a task (my power),but outside the thread
2626
`/login` - login via url or raw
27+
`/logout` - clear credential
2728
`/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env.
2829
`/learn` - set your system prompt, reset by `/learn reset`
2930

app/sender/telegram/__init__.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
# @Software: PyCharm
66
from typing import Optional, Union, List
77

8+
import telegramify_markdown
89
from loguru import logger
910
from telebot import formatting, util
1011
from telebot import types
1112
from telebot.async_telebot import AsyncTeleBot
1213
from telebot.asyncio_storage import StateMemoryStorage
13-
from telebot.formatting import escape_markdown
1414
from telegramify_markdown import convert
1515

1616
from app.sender.util_func import (
@@ -23,6 +23,7 @@
2323
TimerObjectContainer,
2424
dict2markdown,
2525
learn_instruction,
26+
logout,
2627
)
2728
from app.setting.telegram import BotSetting
2829
from llmkira.kv_manager.env import EnvManager
@@ -69,7 +70,15 @@ async def transcribe(
6970
event_messages = []
7071
files = [file for file in files if file] # No None
7172
for index, message in enumerate(messages):
72-
message_text = getattr(message, "text", "empty")
73+
message_text = (
74+
(
75+
getattr(message, "text", None)
76+
or getattr(message, "caption", None)
77+
or "empty"
78+
)
79+
if message is not None
80+
else "empty"
81+
)
7382
event_messages.append(
7483
EventMessage(
7584
chat_id=str(message.chat.id),
@@ -251,6 +260,17 @@ async def listen_login_command(message: types.Message):
251260
parse_mode="MarkdownV2",
252261
)
253262

263+
@bot.message_handler(commands="logout", chat_types=["private"])
264+
async def listen_logout_command(message: types.Message):
265+
logger.debug("Debug:logout command")
266+
_cmd, _arg = parse_command(command=message.text)
267+
reply = await logout(uid=uid_make(__sender__, message.from_user.id))
268+
await bot.reply_to(
269+
message,
270+
text=reply,
271+
parse_mode="MarkdownV2",
272+
)
273+
254274
@bot.message_handler(commands="env", chat_types=["private"])
255275
async def listen_env_command(message: types.Message):
256276
_cmd, _arg = parse_command(command=message.text)
@@ -299,8 +319,7 @@ async def listen_help_command(message: types.Message):
299319
_message = await bot.reply_to(
300320
message,
301321
text=formatting.format_text(
302-
formatting.mbold("🥕 Help"),
303-
escape_markdown(help_message()),
322+
telegramify_markdown.convert(help_message()),
304323
separator="\n",
305324
),
306325
parse_mode="MarkdownV2",

app/sender/telegram/event.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77

88
def help_message():
99
return """
10-
/help - show help message
11-
/chat - just want to chat with me
12-
/task - chat with function_enable
13-
/ask - chat with function_disable
14-
/tool - check all useful tools
15-
/clear - clear the chat history
16-
/auth - auth the tool_call
17-
/learn - set your system prompt, reset by `/learn reset`
10+
# Command List
1811
19-
Private Chat Only:
20-
/login - login via url or something
21-
/env - set v-env split by ; , use `/env ENV=NONE` to disable a env.
12+
`/help` - show help message
13+
`/chat` - just want to chat with me
14+
`/task` - chat with function_enable
15+
`/ask` - chat with function_disable
16+
`/tool` - check all useful tools
17+
`/clear` - clear the chat history
18+
`/auth` - auth the tool_call
19+
`/learn` - set your system prompt, reset by `/learn reset`
2220
23-
!Please confirm that that bot instance is secure, some plugins may be dangerous on unsafe instance.
21+
**Private Chat Only**
22+
23+
`/login` - login via url or something
24+
`/logout` - clear credential
25+
`/env` - set v-env split by ; , use `/env ENV=NONE` to disable a env.
26+
27+
> Please confirm that that bot instance is secure, some plugins may be dangerous on unsafe instance, wink~
2428
"""

app/sender/util_func.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async def login(uid: str, arg_string) -> str:
170170
error = telegramify_markdown.convert(
171171
"🔑 **Incorrect format.**\n"
172172
"You can set it via `/login https://<something api.openai.com>/v1$<api key>"
173-
"$<model such as gpt-4-turbo>$<tool_model such as gpt-3.5-turbo>` format, "
173+
"$<model such as gpt-4-turbo>$<tool_model such as gpt-4o-mini>` format, "
174174
"or you can log in via URL using `/login token$https://provider.com`.\n"
175175
"Use $ to separate the parameters."
176176
)
@@ -202,7 +202,7 @@ async def login(uid: str, arg_string) -> str:
202202
if len(settings) == 4:
203203
api_tool_model = settings[3]
204204
else:
205-
api_tool_model = "gpt-3.5-turbo"
205+
api_tool_model = "gpt-4o-mini"
206206
credential = Credential(
207207
api_endpoint=api_endpoint,
208208
api_key=api_key,
@@ -220,6 +220,18 @@ async def login(uid: str, arg_string) -> str:
220220
return error
221221

222222

223+
async def logout(uid: str) -> str:
224+
"""
225+
Logout
226+
:param uid: uid_make
227+
:return: str message
228+
"""
229+
user = await USER_MANAGER.read(user_id=uid)
230+
user.credential = None
231+
await USER_MANAGER.save(user_model=user)
232+
return telegramify_markdown.convert("Logout success! Welcome back master!")
233+
234+
223235
class TimerObjectContainer:
224236
def __init__(self):
225237
self.users = {}

app/setting/whitelist.py

Whitespace-only changes.

llmkira/extra/voice_hook.py

+25-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List
22

3-
from fast_langdetect import parse_sentence
3+
from fast_langdetect import detect_multilingual
44
from loguru import logger
55

66
from llmkira.extra.voice import request_cn, request_en
@@ -11,23 +11,35 @@
1111
from llmkira.task.schema import EventMessage, Location
1212

1313

14-
def check_string(text):
14+
def detect_text(text: str) -> list:
1515
"""
16-
检查字符串是否符合要求
17-
:param text: 字符串
18-
:return: 是否符合要求
16+
检测文本的语言
17+
:param text: 文本
18+
:return: 语言
1919
"""
20-
parsed_text = parse_sentence(text)
20+
text = text.replace("\n", "")
21+
text = text[:200]
22+
parsed_text = detect_multilingual(text)
2123
if not parsed_text:
22-
return False
24+
return []
2325
lang_kinds = []
2426
for lang in parsed_text:
25-
if lang.get("lang", "RU") not in ["ZH", "EN"]:
26-
return False
27-
lang_kinds.append(lang.get("lang"))
27+
lang_ = lang.get("lang", None)
28+
if lang_:
29+
lang_kinds.append(lang_)
30+
return lang_kinds
31+
32+
33+
def check_string(text):
34+
"""
35+
检查字符串是否 TTS 可以处理
36+
:param text: 字符串
37+
:return: 是否符合要求
38+
"""
39+
lang_kinds = detect_text(text)
2840
limit = 200
2941
if len(set(lang_kinds)) == 1:
30-
if lang_kinds[0] in ["EN"]:
42+
if lang_kinds[0] in ["en"]:
3143
limit = 500
3244
if "\n\n" in text or text.count("\n") > 3 or len(text) > limit or "```" in text:
3345
return False
@@ -59,16 +71,11 @@ async def hook_run(self, *args, **kwargs):
5971
for message in messages:
6072
if not check_string(message.text):
6173
return args, kwargs
62-
parsed_text = parse_sentence(message.text)
63-
if not parsed_text:
64-
return args, kwargs
65-
lang_kinds = []
66-
for lang in parsed_text:
67-
lang_kinds.append(lang.get("lang"))
74+
lang_kinds = detect_text(message.text)
6875
reecho_api_key = await EnvManager(locate.uid).get_env(
6976
"REECHO_VOICE_KEY", None
7077
)
71-
if (len(set(lang_kinds)) == 1) and (lang_kinds[0] in ["EN"]):
78+
if (len(set(lang_kinds)) == 1) and (lang_kinds[0] in ["en"]):
7279
voice_data = await request_en(message.text)
7380
else:
7481
voice_data = await request_cn(

0 commit comments

Comments
 (0)