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/llama_index/__init__.py
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
from typing import Any, Dict, List, Optional
|
|
2
|
-
|
|
3
|
-
from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
|
|
4
|
-
from llama_index.core.callbacks import TokenCountingHandler
|
|
5
|
-
from llama_index.core.callbacks.schema import CBEventType, EventPayload
|
|
6
|
-
from llama_index.core.llms import ChatMessage, ChatResponse, CompletionResponse
|
|
7
|
-
from llama_index.core.tools.types import ToolMetadata
|
|
8
|
-
|
|
9
|
-
from chainlit.context import context_var
|
|
10
|
-
from chainlit.element import Text
|
|
11
|
-
from chainlit.step import Step, StepType
|
|
12
|
-
from chainlit.utils import utc_now
|
|
13
|
-
|
|
14
|
-
DEFAULT_IGNORE = [
|
|
15
|
-
CBEventType.CHUNKING,
|
|
16
|
-
CBEventType.SYNTHESIZE,
|
|
17
|
-
CBEventType.EMBEDDING,
|
|
18
|
-
CBEventType.NODE_PARSING,
|
|
19
|
-
CBEventType.TREE,
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class LlamaIndexCallbackHandler(TokenCountingHandler):
|
|
24
|
-
"""Base callback handler that can be used to track event starts and ends."""
|
|
25
|
-
|
|
26
|
-
steps: Dict[str, Step]
|
|
27
|
-
|
|
28
|
-
def __init__(
|
|
29
|
-
self,
|
|
30
|
-
event_starts_to_ignore: List[CBEventType] = DEFAULT_IGNORE,
|
|
31
|
-
event_ends_to_ignore: List[CBEventType] = DEFAULT_IGNORE,
|
|
32
|
-
) -> None:
|
|
33
|
-
"""Initialize the base callback handler."""
|
|
34
|
-
super().__init__(
|
|
35
|
-
event_starts_to_ignore=event_starts_to_ignore,
|
|
36
|
-
event_ends_to_ignore=event_ends_to_ignore,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
self.steps = {}
|
|
40
|
-
|
|
41
|
-
def _get_parent_id(self, event_parent_id: Optional[str] = None) -> Optional[str]:
|
|
42
|
-
if event_parent_id and event_parent_id in self.steps:
|
|
43
|
-
return event_parent_id
|
|
44
|
-
elif context_var.get().current_step:
|
|
45
|
-
return context_var.get().current_step.id
|
|
46
|
-
else:
|
|
47
|
-
return None
|
|
48
|
-
|
|
49
|
-
def on_event_start(
|
|
50
|
-
self,
|
|
51
|
-
event_type: CBEventType,
|
|
52
|
-
payload: Optional[Dict[str, Any]] = None,
|
|
53
|
-
event_id: str = "",
|
|
54
|
-
parent_id: str = "",
|
|
55
|
-
**kwargs: Any,
|
|
56
|
-
) -> str:
|
|
57
|
-
"""Run when an event starts and return id of event."""
|
|
58
|
-
step_type: StepType = "undefined"
|
|
59
|
-
step_name: str = event_type.value
|
|
60
|
-
step_input: Optional[Dict[str, Any]] = payload
|
|
61
|
-
if event_type == CBEventType.FUNCTION_CALL:
|
|
62
|
-
step_type = "tool"
|
|
63
|
-
if payload:
|
|
64
|
-
metadata: Optional[ToolMetadata] = payload.get(EventPayload.TOOL)
|
|
65
|
-
if metadata:
|
|
66
|
-
step_name = getattr(metadata, "name", step_name)
|
|
67
|
-
step_input = payload.get(EventPayload.FUNCTION_CALL)
|
|
68
|
-
elif event_type == CBEventType.RETRIEVE:
|
|
69
|
-
step_type = "tool"
|
|
70
|
-
elif event_type == CBEventType.QUERY:
|
|
71
|
-
step_type = "tool"
|
|
72
|
-
elif event_type == CBEventType.LLM:
|
|
73
|
-
step_type = "llm"
|
|
74
|
-
else:
|
|
75
|
-
return event_id
|
|
76
|
-
|
|
77
|
-
step = Step(
|
|
78
|
-
name=step_name,
|
|
79
|
-
type=step_type,
|
|
80
|
-
parent_id=self._get_parent_id(parent_id),
|
|
81
|
-
id=event_id,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
self.steps[event_id] = step
|
|
85
|
-
step.start = utc_now()
|
|
86
|
-
step.input = step_input or {}
|
|
87
|
-
context_var.get().loop.create_task(step.send())
|
|
88
|
-
return event_id
|
|
89
|
-
|
|
90
|
-
def on_event_end(
|
|
91
|
-
self,
|
|
92
|
-
event_type: CBEventType,
|
|
93
|
-
payload: Optional[Dict[str, Any]] = None,
|
|
94
|
-
event_id: str = "",
|
|
95
|
-
**kwargs: Any,
|
|
96
|
-
) -> None:
|
|
97
|
-
"""Run when an event ends."""
|
|
98
|
-
step = self.steps.get(event_id, None)
|
|
99
|
-
|
|
100
|
-
if payload is None or step is None:
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
step.end = utc_now()
|
|
104
|
-
|
|
105
|
-
if event_type == CBEventType.FUNCTION_CALL:
|
|
106
|
-
response = payload.get(EventPayload.FUNCTION_OUTPUT)
|
|
107
|
-
if response:
|
|
108
|
-
step.output = f"{response}"
|
|
109
|
-
context_var.get().loop.create_task(step.update())
|
|
110
|
-
|
|
111
|
-
elif event_type == CBEventType.QUERY:
|
|
112
|
-
response = payload.get(EventPayload.RESPONSE)
|
|
113
|
-
source_nodes = getattr(response, "source_nodes", None)
|
|
114
|
-
if source_nodes:
|
|
115
|
-
source_refs = ", ".join(
|
|
116
|
-
[f"Source {idx}" for idx, _ in enumerate(source_nodes)]
|
|
117
|
-
)
|
|
118
|
-
step.elements = [
|
|
119
|
-
Text(
|
|
120
|
-
name=f"Source {idx}",
|
|
121
|
-
content=source.text or "Empty node",
|
|
122
|
-
display="side",
|
|
123
|
-
)
|
|
124
|
-
for idx, source in enumerate(source_nodes)
|
|
125
|
-
]
|
|
126
|
-
step.output = f"Retrieved the following sources: {source_refs}"
|
|
127
|
-
context_var.get().loop.create_task(step.update())
|
|
128
|
-
|
|
129
|
-
elif event_type == CBEventType.RETRIEVE:
|
|
130
|
-
sources = payload.get(EventPayload.NODES)
|
|
131
|
-
if sources:
|
|
132
|
-
source_refs = ", ".join(
|
|
133
|
-
[f"Source {idx}" for idx, _ in enumerate(sources)]
|
|
134
|
-
)
|
|
135
|
-
step.elements = [
|
|
136
|
-
Text(
|
|
137
|
-
name=f"Source {idx}",
|
|
138
|
-
display="side",
|
|
139
|
-
content=source.node.get_text() or "Empty node",
|
|
140
|
-
)
|
|
141
|
-
for idx, source in enumerate(sources)
|
|
142
|
-
]
|
|
143
|
-
step.output = f"Retrieved the following sources: {source_refs}"
|
|
144
|
-
context_var.get().loop.create_task(step.update())
|
|
145
|
-
|
|
146
|
-
elif event_type == CBEventType.LLM:
|
|
147
|
-
formatted_messages = payload.get(EventPayload.MESSAGES) # type: Optional[List[ChatMessage]]
|
|
148
|
-
formatted_prompt = payload.get(EventPayload.PROMPT)
|
|
149
|
-
response = payload.get(EventPayload.RESPONSE)
|
|
150
|
-
|
|
151
|
-
if formatted_messages:
|
|
152
|
-
messages = [
|
|
153
|
-
GenerationMessage(
|
|
154
|
-
role=m.role.value, # type: ignore
|
|
155
|
-
content=m.content or "",
|
|
156
|
-
)
|
|
157
|
-
for m in formatted_messages
|
|
158
|
-
]
|
|
159
|
-
else:
|
|
160
|
-
messages = None
|
|
161
|
-
|
|
162
|
-
if isinstance(response, ChatResponse):
|
|
163
|
-
content = response.message.content or ""
|
|
164
|
-
elif isinstance(response, CompletionResponse):
|
|
165
|
-
content = response.text
|
|
166
|
-
else:
|
|
167
|
-
content = ""
|
|
168
|
-
|
|
169
|
-
step.output = content
|
|
170
|
-
|
|
171
|
-
token_count = self.total_llm_token_count or None
|
|
172
|
-
raw_response = response.raw if response else None
|
|
173
|
-
model = getattr(raw_response, "model", None)
|
|
174
|
-
|
|
175
|
-
if messages and isinstance(response, ChatResponse):
|
|
176
|
-
msg: ChatMessage = response.message
|
|
177
|
-
step.generation = ChatGeneration(
|
|
178
|
-
model=model,
|
|
179
|
-
messages=messages,
|
|
180
|
-
message_completion=GenerationMessage(
|
|
181
|
-
role=msg.role.value, # type: ignore
|
|
182
|
-
content=content,
|
|
183
|
-
),
|
|
184
|
-
token_count=token_count,
|
|
185
|
-
)
|
|
186
|
-
elif formatted_prompt:
|
|
187
|
-
step.generation = CompletionGeneration(
|
|
188
|
-
model=model,
|
|
189
|
-
prompt=formatted_prompt,
|
|
190
|
-
completion=content,
|
|
191
|
-
token_count=token_count,
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
context_var.get().loop.create_task(step.update())
|
|
195
|
-
|
|
196
|
-
else:
|
|
197
|
-
step.output = payload
|
|
198
|
-
context_var.get().loop.create_task(step.update())
|
|
199
|
-
|
|
200
|
-
self.steps.pop(event_id, None)
|
|
201
|
-
|
|
202
|
-
def _noop(self, *args, **kwargs):
|
|
203
|
-
pass
|
|
204
|
-
|
|
205
|
-
start_trace = _noop
|
|
206
|
-
end_trace = _noop
|
chainlit/logger.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import sys
|
|
3
|
-
|
|
4
|
-
logging.basicConfig(
|
|
5
|
-
level=logging.INFO,
|
|
6
|
-
stream=sys.stdout,
|
|
7
|
-
format="%(asctime)s - %(message)s",
|
|
8
|
-
datefmt="%Y-%m-%d %H:%M:%S",
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
logging.getLogger("socketio").setLevel(logging.ERROR)
|
|
12
|
-
logging.getLogger("engineio").setLevel(logging.ERROR)
|
|
13
|
-
logging.getLogger("numexpr").setLevel(logging.ERROR)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
logger = logging.getLogger("chainlit")
|
chainlit/markdown.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
|
-
from chainlit.logger import logger
|
|
6
|
-
|
|
7
|
-
from ._utils import is_path_inside
|
|
8
|
-
|
|
9
|
-
# Default chainlit.md file created if none exists
|
|
10
|
-
DEFAULT_MARKDOWN_STR = """# Welcome to Chainlit! 🚀🤖
|
|
11
|
-
|
|
12
|
-
Hi there, Developer! 👋 We're excited to have you on board. Chainlit is a powerful tool designed to help you prototype, debug and share applications built on top of LLMs.
|
|
13
|
-
|
|
14
|
-
## Useful Links 🔗
|
|
15
|
-
|
|
16
|
-
- **Documentation:** Get started with our comprehensive [Chainlit Documentation](https://docs.chainlit.io) 📚
|
|
17
|
-
- **Discord Community:** Join our friendly [Chainlit Discord](https://discord.gg/k73SQ3FyUh) to ask questions, share your projects, and connect with other developers! 💬
|
|
18
|
-
|
|
19
|
-
We can't wait to see what you create with Chainlit! Happy coding! 💻😊
|
|
20
|
-
|
|
21
|
-
## Welcome screen
|
|
22
|
-
|
|
23
|
-
To modify the welcome screen, edit the `chainlit.md` file at the root of your project. If you do not want a welcome screen, just leave this file empty.
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def init_markdown(root: str):
|
|
28
|
-
"""Initialize the chainlit.md file if it doesn't exist."""
|
|
29
|
-
chainlit_md_file = os.path.join(root, "chainlit.md")
|
|
30
|
-
|
|
31
|
-
if not os.path.exists(chainlit_md_file):
|
|
32
|
-
with open(chainlit_md_file, "w", encoding="utf-8") as f:
|
|
33
|
-
f.write(DEFAULT_MARKDOWN_STR)
|
|
34
|
-
logger.info(f"Created default chainlit markdown file at {chainlit_md_file}")
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def get_markdown_str(root: str, language: str) -> Optional[str]:
|
|
38
|
-
"""Get the chainlit.md file as a string."""
|
|
39
|
-
root_path = Path(root)
|
|
40
|
-
translated_chainlit_md_path = root_path / f"chainlit_{language}.md"
|
|
41
|
-
default_chainlit_md_path = root_path / "chainlit.md"
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
is_path_inside(translated_chainlit_md_path, root_path)
|
|
45
|
-
and translated_chainlit_md_path.is_file()
|
|
46
|
-
):
|
|
47
|
-
chainlit_md_path = translated_chainlit_md_path
|
|
48
|
-
else:
|
|
49
|
-
chainlit_md_path = default_chainlit_md_path
|
|
50
|
-
logger.warning(
|
|
51
|
-
f"Translated markdown file for {language} not found. Defaulting to chainlit.md."
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
if chainlit_md_path.is_file():
|
|
55
|
-
return chainlit_md_path.read_text(encoding="utf-8")
|
|
56
|
-
else:
|
|
57
|
-
return None
|
chainlit/mcp.py
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import shlex
|
|
2
|
-
from typing import Dict, Literal, Optional, Union
|
|
3
|
-
|
|
4
|
-
from pydantic import BaseModel
|
|
5
|
-
|
|
6
|
-
from chainlit.config import config
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class StdioMcpConnection(BaseModel):
|
|
10
|
-
name: str
|
|
11
|
-
command: str
|
|
12
|
-
args: list[str]
|
|
13
|
-
clientType: Literal["stdio"] = "stdio"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class SseMcpConnection(BaseModel):
|
|
17
|
-
name: str
|
|
18
|
-
url: str
|
|
19
|
-
headers: Optional[Dict[str, str]] = None
|
|
20
|
-
clientType: Literal["sse"] = "sse"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class HttpMcpConnection(BaseModel):
|
|
24
|
-
name: str
|
|
25
|
-
url: str
|
|
26
|
-
headers: Optional[Dict[str, str]] = None
|
|
27
|
-
clientType: Literal["streamable-http"] = "streamable-http"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
McpConnection = Union[StdioMcpConnection, SseMcpConnection, HttpMcpConnection]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def validate_mcp_command(command_string: str):
|
|
34
|
-
"""
|
|
35
|
-
Validates that a command string uses command in the allowed list as the executable and returns
|
|
36
|
-
the executable and list of arguments suitable for subprocess calls.
|
|
37
|
-
|
|
38
|
-
This function handles potential command prefixes, flags, and options
|
|
39
|
-
to ensure only commands in allowed list are allowed.
|
|
40
|
-
|
|
41
|
-
Args:
|
|
42
|
-
command_string (str): The full command string to validate
|
|
43
|
-
|
|
44
|
-
Returns:
|
|
45
|
-
tuple: (env, executable, args_list) where:
|
|
46
|
-
- env (dict): Environment variables as a dictionary
|
|
47
|
-
- executable (str): The executable name or path
|
|
48
|
-
- args_list (list): List of command arguments
|
|
49
|
-
|
|
50
|
-
Raises:
|
|
51
|
-
ValueError: If the command doesn't use an allowed executable
|
|
52
|
-
"""
|
|
53
|
-
# Split the command string into parts while respecting quotes and escapes
|
|
54
|
-
# Using shlex.split provides POSIX-compatible parsing so that arguments
|
|
55
|
-
# wrapped in quotes (e.g. "--header \"Authorization: Bearer TOKEN\"")
|
|
56
|
-
# or environment variable assignments such as
|
|
57
|
-
# MY_VAR="value with spaces" are preserved as single list items.
|
|
58
|
-
# On Windows, shlex also works as long as posix=False is not required for
|
|
59
|
-
# our use-case (Chainlit targets POSIX-style shells for the MCP command).
|
|
60
|
-
try:
|
|
61
|
-
parts = shlex.split(command_string, posix=True)
|
|
62
|
-
except ValueError as exc:
|
|
63
|
-
# Provide a clearer error message when the command cannot be parsed
|
|
64
|
-
raise ValueError(f"Invalid command string: {exc}") from exc
|
|
65
|
-
|
|
66
|
-
if not parts:
|
|
67
|
-
raise ValueError("Empty command string")
|
|
68
|
-
|
|
69
|
-
# Look for the actual executable in the command
|
|
70
|
-
executable = None
|
|
71
|
-
executable_index = None
|
|
72
|
-
allowed_executables = config.features.mcp.stdio.allowed_executables
|
|
73
|
-
for i, part in enumerate(parts):
|
|
74
|
-
# Remove any path components to get the base executable name
|
|
75
|
-
base_exec = part.split("/")[-1].split("\\")[-1]
|
|
76
|
-
if allowed_executables is None or base_exec in allowed_executables:
|
|
77
|
-
executable = part
|
|
78
|
-
executable_index = i
|
|
79
|
-
break
|
|
80
|
-
|
|
81
|
-
if executable is None or executable_index is None:
|
|
82
|
-
raise ValueError(
|
|
83
|
-
f"Only commands in ({', '.join(allowed_executables)}) are allowed"
|
|
84
|
-
if allowed_executables
|
|
85
|
-
else "No allowed executables found"
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
# Return `executable` as the executable and everything after it as args
|
|
89
|
-
args_list = parts[executable_index + 1 :]
|
|
90
|
-
env_list = parts[:executable_index]
|
|
91
|
-
env = {}
|
|
92
|
-
for env_var in env_list:
|
|
93
|
-
if "=" in env_var:
|
|
94
|
-
key, value = env_var.split("=", 1)
|
|
95
|
-
env[key] = value
|
|
96
|
-
else:
|
|
97
|
-
raise ValueError(f"Invalid environment variable format: {env_var}")
|
|
98
|
-
|
|
99
|
-
return env, executable, args_list
|