chainlit 0.4.2__tar.gz → 0.4.3__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.
Potentially problematic release.
This version of chainlit might be problematic. Click here for more details.
- {chainlit-0.4.2 → chainlit-0.4.3}/PKG-INFO +3 -2
- chainlit-0.4.3/chainlit/__init__.py +165 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/cli/__init__.py +13 -1
- chainlit-0.4.3/chainlit/cli/mock.py +1612 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/config.py +5 -2
- chainlit-0.4.2/chainlit/frontend/dist/assets/index-995e21ad.js → chainlit-0.4.3/chainlit/frontend/dist/assets/index-37b5009c.js +1 -1
- chainlit-0.4.2/chainlit/frontend/dist/assets/index-fb1e167a.js → chainlit-0.4.3/chainlit/frontend/dist/assets/index-51393291.js +2 -2
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/frontend/dist/index.html +1 -1
- chainlit-0.4.3/chainlit/langflow/__init__.py +75 -0
- chainlit-0.4.3/chainlit/lc/__init__.py +96 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/lc/agent.py +8 -5
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/lc/callbacks.py +3 -3
- chainlit-0.4.3/chainlit/llama_index/__init__.py +34 -0
- chainlit-0.4.3/chainlit/llama_index/callbacks.py +99 -0
- chainlit-0.4.3/chainlit/llama_index/run.py +34 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/message.py +3 -3
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/server.py +14 -3
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/session.py +2 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/sync.py +8 -3
- chainlit-0.4.3/chainlit/utils.py +51 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/pyproject.toml +3 -2
- chainlit-0.4.2/chainlit/__init__.py +0 -275
- chainlit-0.4.2/chainlit/cli/mock.py +0 -48
- chainlit-0.4.2/chainlit/lc/__init__.py +0 -11
- {chainlit-0.4.2 → chainlit-0.4.3}/README.md +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/__main__.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/action.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/cache.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/cli/auth.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/cli/deploy.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/cli/utils.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/client/base.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/client/cloud.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/client/local.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/client/utils.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/context.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/db/__init__.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/db/prisma/schema.prisma +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/element.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/emitter.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/frontend/dist/assets/index-f93cc942.css +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/frontend/dist/assets/logo_dark-bc7401f6.svg +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/frontend/dist/assets/logo_light-f19fc2ea.svg +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/frontend/dist/favicon.svg +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/hello.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/logger.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/markdown.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/telemetry.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/types.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/user_session.py +0 -0
- {chainlit-0.4.2 → chainlit-0.4.3}/chainlit/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: chainlit
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.3
|
|
4
4
|
Summary: A faster way to build chatbot UIs.
|
|
5
5
|
Home-page: https://github.com/Chainlit/chainlit
|
|
6
6
|
License: Apache-2.0 license
|
|
@@ -19,8 +19,9 @@ Requires-Dist: asyncer (>=0.0.2,<0.0.3)
|
|
|
19
19
|
Requires-Dist: auth0-python (>=4.1.1,<5.0.0)
|
|
20
20
|
Requires-Dist: click (>=8.1.3,<9.0.0)
|
|
21
21
|
Requires-Dist: dataclasses_json (>=0.5.7,<0.6.0)
|
|
22
|
-
Requires-Dist: fastapi (>=0.
|
|
22
|
+
Requires-Dist: fastapi (>=0.97.0,<0.98.0)
|
|
23
23
|
Requires-Dist: fastapi-socketio (>=0.0.10,<0.0.11)
|
|
24
|
+
Requires-Dist: nest-asyncio (>=1.5.6,<2.0.0)
|
|
24
25
|
Requires-Dist: openai (>=0.27.7,<0.28.0)
|
|
25
26
|
Requires-Dist: prisma (>=0.9.0,<0.10.0)
|
|
26
27
|
Requires-Dist: pydantic (>=1.10.8,<2.0.0)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
from dotenv import load_dotenv
|
|
2
|
+
from typing import Callable, Any, TYPE_CHECKING
|
|
3
|
+
import os
|
|
4
|
+
import asyncio
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from chainlit.client.base import BaseClient
|
|
8
|
+
|
|
9
|
+
from chainlit.lc import (
|
|
10
|
+
LANGCHAIN_INSTALLED,
|
|
11
|
+
langchain_factory,
|
|
12
|
+
langchain_postprocess,
|
|
13
|
+
langchain_run,
|
|
14
|
+
langchain_rename,
|
|
15
|
+
)
|
|
16
|
+
from chainlit.llama_index import LLAMA_INDEX_INSTALLED, llama_index_factory
|
|
17
|
+
from chainlit.langflow import langflow_factory
|
|
18
|
+
from chainlit.utils import wrap_user_function
|
|
19
|
+
from chainlit.config import config
|
|
20
|
+
from chainlit.telemetry import trace
|
|
21
|
+
from chainlit.version import __version__
|
|
22
|
+
from chainlit.logger import logger
|
|
23
|
+
from chainlit.types import LLMSettings
|
|
24
|
+
from chainlit.action import Action
|
|
25
|
+
from chainlit.element import Image, Text, Pdf, Avatar, Pyplot
|
|
26
|
+
from chainlit.message import Message, ErrorMessage, AskUserMessage, AskFileMessage
|
|
27
|
+
from chainlit.user_session import user_session
|
|
28
|
+
from chainlit.sync import run_sync, make_async
|
|
29
|
+
from chainlit.cache import cache
|
|
30
|
+
|
|
31
|
+
if LANGCHAIN_INSTALLED:
|
|
32
|
+
from chainlit.lc.callbacks import (
|
|
33
|
+
LangchainCallbackHandler,
|
|
34
|
+
AsyncLangchainCallbackHandler,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
if LLAMA_INDEX_INSTALLED:
|
|
38
|
+
from chainlit.llama_index.callbacks import (
|
|
39
|
+
LlamaIndexCallbackHandler,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
env_found = load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
|
|
44
|
+
|
|
45
|
+
if env_found:
|
|
46
|
+
logger.info("Loaded .env file")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@trace
|
|
50
|
+
def on_message(func: Callable) -> Callable:
|
|
51
|
+
"""
|
|
52
|
+
Framework agnostic decorator to react to messages coming from the UI.
|
|
53
|
+
The decorated function is called every time a new message is received.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
func (Callable[[str], Any]): The function to be called when a new message is received. Takes the input message.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
Callable[[str], Any]: The decorated on_message function.
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
config.code.on_message = wrap_user_function(func)
|
|
63
|
+
return func
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@trace
|
|
67
|
+
def on_chat_start(func: Callable) -> Callable:
|
|
68
|
+
"""
|
|
69
|
+
Hook to react to the user websocket connection event.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
func (Callable[], Any]): The connection hook to execute.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Callable[], Any]: The decorated hook.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
config.code.on_chat_start = wrap_user_function(func, with_task=True)
|
|
79
|
+
return func
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@trace
|
|
83
|
+
def on_stop(func: Callable) -> Callable:
|
|
84
|
+
"""
|
|
85
|
+
Hook to react to the user stopping a conversation.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
func (Callable[[], Any]): The stop hook to execute.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
Callable[[], Any]: The decorated stop hook.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
config.code.on_stop = wrap_user_function(func)
|
|
95
|
+
return func
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def action_callback(name: str) -> Callable:
|
|
99
|
+
"""
|
|
100
|
+
Callback to call when an action is clicked in the UI.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
func (Callable[[Action], Any]): The action callback to execute. First parameter is the action.
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
def decorator(func: Callable[[Action], Any]):
|
|
107
|
+
config.code.action_callbacks[name] = wrap_user_function(func, with_task=True)
|
|
108
|
+
return func
|
|
109
|
+
|
|
110
|
+
return decorator
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
@trace
|
|
114
|
+
def client_factory(func: Callable[[], "BaseClient"]) -> Callable[[], "BaseClient"]:
|
|
115
|
+
"""
|
|
116
|
+
Callback to call when to initialize the custom client.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
func (Callable[[str], BaseClient]): The action callback to execute. First parameter is the session id.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
config.code.client_factory = func
|
|
123
|
+
return func
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def sleep(duration: int):
|
|
127
|
+
"""
|
|
128
|
+
Sleep for a given duration.
|
|
129
|
+
Args:
|
|
130
|
+
duration (int): The duration in seconds.
|
|
131
|
+
"""
|
|
132
|
+
return asyncio.sleep(duration)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
__all__ = [
|
|
136
|
+
"user_session",
|
|
137
|
+
"LLMSettings",
|
|
138
|
+
"Action",
|
|
139
|
+
"Pdf",
|
|
140
|
+
"Image",
|
|
141
|
+
"Text",
|
|
142
|
+
"Avatar",
|
|
143
|
+
"Pyplot",
|
|
144
|
+
"Message",
|
|
145
|
+
"ErrorMessage",
|
|
146
|
+
"AskUserMessage",
|
|
147
|
+
"AskFileMessage",
|
|
148
|
+
"langchain_factory",
|
|
149
|
+
"langchain_postprocess",
|
|
150
|
+
"langchain_run",
|
|
151
|
+
"langchain_rename",
|
|
152
|
+
"llama_index_factory",
|
|
153
|
+
"langflow_factory",
|
|
154
|
+
"on_chat_start",
|
|
155
|
+
"on_stop",
|
|
156
|
+
"action_callback",
|
|
157
|
+
"sleep",
|
|
158
|
+
"LangchainCallbackHandler",
|
|
159
|
+
"AsyncLangchainCallbackHandler",
|
|
160
|
+
"LlamaIndexCallbackHandler",
|
|
161
|
+
"client_factory",
|
|
162
|
+
"run_sync",
|
|
163
|
+
"make_async",
|
|
164
|
+
"cache",
|
|
165
|
+
]
|
|
@@ -2,6 +2,10 @@ import click
|
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
4
|
import uvicorn
|
|
5
|
+
import asyncio
|
|
6
|
+
import nest_asyncio
|
|
7
|
+
|
|
8
|
+
nest_asyncio.apply()
|
|
5
9
|
|
|
6
10
|
from chainlit.config import (
|
|
7
11
|
config,
|
|
@@ -52,7 +56,15 @@ def run_chainlit(target: str):
|
|
|
52
56
|
|
|
53
57
|
log_level = "debug" if config.run.debug else "error"
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
# Start the server
|
|
60
|
+
async def start():
|
|
61
|
+
config = uvicorn.Config(app, host=host, port=port, log_level=log_level)
|
|
62
|
+
server = uvicorn.Server(config)
|
|
63
|
+
await server.serve()
|
|
64
|
+
|
|
65
|
+
# Run the asyncio event loop instead of uvloop to enable re entrance
|
|
66
|
+
asyncio.run(start())
|
|
67
|
+
# uvicorn.run(app, host=host, port=port, log_level=log_level)
|
|
56
68
|
|
|
57
69
|
|
|
58
70
|
# Define the "run" command for Chainlit CLI
|