add services shared layer

This commit is contained in:
Jeremy Yin 2024-04-09 22:14:52 +08:00
parent 8aaed632b6
commit 94d28188d9
3 changed files with 18 additions and 4 deletions

View File

@ -6,8 +6,8 @@ from simplylab.services.chat import ChatService
class Services:
def __init__(self, ctx: Context, providers: Providers):
self.ctx = ctx
def __init__(self, context: Context, providers: Providers):
self.ctx = context
self.pvd = providers
@property

View File

@ -8,12 +8,14 @@ from simplylab.model.req import GetAiChatResponseInput, GetUserChatHistoryInput,
from simplylab.model.table import MessageRoleType, Message
from simplylab.error import MessageLimitedInDailyError, MessageLimitedIn30SecondsError
from simplylab.providers import Providers
from simplylab.services.shared import ServicesShared
class ChatService:
def __init__(self, ctx: Context, providers: Providers):
self.ctx = ctx
def __init__(self, context: Context, providers: Providers):
self.ctx = context
self.pvd = providers
self.shared = ServicesShared(context, providers)
async def get_ai_chat_response(self, req: GetAiChatResponseInput) -> GetAiChatResponseOutput:
if await self.pvd.chat.check_user_message_limited_in_30_seconds(self.ctx.user.id):

View File

@ -0,0 +1,12 @@
from simplylab.model.entity import Context
from simplylab.providers import Providers
class ServicesShared:
def __init__(self, context: Context, providers: Providers) -> None:
self.ctx = context
self.pvd = providers
def do_sth(self):
res = self.pvd.user.get_user_by_name("SimplyLab")
return None