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/openai/__init__.py
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
from typing import Union
|
|
3
|
-
|
|
4
|
-
from literalai import ChatGeneration, CompletionGeneration
|
|
5
|
-
|
|
6
|
-
from chainlit.context import local_steps
|
|
7
|
-
from chainlit.step import Step
|
|
8
|
-
from chainlit.utils import check_module_version, timestamp_utc
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def instrument_openai():
|
|
12
|
-
if not check_module_version("openai", "1.0.0"):
|
|
13
|
-
raise ValueError(
|
|
14
|
-
"Expected OpenAI version >= 1.0.0. Run `pip install openai --upgrade`"
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
from literalai.instrumentation.openai import instrument_openai
|
|
18
|
-
|
|
19
|
-
def on_new_generation(
|
|
20
|
-
generation: Union["ChatGeneration", "CompletionGeneration"], timing
|
|
21
|
-
):
|
|
22
|
-
previous_steps = local_steps.get()
|
|
23
|
-
|
|
24
|
-
parent_id = previous_steps[-1].id if previous_steps else None
|
|
25
|
-
|
|
26
|
-
step = Step(
|
|
27
|
-
name=generation.model if generation.model else generation.provider,
|
|
28
|
-
type="llm",
|
|
29
|
-
parent_id=parent_id,
|
|
30
|
-
)
|
|
31
|
-
step.generation = generation
|
|
32
|
-
# Convert start/end time from seconds to milliseconds
|
|
33
|
-
step.start = (
|
|
34
|
-
timestamp_utc(timing.get("start"))
|
|
35
|
-
if timing.get("start", None) is not None
|
|
36
|
-
else None
|
|
37
|
-
)
|
|
38
|
-
step.end = (
|
|
39
|
-
timestamp_utc(timing.get("end"))
|
|
40
|
-
if timing.get("end", None) is not None
|
|
41
|
-
else None
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
if isinstance(generation, ChatGeneration):
|
|
45
|
-
step.input = generation.messages # type: ignore
|
|
46
|
-
step.output = generation.message_completion # type: ignore
|
|
47
|
-
else:
|
|
48
|
-
step.input = generation.prompt # type: ignore
|
|
49
|
-
step.output = generation.completion # type: ignore
|
|
50
|
-
|
|
51
|
-
asyncio.create_task(step.send())
|
|
52
|
-
|
|
53
|
-
instrument_openai(None, on_new_generation)
|
chainlit/py.typed
DELETED
|
File without changes
|
chainlit/secret.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import secrets
|
|
2
|
-
import string
|
|
3
|
-
|
|
4
|
-
# Using punctuation, without chars that can break in the cli (quotes, backslash, backtick...)
|
|
5
|
-
chars = string.ascii_letters + string.digits + "$%*,-./:=>?@^_~"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def random_secret(length: int = 64):
|
|
9
|
-
return "".join(secrets.choice(chars) for i in range(length))
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
from collections.abc import Awaitable, Callable
|
|
2
|
-
from typing import TYPE_CHECKING, Any
|
|
3
|
-
|
|
4
|
-
from pydantic import BaseModel
|
|
5
|
-
|
|
6
|
-
from chainlit import Step
|
|
7
|
-
|
|
8
|
-
if TYPE_CHECKING:
|
|
9
|
-
from semantic_kernel import Kernel
|
|
10
|
-
from semantic_kernel.filters import FunctionInvocationContext
|
|
11
|
-
from semantic_kernel.functions import KernelArguments
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class SemanticKernelFilter(BaseModel):
|
|
15
|
-
"""Semantic Kernel Filter for Chainlit.
|
|
16
|
-
|
|
17
|
-
This filter wraps any function calls that are executed and will capture the input and output of that function
|
|
18
|
-
as a Chainlit Step.
|
|
19
|
-
|
|
20
|
-
You can pass your kernel into the constructor, or you can call `add_to_kernel` later.
|
|
21
|
-
|
|
22
|
-
Args:
|
|
23
|
-
excluded_plugins: a list of plugin_names that will be excluded from displaying steps.
|
|
24
|
-
excluded_functions: a list of function names that will be excluded from displaying steps.
|
|
25
|
-
kernel: the Kernel to add the filter to. If not provided, you can call `add_to_kernel` later.
|
|
26
|
-
|
|
27
|
-
Methods:
|
|
28
|
-
add_to_kernel: this method takes a Kernel and adds the filter to that kernel.
|
|
29
|
-
parse_arguments: this method is called with KernelArguments used for the function
|
|
30
|
-
it can be subclassed to customize how to represent the input arguments.
|
|
31
|
-
|
|
32
|
-
Example::
|
|
33
|
-
|
|
34
|
-
filter = SemanticKernelFilter(kernel=kernel)
|
|
35
|
-
|
|
36
|
-
# or when you create your kernel later on:
|
|
37
|
-
|
|
38
|
-
filter = SemanticKernelFilter()
|
|
39
|
-
# ...
|
|
40
|
-
# other code, including kernel creation.
|
|
41
|
-
# ...
|
|
42
|
-
filter.add_to_kernel(kernel)
|
|
43
|
-
"""
|
|
44
|
-
|
|
45
|
-
excluded_plugins: list[str] | None = None
|
|
46
|
-
excluded_functions: list[str] | None = None
|
|
47
|
-
|
|
48
|
-
def __init__(
|
|
49
|
-
self,
|
|
50
|
-
excluded_plugins: list[str] | None = None,
|
|
51
|
-
excluded_functions: list[str] | None = None,
|
|
52
|
-
*,
|
|
53
|
-
kernel: "Kernel | None" = None,
|
|
54
|
-
) -> None:
|
|
55
|
-
super().__init__(
|
|
56
|
-
excluded_plugins=excluded_plugins, excluded_functions=excluded_functions
|
|
57
|
-
)
|
|
58
|
-
if kernel:
|
|
59
|
-
self.add_to_kernel(kernel)
|
|
60
|
-
|
|
61
|
-
def add_to_kernel(self, kernel: "Kernel") -> None:
|
|
62
|
-
"""Adds the filter to the provided kernel.
|
|
63
|
-
|
|
64
|
-
Args:
|
|
65
|
-
kernel: the Kernel to add the filter to.
|
|
66
|
-
"""
|
|
67
|
-
kernel.add_filter("function_invocation", self._function_invocation_filter) # type: ignore[arg-type]
|
|
68
|
-
|
|
69
|
-
def parse_arguments(self, arguments: "KernelArguments") -> dict[str, Any] | str:
|
|
70
|
-
"""Parse the KernelArguments used for the function.
|
|
71
|
-
|
|
72
|
-
This function can be subclassed to easily adopt how the input arguments are displayed.
|
|
73
|
-
|
|
74
|
-
Args:
|
|
75
|
-
arguments: KernelArguments
|
|
76
|
-
|
|
77
|
-
Returns:
|
|
78
|
-
a dict or string with the input.
|
|
79
|
-
"""
|
|
80
|
-
if len(arguments) == 0:
|
|
81
|
-
return ""
|
|
82
|
-
input_dict = {}
|
|
83
|
-
for key, value in arguments.items():
|
|
84
|
-
if isinstance(value, BaseModel):
|
|
85
|
-
input_dict[key] = value.model_dump(exclude_none=True, by_alias=True)
|
|
86
|
-
else:
|
|
87
|
-
input_dict[key] = value
|
|
88
|
-
return input_dict
|
|
89
|
-
|
|
90
|
-
async def _function_invocation_filter(
|
|
91
|
-
self,
|
|
92
|
-
context: "FunctionInvocationContext",
|
|
93
|
-
next: Callable[["FunctionInvocationContext"], Awaitable[None]],
|
|
94
|
-
):
|
|
95
|
-
if (
|
|
96
|
-
self.excluded_plugins
|
|
97
|
-
and context.function.plugin_name in self.excluded_plugins
|
|
98
|
-
) or (
|
|
99
|
-
self.excluded_functions and context.function.name in self.excluded_functions
|
|
100
|
-
):
|
|
101
|
-
await next(context)
|
|
102
|
-
return
|
|
103
|
-
async with Step(
|
|
104
|
-
type="tool", name=context.function.fully_qualified_name
|
|
105
|
-
) as step:
|
|
106
|
-
step.input = self.parse_arguments(context.arguments)
|
|
107
|
-
await step.send()
|
|
108
|
-
await next(context)
|
|
109
|
-
if context.result:
|
|
110
|
-
step.output = context.result.value
|
|
111
|
-
await step.update()
|