chainlit 0.4.1__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.1 → chainlit-0.4.3}/PKG-INFO +7 -3
- {chainlit-0.4.1 → chainlit-0.4.3}/README.md +4 -1
- chainlit-0.4.3/chainlit/__init__.py +165 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/action.py +2 -4
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/cli/__init__.py +64 -9
- chainlit-0.4.3/chainlit/cli/mock.py +1612 -0
- chainlit-0.4.3/chainlit/client/base.py +152 -0
- chainlit-0.4.3/chainlit/client/cloud.py +440 -0
- chainlit-0.4.3/chainlit/client/local.py +257 -0
- chainlit-0.4.3/chainlit/client/utils.py +23 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/config.py +31 -5
- chainlit-0.4.3/chainlit/context.py +29 -0
- chainlit-0.4.3/chainlit/db/__init__.py +35 -0
- chainlit-0.4.3/chainlit/db/prisma/schema.prisma +48 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/element.py +54 -41
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/emitter.py +1 -30
- chainlit-0.4.1/chainlit/frontend/dist/assets/index-51a1a88f.js → chainlit-0.4.3/chainlit/frontend/dist/assets/index-37b5009c.js +1 -1
- chainlit-0.4.3/chainlit/frontend/dist/assets/index-51393291.js +523 -0
- {chainlit-0.4.1 → 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.1 → chainlit-0.4.3}/chainlit/lc/agent.py +9 -5
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/lc/callbacks.py +9 -24
- 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.1 → chainlit-0.4.3}/chainlit/logger.py +7 -2
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/message.py +25 -19
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/server.py +149 -38
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/session.py +3 -3
- chainlit-0.4.3/chainlit/sync.py +30 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/types.py +26 -1
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/user_session.py +1 -1
- chainlit-0.4.3/chainlit/utils.py +51 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/pyproject.toml +4 -3
- chainlit-0.4.1/chainlit/__init__.py +0 -254
- chainlit-0.4.1/chainlit/cli/mock.py +0 -48
- chainlit-0.4.1/chainlit/client.py +0 -287
- chainlit-0.4.1/chainlit/frontend/dist/assets/index-68c36c96.js +0 -707
- chainlit-0.4.1/chainlit/lc/__init__.py +0 -11
- chainlit-0.4.1/chainlit/sync.py +0 -37
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/__main__.py +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/cache.py +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/cli/auth.py +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/cli/deploy.py +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/cli/utils.py +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/frontend/dist/assets/index-f93cc942.css +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/frontend/dist/assets/logo_dark-bc7401f6.svg +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/frontend/dist/assets/logo_light-f19fc2ea.svg +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/frontend/dist/favicon.svg +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/hello.py +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/markdown.py +0 -0
- {chainlit-0.4.1 → chainlit-0.4.3}/chainlit/telemetry.py +0 -0
- {chainlit-0.4.1 → 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,10 +19,11 @@ 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
24
|
Requires-Dist: nest-asyncio (>=1.5.6,<2.0.0)
|
|
25
25
|
Requires-Dist: openai (>=0.27.7,<0.28.0)
|
|
26
|
+
Requires-Dist: prisma (>=0.9.0,<0.10.0)
|
|
26
27
|
Requires-Dist: pydantic (>=1.10.8,<2.0.0)
|
|
27
28
|
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
|
28
29
|
Requires-Dist: python-graphql-client (>=0.4.3,<0.5.0)
|
|
@@ -92,7 +93,10 @@ $ chainlit run demo.py -w
|
|
|
92
93
|
|
|
93
94
|
### 🔗 With LangChain
|
|
94
95
|
|
|
95
|
-
|
|
96
|
+
Check out our plug-and-play [integration](https://docs.chainlit.io/langchain) with LangChain!
|
|
97
|
+
|
|
98
|
+
### 📚 More Examples - Cookbook
|
|
99
|
+
You can find various examples of Chainlit apps [here](https://github.com/Chainlit/cookbook) that leverage tools and services such as OpenAI, Anthropiс, LangChain, LlamaIndex, ChromaDB, Pinecone and more.
|
|
96
100
|
|
|
97
101
|
## 🛣 Roadmap
|
|
98
102
|
- [ ] New UI elements (spreadsheet, video, carousel...)
|
|
@@ -56,7 +56,10 @@ $ chainlit run demo.py -w
|
|
|
56
56
|
|
|
57
57
|
### 🔗 With LangChain
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
Check out our plug-and-play [integration](https://docs.chainlit.io/langchain) with LangChain!
|
|
60
|
+
|
|
61
|
+
### 📚 More Examples - Cookbook
|
|
62
|
+
You can find various examples of Chainlit apps [here](https://github.com/Chainlit/cookbook) that leverage tools and services such as OpenAI, Anthropiс, LangChain, LlamaIndex, ChromaDB, Pinecone and more.
|
|
60
63
|
|
|
61
64
|
## 🛣 Roadmap
|
|
62
65
|
- [ ] New UI elements (spreadsheet, video, carousel...)
|
|
@@ -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
|
+
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from pydantic.dataclasses import dataclass
|
|
2
2
|
from dataclasses_json import dataclass_json
|
|
3
3
|
|
|
4
|
-
from chainlit.
|
|
4
|
+
from chainlit.context import get_emitter
|
|
5
5
|
from chainlit.telemetry import trace_event
|
|
6
6
|
|
|
7
7
|
|
|
@@ -21,9 +21,7 @@ class Action:
|
|
|
21
21
|
|
|
22
22
|
def __post_init__(self) -> None:
|
|
23
23
|
trace_event(f"init {self.__class__.__name__}")
|
|
24
|
-
self.emit =
|
|
25
|
-
if not self.emit:
|
|
26
|
-
raise RuntimeError("Action should be instantiated in a Chainlit context")
|
|
24
|
+
self.emit = get_emitter().emit
|
|
27
25
|
|
|
28
26
|
async def send(self, for_id: str):
|
|
29
27
|
trace_event(f"send {self.__class__.__name__}")
|
|
@@ -21,6 +21,7 @@ from chainlit.cli.deploy import deploy
|
|
|
21
21
|
from chainlit.cli.utils import check_file
|
|
22
22
|
from chainlit.telemetry import trace_event
|
|
23
23
|
from chainlit.cache import init_lc_cache
|
|
24
|
+
from chainlit.db import init_local_db, migrate_local_db
|
|
24
25
|
from chainlit.logger import logger
|
|
25
26
|
from chainlit.server import app
|
|
26
27
|
|
|
@@ -50,6 +51,9 @@ def run_chainlit(target: str):
|
|
|
50
51
|
# Initialize the LangChain cache if installed and enabled
|
|
51
52
|
init_lc_cache()
|
|
52
53
|
|
|
54
|
+
# Initialize the local database if configured to use it
|
|
55
|
+
init_local_db()
|
|
56
|
+
|
|
53
57
|
log_level = "debug" if config.run.debug else "error"
|
|
54
58
|
|
|
55
59
|
# Start the server
|
|
@@ -60,26 +64,69 @@ def run_chainlit(target: str):
|
|
|
60
64
|
|
|
61
65
|
# Run the asyncio event loop instead of uvloop to enable re entrance
|
|
62
66
|
asyncio.run(start())
|
|
63
|
-
# uvicorn.run(app, host=host, port=port)
|
|
67
|
+
# uvicorn.run(app, host=host, port=port, log_level=log_level)
|
|
64
68
|
|
|
65
69
|
|
|
66
70
|
# Define the "run" command for Chainlit CLI
|
|
67
71
|
@cli.command("run")
|
|
68
72
|
@click.argument("target", required=True, envvar="RUN_TARGET")
|
|
69
|
-
@click.option(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
@click.option(
|
|
74
|
+
"-w",
|
|
75
|
+
"--watch",
|
|
76
|
+
default=False,
|
|
77
|
+
is_flag=True,
|
|
78
|
+
envvar="WATCH",
|
|
79
|
+
help="Reload the app when the module changes",
|
|
80
|
+
)
|
|
81
|
+
@click.option(
|
|
82
|
+
"-h",
|
|
83
|
+
"--headless",
|
|
84
|
+
default=False,
|
|
85
|
+
is_flag=True,
|
|
86
|
+
envvar="HEADLESS",
|
|
87
|
+
help="Will prevent to auto open the app in the browser",
|
|
88
|
+
)
|
|
89
|
+
@click.option(
|
|
90
|
+
"-d",
|
|
91
|
+
"--debug",
|
|
92
|
+
default=False,
|
|
93
|
+
is_flag=True,
|
|
94
|
+
envvar="DEBUG",
|
|
95
|
+
help="Set the log level to debug",
|
|
96
|
+
)
|
|
97
|
+
@click.option(
|
|
98
|
+
"-c",
|
|
99
|
+
"--ci",
|
|
100
|
+
default=False,
|
|
101
|
+
is_flag=True,
|
|
102
|
+
envvar="CI",
|
|
103
|
+
help="Flag to run in CI mode",
|
|
104
|
+
)
|
|
105
|
+
@click.option(
|
|
106
|
+
"--no-cache",
|
|
107
|
+
default=False,
|
|
108
|
+
is_flag=True,
|
|
109
|
+
envvar="NO_CACHE",
|
|
110
|
+
help="Useful to disable third parties cache, such as langchain.",
|
|
111
|
+
)
|
|
112
|
+
@click.option(
|
|
113
|
+
"--db",
|
|
114
|
+
type=click.Choice(["cloud", "local"]),
|
|
115
|
+
help="Useful to control database mode when running CI.",
|
|
116
|
+
)
|
|
117
|
+
@click.option("--host", help="Specify a different host to run the server on")
|
|
118
|
+
@click.option("--port", help="Specify a different port to run the server on")
|
|
119
|
+
def chainlit_run(target, watch, headless, debug, ci, no_cache, db, host, port):
|
|
77
120
|
if host:
|
|
78
121
|
os.environ["CHAINLIT_HOST"] = host
|
|
79
122
|
if port:
|
|
80
123
|
os.environ["CHAINLIT_PORT"] = port
|
|
81
124
|
if ci:
|
|
82
125
|
logger.info("Running in CI mode")
|
|
126
|
+
|
|
127
|
+
if db:
|
|
128
|
+
config.project.database = db
|
|
129
|
+
|
|
83
130
|
config.project.enable_telemetry = False
|
|
84
131
|
no_cache = True
|
|
85
132
|
from chainlit.cli.mock import mock_openai
|
|
@@ -131,6 +178,14 @@ def chainlit_logout(args=None, **kwargs):
|
|
|
131
178
|
sys.exit(0)
|
|
132
179
|
|
|
133
180
|
|
|
181
|
+
@cli.command("migrate")
|
|
182
|
+
@click.argument("args", nargs=-1)
|
|
183
|
+
def chainlit_migrate(args=None, **kwargs):
|
|
184
|
+
trace_event("chainlit migrate")
|
|
185
|
+
migrate_local_db()
|
|
186
|
+
sys.exit(0)
|
|
187
|
+
|
|
188
|
+
|
|
134
189
|
@cli.command("init")
|
|
135
190
|
@click.argument("args", nargs=-1)
|
|
136
191
|
def chainlit_init(args=None, **kwargs):
|