Skip to content

Commit 60a1887

Browse files
authored
v1.0.0rc1 (#388)
2 parents 9323475 + 8eb9acf commit 60a1887

File tree

212 files changed

+9449
-8926
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+9449
-8926
lines changed

.github/process_github_events.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def post_comment_on_pr(comment: str, pr_number: int):
5050
- [ ] Change PR merge option
5151
- [ ] Update template repo
5252
- [ ] Search for objects to be deprecated
53+
- [ ] Test parts not covered with pytest:
54+
- [ ] web_api tutorials
55+
- [ ] Test integrations with external services (telegram; stats)
5356
"""
5457

5558

README.md

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Chatsky
1+
![Chatsky](docs/source/_static/images/Chatsky-full-dark.svg)
22

33
[![Documentation Status](https://github.com/deeppavlov/chatsky/workflows/build_and_publish_docs/badge.svg?branch=dev)](https://deeppavlov.github.io/chatsky)
44
[![Codestyle](https://github.com/deeppavlov/chatsky/workflows/codestyle/badge.svg?branch=dev)](https://github.com/deeppavlov/chatsky/actions/workflows/codestyle.yml)
@@ -79,53 +79,47 @@ All the abstractions used in this example are thoroughly explained in the dedica
7979
[user guide](https://deeppavlov.github.io/chatsky/user_guides/basic_conceptions.html).
8080

8181
```python
82-
from chatsky.script import GLOBAL, TRANSITIONS, RESPONSE, Message
83-
from chatsky.pipeline import Pipeline
84-
import chatsky.script.conditions.std_conditions as cnd
82+
from chatsky import (
83+
GLOBAL,
84+
TRANSITIONS,
85+
RESPONSE,
86+
Pipeline,
87+
conditions as cnd,
88+
Transition as Tr,
89+
)
8590

8691
# create a dialog script
8792
script = {
8893
GLOBAL: {
89-
TRANSITIONS: {
90-
("flow", "node_hi"): cnd.exact_match("Hi"),
91-
("flow", "node_ok"): cnd.true()
92-
}
94+
TRANSITIONS: [
95+
Tr(
96+
dst=("flow", "node_hi"),
97+
cnd=cnd.ExactMatch("Hi"),
98+
),
99+
Tr(
100+
dst=("flow", "node_ok")
101+
)
102+
]
93103
},
94104
"flow": {
95-
"node_hi": {RESPONSE: Message("Hi!")},
96-
"node_ok": {RESPONSE: Message("OK")},
105+
"node_hi": {RESPONSE: "Hi!"},
106+
"node_ok": {RESPONSE: "OK"},
97107
},
98108
}
99109

100-
# init pipeline
101-
pipeline = Pipeline.from_script(script, start_label=("flow", "node_hi"))
110+
# initialize Pipeline (needed to run the script)
111+
pipeline = Pipeline(script, start_label=("flow", "node_hi"))
102112

103113

104-
def turn_handler(in_request: Message, pipeline: Pipeline) -> Message:
105-
# Pass user request into pipeline and get dialog context (message history)
106-
# The pipeline will automatically choose the correct response using script
107-
ctx = pipeline(in_request, 0)
108-
# Get last response from the context
109-
out_response = ctx.last_response
110-
return out_response
111-
112-
113-
while True:
114-
in_request = input("Your message: ")
115-
out_response = turn_handler(Message(in_request), pipeline)
116-
print("Response: ", out_response.text)
114+
pipeline.run()
117115
```
118116

119117
When you run this code, you get similar output:
120118
```
121-
Your message: hi
122-
Response: OK
123-
Your message: Hi
124-
Response: Hi!
125-
Your message: ok
126-
Response: OK
127-
Your message: ok
128-
Response: OK
119+
request: hi
120+
response: text='OK'
121+
request: Hi
122+
response: text='Hi!'
129123
```
130124

131125
More advanced examples are available as a part of documentation:

chatsky/__init__.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,42 @@
66
__version__ = version(__name__)
77

88

9-
import nest_asyncio
9+
import nest_asyncio as __nest_asyncio__
1010

11-
nest_asyncio.apply()
11+
__nest_asyncio__.apply()
12+
13+
from chatsky.core import (
14+
GLOBAL,
15+
LOCAL,
16+
RESPONSE,
17+
TRANSITIONS,
18+
MISC,
19+
PRE_RESPONSE,
20+
PRE_TRANSITION,
21+
BaseCondition,
22+
AnyCondition,
23+
BaseResponse,
24+
AnyResponse,
25+
BaseDestination,
26+
AnyDestination,
27+
BaseProcessing,
28+
BasePriority,
29+
AnyPriority,
30+
Pipeline,
31+
Context,
32+
Message,
33+
Transition,
34+
Transition as Tr,
35+
MessageInitTypes,
36+
NodeLabel,
37+
NodeLabelInitTypes,
38+
AbsoluteNodeLabel,
39+
AbsoluteNodeLabelInitTypes,
40+
)
41+
import chatsky.conditions as cnd
42+
import chatsky.destinations as dst
43+
import chatsky.responses as rsp
44+
import chatsky.processing as proc
1245

13-
from chatsky.pipeline import Pipeline
14-
from chatsky.script import Context, Script
1546

1647
import chatsky.__rebuild_pydantic_models__
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# flake8: noqa: F401
22

3-
from chatsky.pipeline import Pipeline
4-
from chatsky.pipeline.types import ExtraHandlerRuntimeInfo
5-
from chatsky.script import Context, Script
3+
from chatsky.core.service.types import ExtraHandlerRuntimeInfo, StartConditionCheckerFunction, ComponentExecutionState
4+
from chatsky.core import Context, Script
5+
from chatsky.core.script import Node
6+
from chatsky.core.pipeline import Pipeline
7+
from chatsky.slots.slots import SlotManager
8+
from chatsky.core.context import FrameworkData
69

10+
Pipeline.model_rebuild()
711
Script.model_rebuild()
812
Context.model_rebuild()
913
ExtraHandlerRuntimeInfo.model_rebuild()
14+
FrameworkData.model_rebuild()

chatsky/conditions/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from chatsky.conditions.standard import (
2+
ExactMatch,
3+
HasText,
4+
Regexp,
5+
Any,
6+
All,
7+
Negation,
8+
CheckLastLabels,
9+
Not,
10+
HasCallbackQuery,
11+
)
12+
from chatsky.conditions.slots import SlotsExtracted

chatsky/conditions/slots.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Slot Conditions
3+
---------------------------
4+
Provides slot-related conditions.
5+
"""
6+
7+
from __future__ import annotations
8+
from typing import Literal, List
9+
10+
from chatsky.core import Context, BaseCondition
11+
from chatsky.slots.slots import SlotName
12+
13+
14+
class SlotsExtracted(BaseCondition):
15+
"""
16+
Check if :py:attr:`.slots` are extracted.
17+
18+
:param mode: Whether to check if all slots are extracted or any slot is extracted.
19+
"""
20+
21+
slots: List[SlotName]
22+
"""
23+
Names of the slots that need to be checked.
24+
"""
25+
mode: Literal["any", "all"] = "all"
26+
"""
27+
Whether to check if all slots are extracted or any slot is extracted.
28+
"""
29+
30+
def __init__(self, *slots: SlotName, mode: Literal["any", "all"] = "all"):
31+
super().__init__(slots=slots, mode=mode)
32+
33+
async def call(self, ctx: Context) -> bool:
34+
manager = ctx.framework_data.slot_manager
35+
if self.mode == "all":
36+
return all(manager.is_slot_extracted(slot) for slot in self.slots)
37+
elif self.mode == "any":
38+
return any(manager.is_slot_extracted(slot) for slot in self.slots)

0 commit comments

Comments
 (0)