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

Service option update #378

Merged
merged 232 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
dc01db6
most things done except components -> before + after handler, clarifi…
ZergLev Jul 10, 2024
ace4a5f
forgot to apply a few things
ZergLev Jul 10, 2024
c49fde9
formatted + partial self-review, feedback required
ZergLev Jul 10, 2024
957d231
formatted with poetry + minor changes
ZergLev Jul 10, 2024
f3cdd51
moved state checking to component, added single_func_init to Extra Ha…
ZergLev Jul 11, 2024
0e21a3e
field_validator added to Service, minor type changes
ZergLev Jul 12, 2024
9e5b688
Several changes and fixes. Tests compile now, but 21 of them fail.
ZergLev Jul 15, 2024
3d6e29f
fixed small mistake, tests still don't pass
ZergLev Jul 15, 2024
d92292b
formatted with poetry
ZergLev Jul 17, 2024
7ba3ac4
starting removal of pipeline.from_script()
ZergLev Jul 17, 2024
40484f0
a bunch of fixes to type annotations + actor's call signature fixed
ZergLev Jul 17, 2024
5df72bd
removed method call() from Actor so that it defaults to that of Pipel…
ZergLev Jul 17, 2024
0612023
fixed validation for ServiceGroups, Services and ExtraHandlers at Pip…
ZergLev Jul 18, 2024
1e67936
an error fixed, pipeline declaration conflicts found (they sent tuple…
ZergLev Jul 18, 2024
049f8f3
replaced from_script() with Pipeline() throughout the codebase, repla…
ZergLev Jul 22, 2024
c5413b8
minor changes and formatted with poetry
ZergLev Jul 22, 2024
66909f3
mistake fixed + fully removed from_script() and set_actor()
ZergLev Jul 22, 2024
9773e63
changed components into pre- and post-services for Pipeline initializ…
ZergLev Jul 22, 2024
baa1698
lint
ZergLev Jul 22, 2024
e33bb16
minor fix
ZergLev Jul 22, 2024
43de1db
minor mistake fixed
ZergLev Jul 22, 2024
fe78e12
found and fixed minor bug
ZergLev Jul 22, 2024
5753de9
removed to_service() and Optional[] where possible, also removed comp…
ZergLev Jul 24, 2024
58af2ca
replaced Pipeline's from_dict() with model_validate()
ZergLev Jul 24, 2024
5a1b19b
minor change
ZergLev Jul 25, 2024
72fb118
added to_service back in, not everywhere yet
ZergLev Jul 25, 2024
87ad935
mistake found, all tests pass except some of my own
ZergLev Jul 26, 2024
740b711
mistake fixed + strict validation for Pipeline
ZergLev Jul 26, 2024
f3b4b07
restored to_service everywhere, finished drafting new tests, some min…
ZergLev Jul 26, 2024
0e6e70d
self-review changes + comments changed
ZergLev Jul 26, 2024
154bbad
formatted with poetry
ZergLev Jul 26, 2024
2df499d
lint
ZergLev Jul 26, 2024
3a562b1
removed a few comments
ZergLev Jul 26, 2024
8fcf1aa
Polishing changes, new tests updated
ZergLev Jul 29, 2024
f0359a8
Pipeline tutorials updated
ZergLev Jul 29, 2024
6c7fa91
slight tutorial changes
ZergLev Jul 29, 2024
627e374
lint
ZergLev Jul 29, 2024
11fe640
fixing one-symbol mistake in docs
ZergLev Jul 29, 2024
066faf5
Parallel services execution drafted, renaming TBD
ZergLev Jul 30, 2024
eac5190
draft: renaming asynchronous to sequential
ZergLev Jul 30, 2024
c401c4d
comment moved to PR description
ZergLev Jul 30, 2024
fd2b8b9
added all_sequential parameter to ServiceGroup
ZergLev Jul 31, 2024
557b7d5
sticking with 'asynchronous' instead of 'parallel'
ZergLev Aug 1, 2024
1113cab
updated tutorials, but these don't look concise, maybe I should redo …
ZergLev Aug 1, 2024
7fd81a4
updating tests
ZergLev Aug 2, 2024
c43570f
updating tutorials
ZergLev Aug 2, 2024
f722e70
fixed mistake in ServiceGroup
ZergLev Aug 2, 2024
f4f801c
tutorial improved
ZergLev Aug 2, 2024
730e941
minor updates to API and tutorials
ZergLev Aug 2, 2024
7fd15c8
remove log_optimization_warnings() and merged async tutorials into one
ZergLev Aug 5, 2024
e6c0685
branch conflicts resolved
ZergLev Aug 5, 2024
5888888
Update chatsky/pipeline/pipeline/component.py
ZergLev Aug 6, 2024
40dc5b8
review changes started
ZergLev Aug 8, 2024
7691341
reverted redundant changes for Actor
ZergLev Aug 8, 2024
d6956ef
changing validation for ExtraHandlers
ZergLev Aug 8, 2024
cf6869a
testing different doc-style
ZergLev Aug 8, 2024
f0d5474
updated validation for ServiceGroup
ZergLev Aug 8, 2024
3f046ab
lint
ZergLev Aug 8, 2024
b343291
minor fix
ZergLev Aug 8, 2024
ed6f9e8
minor fix
ZergLev Aug 8, 2024
c78dd27
lint
ZergLev Aug 8, 2024
7b799bc
strict validation added for some classes
ZergLev Aug 8, 2024
dbde442
minor fix
ZergLev Aug 8, 2024
fc26daf
formatted with poetry
ZergLev Aug 8, 2024
ac66a68
review changes mostly done
ZergLev Aug 9, 2024
2388b2c
minor changes
ZergLev Aug 9, 2024
ba5c64a
lint
ZergLev Aug 9, 2024
f5e299c
minor fix
ZergLev Aug 9, 2024
472bba8
testing new docstrings format for PipelineComponent
ZergLev Aug 9, 2024
9a7abe9
added docstrings for remaining classes and switched to conventional d…
ZergLev Aug 9, 2024
5cc6717
minor docs fix
ZergLev Aug 9, 2024
2b04dfa
lint
ZergLev Aug 9, 2024
c5ca8ba
trying to inherit PipelineComponent fields in Service, ServiceGroup
ZergLev Aug 9, 2024
a5d3b33
fixing new autodocs
ZergLev Aug 9, 2024
314b9fc
checking if conf.py is the reason for it not working
ZergLev Aug 9, 2024
4c7915d
added descriptions for new methods
ZergLev Aug 12, 2024
5930712
Merge branch 'feat/pydantic_improvements' into feat/service_option_up…
ZergLev Aug 12, 2024
3130a82
updated the basic pipeline_from_dict tutorial for now
ZergLev Aug 12, 2024
e7f1506
trying to show inherited members in the docs except Pydantic.BaseMode…
ZergLev Aug 12, 2024
4a019a7
fixing docs
ZergLev Aug 12, 2024
05eb401
Fixed typo
ZergLev Aug 12, 2024
75cb0b8
trying with undoc-members == True
ZergLev Aug 12, 2024
3922a03
reverting redundant change
ZergLev Aug 12, 2024
2aacdbb
trying out member-order == groupwise
ZergLev Aug 12, 2024
a4b55b2
reverted change for now, didn't work as needed
ZergLev Aug 12, 2024
5cf3dbc
testing a possible docs format
ZergLev Aug 12, 2024
2ff6752
trying to inherit only fields
ZergLev Aug 12, 2024
f026b9e
documentation format fixed, but review required
ZergLev Aug 12, 2024
9278dca
minor fix
ZergLev Aug 12, 2024
7da9f0f
Merge branch 'feat/pydantic_improvements' into feat/service_option_up…
ZergLev Aug 12, 2024
63a829d
Update chatsky/pipeline/pipeline/component.py
ZergLev Aug 14, 2024
33b8de6
doing review changes, type validation bug accidentally created
ZergLev Aug 14, 2024
1c2ef43
merged github commit into my branch
ZergLev Aug 14, 2024
0bab5ba
type validation bug fixed
ZergLev Aug 14, 2024
e6eae96
lint
ZergLev Aug 14, 2024
0f6839d
minor changes + added missing links
ZergLev Aug 15, 2024
a04756f
increased test coverage for PipelineComponent
ZergLev Aug 15, 2024
64c8761
added #pragma: no cover to remove redundant lines from coverage
ZergLev Aug 15, 2024
b17b974
Merge branch 'feat/pydantic_improvements' into feat/service_option_up…
ZergLev Aug 15, 2024
1acbd00
lint
ZergLev Aug 15, 2024
9d322a7
Revert "added #pragma: no cover to remove redundant lines from coverage"
RLKRo Aug 18, 2024
c3f3d95
small changes to validator tests
RLKRo Aug 18, 2024
b27961e
doc style: use `:raises:` directive and rephrase docstrings as commands
RLKRo Aug 18, 2024
de9eb83
hide some validators
RLKRo Aug 18, 2024
6934726
make validator nature clear
RLKRo Aug 18, 2024
fccfc5b
small doc change
RLKRo Aug 18, 2024
028d858
starting the new unit-test, switching to another PC
ZergLev Aug 21, 2024
7b61503
unit-test drafted
ZergLev Aug 23, 2024
c787c0c
testing
ZergLev Aug 23, 2024
de5984a
changed test
ZergLev Aug 26, 2024
726e367
Merge branch 'feat/pydantic_improvements' into feat/service_option_up…
ZergLev Aug 26, 2024
6b20469
typo fixed
ZergLev Aug 26, 2024
c1957de
Merge branch 'feat/service_option_update' of https://github.com/deepp…
ZergLev Aug 26, 2024
d575cd3
fixed mistake
ZergLev Aug 26, 2024
7661963
testing
ZergLev Aug 26, 2024
960d22d
testing
ZergLev Aug 26, 2024
840ab70
fixed typo
ZergLev Aug 26, 2024
91cf3bb
fixed typo
ZergLev Aug 26, 2024
0d430b7
testing
ZergLev Aug 26, 2024
544de74
redid the test, should work now
ZergLev Aug 26, 2024
1cba0ca
merged Pydantic Improvements
ZergLev Sep 2, 2024
88d6a61
merged dev
ZergLev Sep 4, 2024
f206cb5
review changes, but without test changes
ZergLev Sep 1, 2024
ec9d0c0
changing the new test
ZergLev Sep 1, 2024
33f8d25
typo fixed
ZergLev Sep 1, 2024
67ae699
typo fixed
ZergLev Sep 2, 2024
f737f15
test renamed
ZergLev Sep 4, 2024
0ded23a
partially fixed tests
ZergLev Sep 4, 2024
af30e1e
trying to fix test
ZergLev Sep 4, 2024
2f891b1
new test fixed
ZergLev Sep 5, 2024
5e746af
lint
ZergLev Sep 5, 2024
346c1d0
fixed typo
ZergLev Sep 5, 2024
93d6ce6
tutorial updated
ZergLev Sep 5, 2024
3affd06
Docs typo fixed
ZergLev Sep 5, 2024
bb3ffa6
poetry format + comment changed
ZergLev Aug 28, 2024
adebca6
drafted a new validator for service
ZergLev Aug 28, 2024
e693f51
added the option to await in condition, changing PipelineComponent's …
ZergLev Aug 28, 2024
3c3e606
did the singature changes for PipelineComponent, Service and ServiceG…
ZergLev Aug 28, 2024
d9833cb
same done for actor
ZergLev Aug 28, 2024
73f5b84
lint
ZergLev Aug 28, 2024
00bfecf
changed how service_successful_condition to awaits on the task
ZergLev Aug 29, 2024
e772a1d
Cherry-picking to merge branch
ZergLev Aug 29, 2024
cc098b9
simplified signatures + implemented call for Service class
ZergLev Aug 29, 2024
d7edca9
lint + my own mistake fixed
ZergLev Aug 29, 2024
28671ed
drafted service_successful_condition change into a BaseCondition
ZergLev Aug 29, 2024
d38965e
lint
ZergLev Aug 29, 2024
3fb3389
typo fixed
ZergLev Aug 29, 2024
306c807
trying to fix a bug
ZergLev Aug 29, 2024
0a5573f
changed OTLP extractors signature and more minor fixes
ZergLev Sep 6, 2024
7c53174
changed chatsky_instrumentor's signature too
ZergLev Sep 6, 2024
b3fc543
lint
ZergLev Sep 6, 2024
893a172
partially updated service conditions tutorials
ZergLev Sep 6, 2024
9f51ea8
testing conditions' interactions with pydantic
ZergLev Sep 6, 2024
a78f9b8
testing
ZergLev Sep 6, 2024
b4f97f1
changed how services are awaited and added sync handler support for s…
ZergLev Sep 9, 2024
0fa880e
all_async test added, tests fixed, some typos fixed
ZergLev Sep 9, 2024
3970e08
updated tutorials
ZergLev Sep 11, 2024
6999c09
some unit-tests added, a few more are needed
ZergLev Sep 13, 2024
8a23be8
lint
ZergLev Sep 13, 2024
e7ad781
typo fixed
ZergLev Sep 13, 2024
d8fbebc
changed ExtraHandler signature
ZergLev Sep 16, 2024
cdddcda
Service test coverage raised to full
ZergLev Sep 16, 2024
10aec0f
lint
ZergLev Sep 16, 2024
030f665
fixed typo
ZergLev Sep 16, 2024
09bde01
fixed another typo
ZergLev Sep 16, 2024
250252b
removed ServiceRuntimeInfo, related tests and updated
ZergLev Sep 18, 2024
1ef3e24
lint
ZergLev Sep 18, 2024
837874d
changed ServiceFinishedCondition
ZergLev Sep 18, 2024
4aaff5c
ServiceState fixed, tests updated for it
ZergLev Sep 19, 2024
6956da2
lint
ZergLev Sep 19, 2024
86255ae
typo fixed + tutorials updated
ZergLev Sep 19, 2024
311817c
removed 'default' parameter from 'PipelineComponent's get_state(), be…
ZergLev Sep 19, 2024
50fd8d3
minor change
ZergLev Sep 19, 2024
3952df2
remove incorrect doc
RLKRo Sep 20, 2024
81625bf
change log level for script exceptions to error
RLKRo Sep 20, 2024
57a9327
Update chatsky/core/service/component.py
ZergLev Sep 20, 2024
14b63df
moved service tests to tests/pipeline
ZergLev Sep 20, 2024
a6ca7af
moved ServiceFinishedCondition to the other conditions, also renamed …
ZergLev Sep 20, 2024
ecbc029
changed model_validator to field_validator, removed redundant functio…
ZergLev Sep 20, 2024
c595ef9
stats collection failing doesn't fail the whole Service + the right t…
ZergLev Sep 23, 2024
f81b525
moved failed stats collection test to 'tests/stats'
ZergLev Sep 23, 2024
0eb1b82
lint
ZergLev Sep 23, 2024
4926391
logs are printed in pipeline tutorials, testing it now
ZergLev Sep 23, 2024
0655967
fixing typos
ZergLev Sep 23, 2024
b3e53cb
paths are now generated for Service handlers if they're PipelineCompo…
ZergLev Sep 23, 2024
d8ca04d
info_dict removed from pipeline, more typos fixed
ZergLev Sep 23, 2024
f7133cc
fixing mistakes
ZergLev Sep 23, 2024
926dba6
fixed another tutorial typo, one bug left
ZergLev Sep 23, 2024
62fd43d
various polishing changes/fixes
ZergLev Sep 25, 2024
d14fcf9
testing tutorial links, looking for redundant logging parameters
ZergLev Sep 25, 2024
1d5be48
testing tutorials + lint
ZergLev Sep 25, 2024
af5efe2
fixed typo
ZergLev Sep 25, 2024
e2f63cf
testing tutorials
ZergLev Sep 25, 2024
79a76b7
fixed typo
ZergLev Sep 25, 2024
f5c7c77
fixing tutorials
ZergLev Sep 25, 2024
e2c0850
fixing some tutorial links
ZergLev Sep 25, 2024
0cdf5d9
tutorial links fixed
ZergLev Sep 25, 2024
02b0bc5
refactoring tutorials + abridged 5th pipeline tutorial for clarity
ZergLev Sep 25, 2024
7bb22c9
tutorial mistake fixed
ZergLev Sep 25, 2024
f21d9cd
3rd pipeline tutorial slightly tweaked as we agreed
ZergLev Sep 25, 2024
89b54a8
refactored pipeline tutorials 4 and 5 now
ZergLev Sep 25, 2024
04729dd
lint
ZergLev Sep 25, 2024
237e776
make ServiceFinished wait by default
RLKRo Sep 25, 2024
e72b35f
remove task creation from component call
RLKRo Sep 25, 2024
b6a315f
fix services with BaseProcessing handlers
RLKRo Sep 25, 2024
af3353e
remove outdated service call
RLKRo Sep 25, 2024
6b667bf
add documentation to initialize_service_states
RLKRo Sep 25, 2024
e90e0f3
add pre-service, actor, post-service order test
RLKRo Sep 25, 2024
e617388
assert logs for failed stats collection test
RLKRo Sep 25, 2024
0770cd2
unrelated: add slow marks to some test cases
RLKRo Sep 25, 2024
083faa6
restrict types that validate into service
RLKRo Sep 25, 2024
37badf1
revert validation of ServiceGroup from list
RLKRo Sep 25, 2024
054c688
remove ServiceFunction type
RLKRo Sep 26, 2024
1b93af7
rename asynchronous to concurrent
RLKRo Sep 26, 2024
881d691
add BaseProcessing to ServiceInitTypes
RLKRo Sep 26, 2024
869ba28
remove .pipeline prefix from service paths
RLKRo Sep 26, 2024
09e9c8f
improve rename_component_incrementing
RLKRo Sep 26, 2024
0ec0760
make test utils async; remove asyncio.run
RLKRo Sep 26, 2024
8bb2e8b
remove GlobalExtraHandlerType
RLKRo Sep 26, 2024
6c3727b
add docstring to computed names
RLKRo Sep 26, 2024
4319210
remove UNDEFINED extra handler type
RLKRo Sep 26, 2024
ce13f50
minor doc changes
RLKRo Sep 26, 2024
a1ddc11
lint
RLKRo Sep 27, 2024
412cc8d
remove func from extra handler runtime info
RLKRo Sep 27, 2024
d63b915
pipeline tutorial rewrite
RLKRo Sep 27, 2024
d2a946e
rename tutorials files; move to service directory
RLKRo Sep 27, 2024
0193a15
remove pipeline argument from sample data provider
RLKRo Sep 27, 2024
37112b3
use toy_script_kwargs in stats tutorials
RLKRo Sep 27, 2024
37efe95
doc updates
RLKRo Sep 27, 2024
d30d28f
Merge branch 'refs/heads/dev' into feat/service_option_update
RLKRo Sep 27, 2024
403d6ec
revert making wait True by default
RLKRo Sep 27, 2024
13c61da
update service conditions module docstring
RLKRo Sep 27, 2024
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
7 changes: 5 additions & 2 deletions chatsky/__rebuild_pydantic_models__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# flake8: noqa: F401

from chatsky.core.service.types import ExtraHandlerRuntimeInfo, StartConditionCheckerFunction, ComponentExecutionState
from chatsky.core.service.types import ExtraHandlerRuntimeInfo, ComponentExecutionState
from chatsky.core import Context, Script
from chatsky.core.script import Node
from chatsky.core.pipeline import Pipeline
from chatsky.slots.slots import SlotManager
from chatsky.core.context import FrameworkData
from chatsky.core.context import FrameworkData, ServiceState
from chatsky.core.service import PipelineComponent

PipelineComponent.model_rebuild()
Pipeline.model_rebuild()
Script.model_rebuild()
Context.model_rebuild()
ExtraHandlerRuntimeInfo.model_rebuild()
FrameworkData.model_rebuild()
ServiceState.model_rebuild()
1 change: 1 addition & 0 deletions chatsky/conditions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
HasCallbackQuery,
)
from chatsky.conditions.slots import SlotsExtracted
from chatsky.conditions.service import ServiceFinished
40 changes: 40 additions & 0 deletions chatsky/conditions/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Service Conditions
------------------
Provides service-related conditions
"""

from __future__ import annotations

from chatsky.core.context import Context
from chatsky.core.script_function import BaseCondition

from chatsky.core.service.types import (
ComponentExecutionState,
)


class ServiceFinished(BaseCondition):
"""
Check if a :py:class:`~chatsky.core.service.service.Service` was executed successfully.
"""

path: str
"""The path of the condition pipeline component."""
wait: bool = False
"""
Whether to wait for the service to be finished.

This eliminates possible service states ``NOT_RUN`` and ``RUNNING``.
"""

def __init__(self, path: str, *, wait: bool = False):
super().__init__(path=path, wait=wait)

async def call(self, ctx: Context) -> bool:
if self.wait:
await ctx.framework_data.service_states[self.path].finished_event.wait()

state = ctx.framework_data.service_states[self.path].execution_status

return ComponentExecutionState[state] == ComponentExecutionState.FINISHED
25 changes: 21 additions & 4 deletions chatsky/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from __future__ import annotations
import logging
import asyncio
from uuid import UUID, uuid4
from typing import Any, Optional, Union, Dict, TYPE_CHECKING

Expand All @@ -28,9 +29,9 @@
from chatsky.core.node_label import AbsoluteNodeLabel, AbsoluteNodeLabelInitTypes

if TYPE_CHECKING:
from chatsky.core.service import ComponentExecutionState
from chatsky.core.script import Node
from chatsky.core.pipeline import Pipeline
from chatsky.core.service.types import ComponentExecutionState

logger = logging.getLogger(__name__)

Expand All @@ -53,13 +54,29 @@ class ContextError(Exception):
"""Raised when context methods are not used correctly."""


class FrameworkData(BaseModel):
class ServiceState(BaseModel, arbitrary_types_allowed=True):
execution_status: ComponentExecutionState = Field(default="NOT_RUN")
"""
:py:class:`.ComponentExecutionState` of this pipeline service.
Cleared at the end of every turn.
"""
finished_event: asyncio.Event = Field(default_factory=asyncio.Event)
"""
Asyncio `Event` which can be awaited until this service finishes.
Cleared at the end of every turn.
"""


class FrameworkData(BaseModel, arbitrary_types_allowed=True):
"""
Framework uses this to store data related to any of its modules.
"""

service_states: Dict[str, ComponentExecutionState] = Field(default_factory=dict, exclude=True)
"Statuses of all the pipeline services. Cleared at the end of every turn."
service_states: Dict[str, ServiceState] = Field(default_factory=dict, exclude=True)
"""
Dictionary containing :py:class:`.ServiceState` of all the pipeline components.
Cleared at the end of every turn.
"""
current_node: Optional[Node] = Field(default=None, exclude=True)
"""
A copy of the current node provided by :py:meth:`~chatsky.core.script.Script.get_inherited_node`.
Expand Down
84 changes: 5 additions & 79 deletions chatsky/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@
from chatsky.slots.slots import GroupSlot
from chatsky.core.service.group import ServiceGroup, ServiceGroupInitTypes
from chatsky.core.service.extra import ComponentExtraHandlerInitTypes, BeforeHandler, AfterHandler
from chatsky.core.service.types import (
GlobalExtraHandlerType,
ExtraHandlerFunction,
)
from .service import Service
from .utils import finalize_service_group
from .utils import finalize_service_group, initialize_service_states
from chatsky.core.service.actor import Actor
from chatsky.core.node_label import AbsoluteNodeLabel, AbsoluteNodeLabelInitTypes
from chatsky.core.script_parsing import JSONImporter, Path
Expand Down Expand Up @@ -104,15 +100,6 @@ class Pipeline(BaseModel, extra="forbid", arbitrary_types_allowed=True):
timeout: Optional[float] = None
"""
Timeout to add to pipeline root service group.
"""
optimization_warnings: bool = False
"""
Asynchronous pipeline optimization check request flag;
warnings will be sent to logs. Additionally, it has some calculated fields:

- `services_pipeline` is a pipeline root :py:class:`~.ServiceGroup` object,
- `actor` is a pipeline actor, found among services.

"""
parallelize_processing: bool = False
"""
Expand All @@ -136,7 +123,6 @@ def __init__(
before_handler: ComponentExtraHandlerInitTypes = None,
after_handler: ComponentExtraHandlerInitTypes = None,
timeout: float = None,
optimization_warnings: bool = None,
parallelize_processing: bool = None,
):
if fallback_label is None:
Expand All @@ -154,7 +140,6 @@ def __init__(
"before_handler": before_handler,
"after_handler": after_handler,
"timeout": timeout,
"optimization_warnings": optimization_warnings,
"parallelize_processing": parallelize_processing,
}
empty_fields = set()
Expand Down Expand Up @@ -216,14 +201,11 @@ def services_pipeline(self) -> PipelineServiceGroup:
after_handler=self.after_handler,
timeout=self.timeout,
)
services_pipeline.name = "pipeline"
services_pipeline.path = ".pipeline"
services_pipeline.name = ""
services_pipeline.path = ""

finalize_service_group(services_pipeline, path=services_pipeline.path)

if self.optimization_warnings:
services_pipeline.log_optimization_warnings()

return services_pipeline

@model_validator(mode="after")
Expand All @@ -240,60 +222,6 @@ def validate_fallback_label(self):
raise ValueError(f"Unknown fallback_label={self.fallback_label}")
return self

def add_global_handler(
self,
global_handler_type: GlobalExtraHandlerType,
extra_handler: ExtraHandlerFunction,
whitelist: Optional[List[str]] = None,
blacklist: Optional[List[str]] = None,
):
"""
Method for adding global wrappers to pipeline.
Different types of global wrappers are called before/after pipeline execution
or before/after each pipeline component.
They can be used for pipeline statistics collection or other functionality extensions.
NB! Global wrappers are still wrappers,
they shouldn't be used for much time-consuming tasks (see :py:mod:`chatsky.core.service.extra`).

:param global_handler_type: (required) indication where the wrapper
function should be executed.
:param extra_handler: (required) wrapper function itself.
:type extra_handler: ExtraHandlerFunction
:param whitelist: a list of services to only add this wrapper to.
:param blacklist: a list of services to not add this wrapper to.
:return: `None`
"""

def condition(name: str) -> bool:
return (whitelist is None or name in whitelist) and (blacklist is None or name not in blacklist)

if (
global_handler_type is GlobalExtraHandlerType.BEFORE_ALL
or global_handler_type is GlobalExtraHandlerType.AFTER_ALL
):
whitelist = ["pipeline"]
global_handler_type = (
GlobalExtraHandlerType.BEFORE
if global_handler_type is GlobalExtraHandlerType.BEFORE_ALL
else GlobalExtraHandlerType.AFTER
)

self.services_pipeline.add_extra_handler(global_handler_type, extra_handler, condition)

@property
def info_dict(self) -> dict:
"""
Property for retrieving info dictionary about this pipeline.
Returns info dict, containing most important component public fields as well as its type.
All complex or unserializable fields here are replaced with 'Instance of [type]'.
"""
return {
"type": type(self).__name__,
"messenger_interface": f"Instance of {type(self.messenger_interface).__name__}",
"context_storage": f"Instance of {type(self.context_storage).__name__}",
"services": [self.services_pipeline.info_dict],
}

async def _run_pipeline(
self, request: Message, ctx_id: Optional[Hashable] = None, update_ctx_misc: Optional[dict] = None
) -> Context:
Expand Down Expand Up @@ -329,12 +257,10 @@ async def _run_pipeline(
ctx.framework_data.slot_manager.set_root_slot(self.slots)

ctx.framework_data.pipeline = self
initialize_service_states(ctx, self.services_pipeline)

ctx.add_request(request)
result = await self.services_pipeline(ctx, self)

if asyncio.iscoroutine(result):
await result
await self.services_pipeline(ctx)

ctx.framework_data.service_states.clear()
ctx.framework_data.pipeline = None
Expand Down
2 changes: 1 addition & 1 deletion chatsky/core/script_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def wrapped_call(self, ctx: Context, *, info: str = ""):
logger.debug(f"Function {self.__class__.__name__} returned {result!r}. {info}")
return result
except Exception as exc:
logger.warning(f"An exception occurred in {self.__class__.__name__}. {info}", exc_info=exc)
logger.error(f"An exception occurred in {self.__class__.__name__}. {info}", exc_info=exc)
return exc

async def __call__(self, ctx: Context):
Expand Down
11 changes: 0 additions & 11 deletions chatsky/core/service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@
"""

from .component import PipelineComponent
from .conditions import (
always_start_condition,
service_successful_condition,
not_condition,
all_condition,
any_condition,
)
from .extra import BeforeHandler, AfterHandler
from .group import ServiceGroup
from .service import Service, to_service
from .types import (
ServiceRuntimeInfo,
ExtraHandlerRuntimeInfo,
GlobalExtraHandlerType,
ExtraHandlerType,
PipelineRunnerFunction,
ComponentExecutionState,
StartConditionCheckerFunction,
ExtraHandlerConditionFunction,
ExtraHandlerFunction,
ServiceFunction,
)
24 changes: 9 additions & 15 deletions chatsky/core/service/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from __future__ import annotations
import logging
import asyncio
from typing import TYPE_CHECKING, Dict
from pydantic import model_validator
from typing import Dict

from chatsky.core.service.component import PipelineComponent
from chatsky.core.transition import get_next_label
Expand All @@ -25,9 +24,6 @@
from chatsky.core.context import Context
from chatsky.core.script_function import BaseProcessing

if TYPE_CHECKING:
from chatsky.core.pipeline import Pipeline

logger = logging.getLogger(__name__)


Expand All @@ -37,16 +33,14 @@ class Actor(PipelineComponent):
according to the :py:class:`~chatsky.core.script.Script`.
"""

@model_validator(mode="after")
def __tick_async_flag__(self):
self.calculated_async_flag = False
return self

@property
def computed_name(self) -> str:
"""
"actor"
"""
return "actor"

async def run_component(self, ctx: Context, pipeline: Pipeline) -> None:
async def run_component(self, ctx: Context) -> None:
"""
Process the context in the following way:

Expand All @@ -56,17 +50,17 @@ async def run_component(self, ctx: Context, pipeline: Pipeline) -> None:
3. Run pre-response of the :py:attr:`.Context.current_node`.
4. Determine and save the response of the :py:attr:`.Context.current_node`
"""
next_label = pipeline.fallback_label
next_label = ctx.pipeline.fallback_label

try:
ctx.framework_data.current_node = pipeline.script.get_inherited_node(ctx.last_label)
ctx.framework_data.current_node = ctx.pipeline.script.get_inherited_node(ctx.last_label)

logger.debug("Running pre_transition")
await self._run_processing(ctx.current_node.pre_transition, ctx)

logger.debug("Running transitions")

destination_result = await get_next_label(ctx, ctx.current_node.transitions, pipeline.default_priority)
destination_result = await get_next_label(ctx, ctx.current_node.transitions, ctx.pipeline.default_priority)
if destination_result is not None:
next_label = destination_result
except Exception as exc:
Expand All @@ -79,7 +73,7 @@ async def run_component(self, ctx: Context, pipeline: Pipeline) -> None:
response = Message()

try:
ctx.framework_data.current_node = pipeline.script.get_inherited_node(next_label)
ctx.framework_data.current_node = ctx.pipeline.script.get_inherited_node(next_label)

logger.debug("Running pre_response")
await self._run_processing(ctx.current_node.pre_response, ctx)
Expand Down
Loading
Loading