chainlit 2.7.0__py3-none-any.whl → 2.7.1__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 chainlit might be problematic. Click here for more details.
- {chainlit-2.7.0.dist-info → chainlit-2.7.1.dist-info}/METADATA +1 -1
- chainlit-2.7.1.dist-info/RECORD +4 -0
- chainlit/__init__.py +0 -207
- chainlit/__main__.py +0 -4
- chainlit/_utils.py +0 -8
- chainlit/action.py +0 -33
- chainlit/auth/__init__.py +0 -95
- chainlit/auth/cookie.py +0 -197
- chainlit/auth/jwt.py +0 -42
- chainlit/cache.py +0 -45
- chainlit/callbacks.py +0 -433
- chainlit/chat_context.py +0 -64
- chainlit/chat_settings.py +0 -34
- chainlit/cli/__init__.py +0 -235
- chainlit/config.py +0 -621
- chainlit/context.py +0 -112
- chainlit/data/__init__.py +0 -111
- chainlit/data/acl.py +0 -19
- chainlit/data/base.py +0 -107
- chainlit/data/chainlit_data_layer.py +0 -687
- chainlit/data/dynamodb.py +0 -616
- chainlit/data/literalai.py +0 -501
- chainlit/data/sql_alchemy.py +0 -741
- chainlit/data/storage_clients/__init__.py +0 -0
- chainlit/data/storage_clients/azure.py +0 -84
- chainlit/data/storage_clients/azure_blob.py +0 -94
- chainlit/data/storage_clients/base.py +0 -28
- chainlit/data/storage_clients/gcs.py +0 -101
- chainlit/data/storage_clients/s3.py +0 -88
- chainlit/data/utils.py +0 -29
- chainlit/discord/__init__.py +0 -6
- chainlit/discord/app.py +0 -364
- chainlit/element.py +0 -454
- chainlit/emitter.py +0 -450
- chainlit/hello.py +0 -12
- chainlit/input_widget.py +0 -182
- chainlit/langchain/__init__.py +0 -6
- chainlit/langchain/callbacks.py +0 -682
- chainlit/langflow/__init__.py +0 -25
- chainlit/llama_index/__init__.py +0 -6
- chainlit/llama_index/callbacks.py +0 -206
- chainlit/logger.py +0 -16
- chainlit/markdown.py +0 -57
- chainlit/mcp.py +0 -99
- chainlit/message.py +0 -619
- chainlit/mistralai/__init__.py +0 -50
- chainlit/oauth_providers.py +0 -835
- chainlit/openai/__init__.py +0 -53
- chainlit/py.typed +0 -0
- chainlit/secret.py +0 -9
- chainlit/semantic_kernel/__init__.py +0 -111
- chainlit/server.py +0 -1616
- chainlit/session.py +0 -304
- chainlit/sidebar.py +0 -55
- chainlit/slack/__init__.py +0 -6
- chainlit/slack/app.py +0 -427
- chainlit/socket.py +0 -381
- chainlit/step.py +0 -490
- chainlit/sync.py +0 -43
- chainlit/teams/__init__.py +0 -6
- chainlit/teams/app.py +0 -348
- chainlit/translations/bn.json +0 -214
- chainlit/translations/el-GR.json +0 -214
- chainlit/translations/en-US.json +0 -214
- chainlit/translations/fr-FR.json +0 -214
- chainlit/translations/gu.json +0 -214
- chainlit/translations/he-IL.json +0 -214
- chainlit/translations/hi.json +0 -214
- chainlit/translations/ja.json +0 -214
- chainlit/translations/kn.json +0 -214
- chainlit/translations/ml.json +0 -214
- chainlit/translations/mr.json +0 -214
- chainlit/translations/nl.json +0 -214
- chainlit/translations/ta.json +0 -214
- chainlit/translations/te.json +0 -214
- chainlit/translations/zh-CN.json +0 -214
- chainlit/translations.py +0 -60
- chainlit/types.py +0 -334
- chainlit/user.py +0 -43
- chainlit/user_session.py +0 -153
- chainlit/utils.py +0 -173
- chainlit/version.py +0 -8
- chainlit-2.7.0.dist-info/RECORD +0 -84
- {chainlit-2.7.0.dist-info → chainlit-2.7.1.dist-info}/WHEEL +0 -0
- {chainlit-2.7.0.dist-info → chainlit-2.7.1.dist-info}/entry_points.txt +0 -0
chainlit/context.py
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import uuid
|
|
3
|
-
from contextvars import ContextVar
|
|
4
|
-
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
|
5
|
-
|
|
6
|
-
from lazify import LazyProxy
|
|
7
|
-
|
|
8
|
-
from chainlit.session import ClientType, HTTPSession, WebsocketSession
|
|
9
|
-
|
|
10
|
-
if TYPE_CHECKING:
|
|
11
|
-
from chainlit.emitter import BaseChainlitEmitter
|
|
12
|
-
from chainlit.step import Step
|
|
13
|
-
from chainlit.user import PersistedUser, User
|
|
14
|
-
|
|
15
|
-
CL_RUN_NAMES = ["on_chat_start", "on_message", "on_audio_end"]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class ChainlitContextException(Exception):
|
|
19
|
-
def __init__(self, msg="Chainlit context not found", *args, **kwargs):
|
|
20
|
-
super().__init__(msg, *args, **kwargs)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class ChainlitContext:
|
|
24
|
-
loop: asyncio.AbstractEventLoop
|
|
25
|
-
emitter: "BaseChainlitEmitter"
|
|
26
|
-
session: Union["HTTPSession", "WebsocketSession"]
|
|
27
|
-
|
|
28
|
-
@property
|
|
29
|
-
def current_step(self):
|
|
30
|
-
if previous_steps := local_steps.get():
|
|
31
|
-
return previous_steps[-1]
|
|
32
|
-
|
|
33
|
-
@property
|
|
34
|
-
def current_run(self):
|
|
35
|
-
if previous_steps := local_steps.get():
|
|
36
|
-
return next(
|
|
37
|
-
(step for step in previous_steps if step.name in CL_RUN_NAMES), None
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
def __init__(
|
|
41
|
-
self,
|
|
42
|
-
session: Union["HTTPSession", "WebsocketSession"],
|
|
43
|
-
emitter: Optional["BaseChainlitEmitter"] = None,
|
|
44
|
-
):
|
|
45
|
-
from chainlit.emitter import BaseChainlitEmitter, ChainlitEmitter
|
|
46
|
-
|
|
47
|
-
self.loop = asyncio.get_running_loop()
|
|
48
|
-
self.session = session
|
|
49
|
-
|
|
50
|
-
if emitter:
|
|
51
|
-
self.emitter = emitter
|
|
52
|
-
elif isinstance(self.session, HTTPSession):
|
|
53
|
-
self.emitter = BaseChainlitEmitter(self.session)
|
|
54
|
-
elif isinstance(self.session, WebsocketSession):
|
|
55
|
-
self.emitter = ChainlitEmitter(self.session)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
context_var: ContextVar[ChainlitContext] = ContextVar("chainlit")
|
|
59
|
-
local_steps: ContextVar[Optional[List["Step"]]] = ContextVar(
|
|
60
|
-
"local_steps", default=None
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def init_ws_context(session_or_sid: Union[WebsocketSession, str]) -> ChainlitContext:
|
|
65
|
-
if not isinstance(session_or_sid, WebsocketSession):
|
|
66
|
-
session = WebsocketSession.require(session_or_sid)
|
|
67
|
-
else:
|
|
68
|
-
session = session_or_sid
|
|
69
|
-
context = ChainlitContext(session)
|
|
70
|
-
context_var.set(context)
|
|
71
|
-
return context
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def init_http_context(
|
|
75
|
-
thread_id: Optional[str] = None,
|
|
76
|
-
user: Optional[Union["User", "PersistedUser"]] = None,
|
|
77
|
-
auth_token: Optional[str] = None,
|
|
78
|
-
user_env: Optional[Dict[str, str]] = None,
|
|
79
|
-
client_type: ClientType = "webapp",
|
|
80
|
-
) -> ChainlitContext:
|
|
81
|
-
from chainlit.data import get_data_layer
|
|
82
|
-
|
|
83
|
-
session_id = str(uuid.uuid4())
|
|
84
|
-
thread_id = thread_id or str(uuid.uuid4())
|
|
85
|
-
session = HTTPSession(
|
|
86
|
-
id=session_id,
|
|
87
|
-
thread_id=thread_id,
|
|
88
|
-
token=auth_token,
|
|
89
|
-
user=user,
|
|
90
|
-
client_type=client_type,
|
|
91
|
-
user_env=user_env,
|
|
92
|
-
)
|
|
93
|
-
context = ChainlitContext(session)
|
|
94
|
-
context_var.set(context)
|
|
95
|
-
|
|
96
|
-
if data_layer := get_data_layer():
|
|
97
|
-
if user_id := getattr(user, "id", None):
|
|
98
|
-
asyncio.create_task(
|
|
99
|
-
data_layer.update_thread(thread_id=thread_id, user_id=user_id)
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
return context
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def get_context() -> ChainlitContext:
|
|
106
|
-
try:
|
|
107
|
-
return context_var.get()
|
|
108
|
-
except LookupError as e:
|
|
109
|
-
raise ChainlitContextException from e
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
context: ChainlitContext = LazyProxy(get_context, enable_cache=False)
|
chainlit/data/__init__.py
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import warnings
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
|
-
from .base import BaseDataLayer
|
|
6
|
-
from .utils import (
|
|
7
|
-
queue_until_user_message as queue_until_user_message, # TODO: Consider deprecating re-export.; Redundant alias tells type checkers to STFU.
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
_data_layer: Optional[BaseDataLayer] = None
|
|
11
|
-
_data_layer_initialized = False
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def get_data_layer():
|
|
15
|
-
global _data_layer, _data_layer_initialized
|
|
16
|
-
|
|
17
|
-
if not _data_layer_initialized:
|
|
18
|
-
if _data_layer:
|
|
19
|
-
# Data layer manually set, warn user that this is deprecated.
|
|
20
|
-
|
|
21
|
-
warnings.warn(
|
|
22
|
-
"Setting data layer manually is deprecated. Use @data_layer instead.",
|
|
23
|
-
DeprecationWarning,
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
else:
|
|
27
|
-
from chainlit.config import config
|
|
28
|
-
|
|
29
|
-
if config.code.data_layer:
|
|
30
|
-
# When @data_layer is configured, call it to get data layer.
|
|
31
|
-
_data_layer = config.code.data_layer()
|
|
32
|
-
elif database_url := os.environ.get("DATABASE_URL"):
|
|
33
|
-
from .chainlit_data_layer import ChainlitDataLayer
|
|
34
|
-
|
|
35
|
-
if os.environ.get("LITERAL_API_KEY"):
|
|
36
|
-
warnings.warn(
|
|
37
|
-
"Both LITERAL_API_KEY and DATABASE_URL specified. Ignoring Literal AI data layer and relying on data layer pointing to DATABASE_URL."
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
bucket_name = os.environ.get("BUCKET_NAME")
|
|
41
|
-
|
|
42
|
-
# AWS S3
|
|
43
|
-
aws_region = os.getenv("APP_AWS_REGION")
|
|
44
|
-
aws_access_key = os.getenv("APP_AWS_ACCESS_KEY")
|
|
45
|
-
aws_secret_key = os.getenv("APP_AWS_SECRET_KEY")
|
|
46
|
-
dev_aws_endpoint = os.getenv("DEV_AWS_ENDPOINT")
|
|
47
|
-
is_using_s3 = bool(aws_access_key and aws_secret_key and aws_region)
|
|
48
|
-
|
|
49
|
-
# Google Cloud Storage
|
|
50
|
-
gcs_project_id = os.getenv("APP_GCS_PROJECT_ID")
|
|
51
|
-
gcs_client_email = os.getenv("APP_GCS_CLIENT_EMAIL")
|
|
52
|
-
gcs_private_key = os.getenv("APP_GCS_PRIVATE_KEY")
|
|
53
|
-
is_using_gcs = bool(gcs_project_id)
|
|
54
|
-
|
|
55
|
-
# Azure Storage
|
|
56
|
-
azure_storage_account = os.getenv("APP_AZURE_STORAGE_ACCOUNT")
|
|
57
|
-
azure_storage_key = os.getenv("APP_AZURE_STORAGE_ACCESS_KEY")
|
|
58
|
-
is_using_azure = bool(azure_storage_account and azure_storage_key)
|
|
59
|
-
|
|
60
|
-
storage_client = None
|
|
61
|
-
|
|
62
|
-
if sum([is_using_s3, is_using_gcs, is_using_azure]) > 1:
|
|
63
|
-
warnings.warn(
|
|
64
|
-
"Multiple storage configurations detected. Please use only one."
|
|
65
|
-
)
|
|
66
|
-
elif is_using_s3:
|
|
67
|
-
from chainlit.data.storage_clients.s3 import S3StorageClient
|
|
68
|
-
|
|
69
|
-
storage_client = S3StorageClient(
|
|
70
|
-
bucket=bucket_name,
|
|
71
|
-
region_name=aws_region,
|
|
72
|
-
aws_access_key_id=aws_access_key,
|
|
73
|
-
aws_secret_access_key=aws_secret_key,
|
|
74
|
-
endpoint_url=dev_aws_endpoint,
|
|
75
|
-
)
|
|
76
|
-
elif is_using_gcs:
|
|
77
|
-
from chainlit.data.storage_clients.gcs import GCSStorageClient
|
|
78
|
-
|
|
79
|
-
storage_client = GCSStorageClient(
|
|
80
|
-
project_id=gcs_project_id,
|
|
81
|
-
client_email=gcs_client_email,
|
|
82
|
-
private_key=gcs_private_key,
|
|
83
|
-
bucket_name=bucket_name,
|
|
84
|
-
)
|
|
85
|
-
elif is_using_azure:
|
|
86
|
-
from chainlit.data.storage_clients.azure_blob import (
|
|
87
|
-
AzureBlobStorageClient,
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
storage_client = AzureBlobStorageClient(
|
|
91
|
-
container_name=bucket_name,
|
|
92
|
-
storage_account=azure_storage_account,
|
|
93
|
-
storage_key=azure_storage_key,
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
_data_layer = ChainlitDataLayer(
|
|
97
|
-
database_url=database_url, storage_client=storage_client
|
|
98
|
-
)
|
|
99
|
-
elif api_key := os.environ.get("LITERAL_API_KEY"):
|
|
100
|
-
# When LITERAL_API_KEY is defined, use Literal AI data layer
|
|
101
|
-
from .literalai import LiteralDataLayer
|
|
102
|
-
|
|
103
|
-
# support legacy LITERAL_SERVER variable as fallback
|
|
104
|
-
server = os.environ.get("LITERAL_API_URL") or os.environ.get(
|
|
105
|
-
"LITERAL_SERVER"
|
|
106
|
-
)
|
|
107
|
-
_data_layer = LiteralDataLayer(api_key=api_key, server=server)
|
|
108
|
-
|
|
109
|
-
_data_layer_initialized = True
|
|
110
|
-
|
|
111
|
-
return _data_layer
|
chainlit/data/acl.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
from fastapi import HTTPException
|
|
2
|
-
|
|
3
|
-
from chainlit.data import get_data_layer
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
async def is_thread_author(username: str, thread_id: str):
|
|
7
|
-
data_layer = get_data_layer()
|
|
8
|
-
if not data_layer:
|
|
9
|
-
raise HTTPException(status_code=400, detail="Data layer not initialized")
|
|
10
|
-
|
|
11
|
-
thread_author = await data_layer.get_thread_author(thread_id)
|
|
12
|
-
|
|
13
|
-
if not thread_author:
|
|
14
|
-
raise HTTPException(status_code=404, detail="Thread not found")
|
|
15
|
-
|
|
16
|
-
if thread_author != username:
|
|
17
|
-
raise HTTPException(status_code=401, detail="Unauthorized")
|
|
18
|
-
else:
|
|
19
|
-
return True
|
chainlit/data/base.py
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
from typing import TYPE_CHECKING, Dict, List, Optional
|
|
3
|
-
|
|
4
|
-
from chainlit.types import (
|
|
5
|
-
Feedback,
|
|
6
|
-
PaginatedResponse,
|
|
7
|
-
Pagination,
|
|
8
|
-
ThreadDict,
|
|
9
|
-
ThreadFilter,
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
from .utils import queue_until_user_message
|
|
13
|
-
|
|
14
|
-
if TYPE_CHECKING:
|
|
15
|
-
from chainlit.element import Element, ElementDict
|
|
16
|
-
from chainlit.step import StepDict
|
|
17
|
-
from chainlit.user import PersistedUser, User
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class BaseDataLayer(ABC):
|
|
21
|
-
"""Base class for data persistence."""
|
|
22
|
-
|
|
23
|
-
@abstractmethod
|
|
24
|
-
async def get_user(self, identifier: str) -> Optional["PersistedUser"]:
|
|
25
|
-
pass
|
|
26
|
-
|
|
27
|
-
@abstractmethod
|
|
28
|
-
async def create_user(self, user: "User") -> Optional["PersistedUser"]:
|
|
29
|
-
pass
|
|
30
|
-
|
|
31
|
-
@abstractmethod
|
|
32
|
-
async def delete_feedback(
|
|
33
|
-
self,
|
|
34
|
-
feedback_id: str,
|
|
35
|
-
) -> bool:
|
|
36
|
-
pass
|
|
37
|
-
|
|
38
|
-
@abstractmethod
|
|
39
|
-
async def upsert_feedback(
|
|
40
|
-
self,
|
|
41
|
-
feedback: Feedback,
|
|
42
|
-
) -> str:
|
|
43
|
-
pass
|
|
44
|
-
|
|
45
|
-
@queue_until_user_message()
|
|
46
|
-
@abstractmethod
|
|
47
|
-
async def create_element(self, element: "Element"):
|
|
48
|
-
pass
|
|
49
|
-
|
|
50
|
-
@abstractmethod
|
|
51
|
-
async def get_element(
|
|
52
|
-
self, thread_id: str, element_id: str
|
|
53
|
-
) -> Optional["ElementDict"]:
|
|
54
|
-
pass
|
|
55
|
-
|
|
56
|
-
@queue_until_user_message()
|
|
57
|
-
@abstractmethod
|
|
58
|
-
async def delete_element(self, element_id: str, thread_id: Optional[str] = None):
|
|
59
|
-
pass
|
|
60
|
-
|
|
61
|
-
@queue_until_user_message()
|
|
62
|
-
@abstractmethod
|
|
63
|
-
async def create_step(self, step_dict: "StepDict"):
|
|
64
|
-
pass
|
|
65
|
-
|
|
66
|
-
@queue_until_user_message()
|
|
67
|
-
@abstractmethod
|
|
68
|
-
async def update_step(self, step_dict: "StepDict"):
|
|
69
|
-
pass
|
|
70
|
-
|
|
71
|
-
@queue_until_user_message()
|
|
72
|
-
@abstractmethod
|
|
73
|
-
async def delete_step(self, step_id: str):
|
|
74
|
-
pass
|
|
75
|
-
|
|
76
|
-
@abstractmethod
|
|
77
|
-
async def get_thread_author(self, thread_id: str) -> str:
|
|
78
|
-
return ""
|
|
79
|
-
|
|
80
|
-
@abstractmethod
|
|
81
|
-
async def delete_thread(self, thread_id: str):
|
|
82
|
-
pass
|
|
83
|
-
|
|
84
|
-
@abstractmethod
|
|
85
|
-
async def list_threads(
|
|
86
|
-
self, pagination: "Pagination", filters: "ThreadFilter"
|
|
87
|
-
) -> "PaginatedResponse[ThreadDict]":
|
|
88
|
-
pass
|
|
89
|
-
|
|
90
|
-
@abstractmethod
|
|
91
|
-
async def get_thread(self, thread_id: str) -> "Optional[ThreadDict]":
|
|
92
|
-
pass
|
|
93
|
-
|
|
94
|
-
@abstractmethod
|
|
95
|
-
async def update_thread(
|
|
96
|
-
self,
|
|
97
|
-
thread_id: str,
|
|
98
|
-
name: Optional[str] = None,
|
|
99
|
-
user_id: Optional[str] = None,
|
|
100
|
-
metadata: Optional[Dict] = None,
|
|
101
|
-
tags: Optional[List[str]] = None,
|
|
102
|
-
):
|
|
103
|
-
pass
|
|
104
|
-
|
|
105
|
-
@abstractmethod
|
|
106
|
-
async def build_debug_url(self) -> str:
|
|
107
|
-
pass
|