flowstate-sdk 0.1.12__tar.gz → 0.1.14__tar.gz
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.
- {flowstate_sdk-0.1.12/src/flowstate_sdk.egg-info → flowstate_sdk-0.1.14}/PKG-INFO +1 -1
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/pyproject.toml +1 -1
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/context.py +3 -0
- flowstate_sdk-0.1.14/src/flowstate_sdk/langchain/__init__.py +15 -0
- flowstate_sdk-0.1.14/src/flowstate_sdk/langchain/callback_handler.py +3 -0
- flowstate_sdk-0.1.14/src/flowstate_sdk/langchain/chat_models.py +91 -0
- flowstate_sdk-0.1.14/src/flowstate_sdk/langchain/flowstate_chat_base.py +51 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/sdk_client.py +1 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/workflow.py +7 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14/src/flowstate_sdk.egg-info}/PKG-INFO +1 -1
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk.egg-info/SOURCES.txt +5 -1
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/LICENSE +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/README.md +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/setup.cfg +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/__init__.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/constants.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/cost_table.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/decorators.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/enums.py +0 -0
- /flowstate_sdk-0.1.12/src/flowstate_sdk/langchain/callback_handler.py → /flowstate_sdk-0.1.14/src/flowstate_sdk/langchain/telemetry.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/shared_dataclasses.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/task.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk/task_context.py +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk.egg-info/dependency_links.txt +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk.egg-info/requires.txt +0 -0
- {flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk.egg-info/top_level.txt +0 -0
|
@@ -7,3 +7,6 @@ run_stack: ContextVar[List[str]] = ContextVar("run_stack", default=[])
|
|
|
7
7
|
parent_children_mappings: ContextVar[Dict[str, Set[str]]] = ContextVar(
|
|
8
8
|
"parent_children_mappings", default=defaultdict(set)
|
|
9
9
|
)
|
|
10
|
+
is_replay: ContextVar[bool] = ContextVar("is_replay", default=False)
|
|
11
|
+
replay_counter: ContextVar[int] = ContextVar("replay_counter", default=0)
|
|
12
|
+
replay_step_list: ContextVar[List[str]] = ContextVar("replay_step_list", default=[])
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from flowstate_sdk.langchain.callback_handler import FlowstateCallbackHandler
|
|
2
|
+
from flowstate_sdk.langchain.chat_models import (
|
|
3
|
+
FlowstateChatAnthropic,
|
|
4
|
+
FlowstateChatClaude,
|
|
5
|
+
FlowstateChatGoogle,
|
|
6
|
+
FlowstateChatOpenAI,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"FlowstateCallbackHandler",
|
|
11
|
+
"FlowstateChatOpenAI",
|
|
12
|
+
"FlowstateChatAnthropic",
|
|
13
|
+
"FlowstateChatClaude",
|
|
14
|
+
"FlowstateChatGoogle",
|
|
15
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from flowstate_sdk.langchain.flowstate_chat_base import FlowstateChatModelMixin
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from langchain_openai import ChatOpenAI
|
|
9
|
+
except Exception: # pragma: no cover - optional dependency
|
|
10
|
+
ChatOpenAI = None
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
from langchain_anthropic import ChatAnthropic
|
|
14
|
+
except Exception: # pragma: no cover - optional dependency
|
|
15
|
+
ChatAnthropic = None
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
19
|
+
except Exception: # pragma: no cover - optional dependency
|
|
20
|
+
ChatGoogleGenerativeAI = None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _missing_dependency(name: str, package: str) -> None:
|
|
24
|
+
raise ImportError(
|
|
25
|
+
f"{name} requires optional dependency '{package}'. "
|
|
26
|
+
f"Install it to use this Flowstate wrapper."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if ChatOpenAI is not None:
|
|
31
|
+
|
|
32
|
+
class FlowstateChatOpenAI(FlowstateChatModelMixin, ChatOpenAI):
|
|
33
|
+
provider = "openai"
|
|
34
|
+
|
|
35
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
36
|
+
kwargs = self._flowstate_init_kwargs(kwargs)
|
|
37
|
+
super().__init__(*args, **kwargs)
|
|
38
|
+
|
|
39
|
+
else:
|
|
40
|
+
|
|
41
|
+
class FlowstateChatOpenAI(FlowstateChatModelMixin): # type: ignore[misc]
|
|
42
|
+
provider = "openai"
|
|
43
|
+
|
|
44
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
45
|
+
_missing_dependency("FlowstateChatOpenAI", "langchain-openai")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if ChatAnthropic is not None:
|
|
49
|
+
|
|
50
|
+
class FlowstateChatAnthropic(FlowstateChatModelMixin, ChatAnthropic):
|
|
51
|
+
provider = "anthropic"
|
|
52
|
+
|
|
53
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
54
|
+
kwargs = self._flowstate_init_kwargs(kwargs)
|
|
55
|
+
super().__init__(*args, **kwargs)
|
|
56
|
+
|
|
57
|
+
else:
|
|
58
|
+
|
|
59
|
+
class FlowstateChatAnthropic(FlowstateChatModelMixin): # type: ignore[misc]
|
|
60
|
+
provider = "anthropic"
|
|
61
|
+
|
|
62
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
63
|
+
_missing_dependency("FlowstateChatAnthropic", "langchain-anthropic")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if ChatGoogleGenerativeAI is not None:
|
|
67
|
+
|
|
68
|
+
class FlowstateChatGoogle(FlowstateChatModelMixin, ChatGoogleGenerativeAI):
|
|
69
|
+
provider = "google"
|
|
70
|
+
|
|
71
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
72
|
+
kwargs = self._flowstate_init_kwargs(kwargs)
|
|
73
|
+
super().__init__(*args, **kwargs)
|
|
74
|
+
|
|
75
|
+
else:
|
|
76
|
+
|
|
77
|
+
class FlowstateChatGoogle(FlowstateChatModelMixin): # type: ignore[misc]
|
|
78
|
+
provider = "google"
|
|
79
|
+
|
|
80
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
81
|
+
_missing_dependency("FlowstateChatGoogle", "langchain-google-genai")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
FlowstateChatClaude = FlowstateChatAnthropic
|
|
85
|
+
|
|
86
|
+
__all__ = [
|
|
87
|
+
"FlowstateChatOpenAI",
|
|
88
|
+
"FlowstateChatAnthropic",
|
|
89
|
+
"FlowstateChatClaude",
|
|
90
|
+
"FlowstateChatGoogle",
|
|
91
|
+
]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, Iterable, List, Optional
|
|
4
|
+
|
|
5
|
+
from flowstate_sdk.langchain.telemetry import FlowstateCallbackHandler
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _extract_model_name(kwargs: Dict[str, Any]) -> Optional[str]:
|
|
9
|
+
for key in ("model", "model_name", "model_id"):
|
|
10
|
+
val = kwargs.get(key)
|
|
11
|
+
if isinstance(val, str) and val.strip():
|
|
12
|
+
return val
|
|
13
|
+
return None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _normalize_callbacks(callbacks: Any) -> List[Any]:
|
|
17
|
+
if callbacks is None:
|
|
18
|
+
return []
|
|
19
|
+
if isinstance(callbacks, list):
|
|
20
|
+
return list(callbacks)
|
|
21
|
+
if isinstance(callbacks, tuple):
|
|
22
|
+
return list(callbacks)
|
|
23
|
+
return [callbacks]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _has_flowstate_callback(callbacks: Iterable[Any]) -> bool:
|
|
27
|
+
for cb in callbacks:
|
|
28
|
+
if isinstance(cb, FlowstateCallbackHandler):
|
|
29
|
+
return True
|
|
30
|
+
return False
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _merge_callbacks(existing: Any, additional: List[Any]) -> List[Any]:
|
|
34
|
+
existing_list = _normalize_callbacks(existing)
|
|
35
|
+
if _has_flowstate_callback(existing_list):
|
|
36
|
+
return existing_list
|
|
37
|
+
return existing_list + list(additional)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class FlowstateChatModelMixin:
|
|
41
|
+
provider: str = ""
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def _flowstate_build_callbacks(cls, kwargs: Dict[str, Any]) -> List[Any]:
|
|
45
|
+
model = _extract_model_name(kwargs) or "unknown"
|
|
46
|
+
handler = FlowstateCallbackHandler(cls.provider, model)
|
|
47
|
+
return _merge_callbacks(kwargs.pop("callbacks", None), [handler])
|
|
48
|
+
|
|
49
|
+
def _flowstate_init_kwargs(self, kwargs: Dict[str, Any]) -> Dict[str, Any]:
|
|
50
|
+
kwargs["callbacks"] = self._flowstate_build_callbacks(kwargs)
|
|
51
|
+
return kwargs
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import uuid
|
|
2
2
|
from collections import defaultdict
|
|
3
3
|
from datetime import datetime
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
from . import context
|
|
6
7
|
from .sdk_client import SDKClient
|
|
@@ -40,6 +41,12 @@ class Workflow:
|
|
|
40
41
|
}
|
|
41
42
|
self.client.emit(workflow_payload)
|
|
42
43
|
|
|
44
|
+
if os.getenv("IS_FLOWSTATE_REPLAY"):
|
|
45
|
+
replay_list = self.client.retrieve_replay_plan(os.getenv("FLOWSTATE_REPLAY_PARENT_ID"))
|
|
46
|
+
context.replay_counter.set(0)
|
|
47
|
+
context.replay_step_list.set(replay_list)
|
|
48
|
+
context.is_replay.set(True)
|
|
49
|
+
|
|
43
50
|
run_payload = RunRecord(
|
|
44
51
|
run_id=str(self.run_id),
|
|
45
52
|
workflow_id=str(self.workflow_id),
|
|
@@ -17,4 +17,8 @@ src/flowstate_sdk.egg-info/SOURCES.txt
|
|
|
17
17
|
src/flowstate_sdk.egg-info/dependency_links.txt
|
|
18
18
|
src/flowstate_sdk.egg-info/requires.txt
|
|
19
19
|
src/flowstate_sdk.egg-info/top_level.txt
|
|
20
|
-
src/flowstate_sdk/langchain/
|
|
20
|
+
src/flowstate_sdk/langchain/__init__.py
|
|
21
|
+
src/flowstate_sdk/langchain/callback_handler.py
|
|
22
|
+
src/flowstate_sdk/langchain/chat_models.py
|
|
23
|
+
src/flowstate_sdk/langchain/flowstate_chat_base.py
|
|
24
|
+
src/flowstate_sdk/langchain/telemetry.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flowstate_sdk-0.1.12 → flowstate_sdk-0.1.14}/src/flowstate_sdk.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|