chatgraph 0.5.2__py3-none-any.whl → 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of chatgraph might be problematic. Click here for more details.
- chatgraph/bot/chatbot_model.py +8 -1
- chatgraph/types/background_task.py +22 -18
- {chatgraph-0.5.2.dist-info → chatgraph-0.5.3.dist-info}/METADATA +1 -1
- {chatgraph-0.5.2.dist-info → chatgraph-0.5.3.dist-info}/RECORD +7 -7
- {chatgraph-0.5.2.dist-info → chatgraph-0.5.3.dist-info}/LICENSE +0 -0
- {chatgraph-0.5.2.dist-info → chatgraph-0.5.3.dist-info}/WHEEL +0 -0
- {chatgraph-0.5.2.dist-info → chatgraph-0.5.3.dist-info}/entry_points.txt +0 -0
chatgraph/bot/chatbot_model.py
CHANGED
|
@@ -10,7 +10,7 @@ from ..types.message_types import Message, Button
|
|
|
10
10
|
from ..types.end_types import RedirectResponse, EndChatResponse, TransferToHuman
|
|
11
11
|
from ..types.route import Route
|
|
12
12
|
from .chatbot_router import ChatbotRouter
|
|
13
|
-
|
|
13
|
+
from ..types.background_task import BackgroundTask
|
|
14
14
|
|
|
15
15
|
class ChatbotApp:
|
|
16
16
|
"""
|
|
@@ -177,8 +177,15 @@ class ChatbotApp:
|
|
|
177
177
|
userCall.route = route
|
|
178
178
|
await self.process_message(userCall)
|
|
179
179
|
|
|
180
|
+
|
|
180
181
|
elif not userCall_response:
|
|
182
|
+
route = route + "." + route.split(".")[-1]
|
|
183
|
+
userCall.route = route
|
|
181
184
|
return
|
|
185
|
+
|
|
186
|
+
elif isinstance(userCall_response, BackgroundTask):
|
|
187
|
+
response = await userCall_response.run()
|
|
188
|
+
await self.__process_func_response(response, userCall, route=route)
|
|
182
189
|
|
|
183
190
|
else:
|
|
184
191
|
error("Tipo de retorno inválido!")
|
|
@@ -2,22 +2,26 @@ import asyncio
|
|
|
2
2
|
from typing import Any, Callable
|
|
3
3
|
import threading
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
class BackgroundTask:
|
|
6
|
+
def __init__(self, func: Callable, *args: Any, **kwargs: Any) -> None:
|
|
7
|
+
"""
|
|
8
|
+
Inicia uma função de forma assíncrona em segundo plano e printa sua saída.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
func (Callable): A função a ser executada.
|
|
12
|
+
args (Any): Argumentos posicionais a serem passados para a função.
|
|
13
|
+
kwargs (Any): Argumentos nomeados a serem passados para a função.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
if not asyncio.iscoroutinefunction(func):
|
|
17
|
+
raise TypeError("A função fornecida deve ser uma coroutine (async def).")
|
|
18
|
+
|
|
19
|
+
self.args = args
|
|
20
|
+
self.kwargs = kwargs
|
|
21
|
+
self.func = func
|
|
8
22
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def start_loop():
|
|
15
|
-
loop = asyncio.new_event_loop()
|
|
16
|
-
asyncio.set_event_loop(loop)
|
|
17
|
-
loop.run_until_complete(func(*args, **kwargs))
|
|
18
|
-
|
|
19
|
-
# Executa o loop de eventos em uma thread separada
|
|
20
|
-
thread = threading.Thread(target=start_loop)
|
|
21
|
-
thread.start()
|
|
22
|
-
else:
|
|
23
|
-
raise TypeError("A função fornecida deve ser uma coroutine (async def).")
|
|
23
|
+
async def run(self):
|
|
24
|
+
"""
|
|
25
|
+
Executa a função em segundo plano.
|
|
26
|
+
"""
|
|
27
|
+
return await self.func(*self.args, **self.kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
chatgraph/__init__.py,sha256=QtS8l6UjQ7N9gPNruTaPKUTNP8-EvTYeiTBoiSKGp7E,781
|
|
2
2
|
chatgraph/auth/credentials.py,sha256=xsMEpLQnc66novPjL6upocMcnUnvFJ7yxINzUenkxmc,2388
|
|
3
|
-
chatgraph/bot/chatbot_model.py,sha256=
|
|
3
|
+
chatgraph/bot/chatbot_model.py,sha256=PhWCDDTIfT92rwS-USciugVjXuCDKk44NJbiOfEhvRk,7051
|
|
4
4
|
chatgraph/bot/chatbot_router.py,sha256=bVbm9dBoC2OesetXlQJpCrkaiLM3GUro0GrOyCSgreI,2586
|
|
5
5
|
chatgraph/cli/__init__.py,sha256=tfgYhGoKy1nD4STN4xDh6J4VV55RICk7v1GZmzAg-bM,7413
|
|
6
6
|
chatgraph/error/chatbot_error.py,sha256=4sEcW8vz0eQk2QDmDygucVM4caHliZW5iH7XJvmLBuk,1897
|
|
@@ -10,13 +10,13 @@ chatgraph/messages/message_consumer.py,sha256=yHhfLYjtmXQYG44o7SNO6XUaeM4-jH8BpI
|
|
|
10
10
|
chatgraph/pb/router.proto,sha256=pw3hTwjdMN8-yJIAlKHNigVKYqM-w2nme9-2bCTBiJ0,2853
|
|
11
11
|
chatgraph/pb/router_pb2.py,sha256=jw-Rg05NMwgOKrRsoubFFb82v_O80KgWY4tIqwUf2Aw,6571
|
|
12
12
|
chatgraph/pb/router_pb2_grpc.py,sha256=KxhVxCMVD9tpuX7CyXqIkzZ4P3zfXeVT92Bt_Hi7mrE,24109
|
|
13
|
-
chatgraph/types/background_task.py,sha256=
|
|
13
|
+
chatgraph/types/background_task.py,sha256=j-Bpd1l_LCDiWukhfG8wNr1F0_GUaOL_J2_BCUnTof4,928
|
|
14
14
|
chatgraph/types/end_types.py,sha256=--Ty2gM_y7J-yRAvZV26e4HMUpoguAMAhfOIS9-kQTk,1316
|
|
15
15
|
chatgraph/types/message_types.py,sha256=__LOk09Xfvojum0xiq9n157_3QSSLNaDMc02iq8dGpk,3434
|
|
16
16
|
chatgraph/types/request_types.py,sha256=BeUI2l9XZpBf5c8xyPvKI68WZ5u6n98cC8DmUfWKlQ0,8788
|
|
17
17
|
chatgraph/types/route.py,sha256=FO5INy5UXgicuQ8FKEZKcPv6WS5YH10dPx2OaPu_0sE,2978
|
|
18
|
-
chatgraph-0.5.
|
|
19
|
-
chatgraph-0.5.
|
|
20
|
-
chatgraph-0.5.
|
|
21
|
-
chatgraph-0.5.
|
|
22
|
-
chatgraph-0.5.
|
|
18
|
+
chatgraph-0.5.3.dist-info/entry_points.txt,sha256=bO9_Q-PqE5vCNNo6ke_-3j2gHfKQMDGnKDTkNuCdBuA,48
|
|
19
|
+
chatgraph-0.5.3.dist-info/LICENSE,sha256=rVJozpRzDlplOpvI8A1GvmfVS0ReYdZvMWc1j2jV0v8,1090
|
|
20
|
+
chatgraph-0.5.3.dist-info/METADATA,sha256=X4TtQbT5Bcpbaes_XIrLjuoELAMuYU3y105R8F7Ilnw,12866
|
|
21
|
+
chatgraph-0.5.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
22
|
+
chatgraph-0.5.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|