chainlit 0.7.700__py3-none-any.whl → 1.0.0rc1__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/__init__.py +32 -23
- chainlit/auth.py +9 -10
- chainlit/cli/__init__.py +1 -2
- chainlit/config.py +13 -12
- chainlit/context.py +7 -3
- chainlit/data/__init__.py +375 -9
- chainlit/data/acl.py +6 -5
- chainlit/element.py +86 -123
- chainlit/emitter.py +117 -50
- chainlit/frontend/dist/assets/{index-71698725.js → index-6aee009a.js} +118 -292
- chainlit/frontend/dist/assets/{react-plotly-2c0acdf0.js → react-plotly-2f07c02a.js} +1 -1
- chainlit/frontend/dist/index.html +1 -1
- chainlit/haystack/callbacks.py +45 -43
- chainlit/hello.py +1 -1
- chainlit/langchain/callbacks.py +132 -120
- chainlit/llama_index/callbacks.py +68 -48
- chainlit/message.py +179 -207
- chainlit/oauth_providers.py +39 -34
- chainlit/playground/provider.py +44 -30
- chainlit/playground/providers/anthropic.py +4 -4
- chainlit/playground/providers/huggingface.py +2 -2
- chainlit/playground/providers/langchain.py +8 -10
- chainlit/playground/providers/openai.py +19 -13
- chainlit/server.py +155 -99
- chainlit/session.py +109 -40
- chainlit/socket.py +47 -36
- chainlit/step.py +393 -0
- chainlit/types.py +78 -21
- chainlit/user.py +32 -0
- chainlit/user_session.py +1 -5
- {chainlit-0.7.700.dist-info → chainlit-1.0.0rc1.dist-info}/METADATA +12 -31
- chainlit-1.0.0rc1.dist-info/RECORD +60 -0
- chainlit/client/base.py +0 -169
- chainlit/client/cloud.py +0 -502
- chainlit/prompt.py +0 -40
- chainlit-0.7.700.dist-info/RECORD +0 -61
- {chainlit-0.7.700.dist-info → chainlit-1.0.0rc1.dist-info}/WHEEL +0 -0
- {chainlit-0.7.700.dist-info → chainlit-1.0.0rc1.dist-info}/entry_points.txt +0 -0
chainlit/user.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Dict, Literal, TypedDict
|
|
2
|
+
|
|
3
|
+
from dataclasses_json import DataClassJsonMixin
|
|
4
|
+
from pydantic.dataclasses import Field, dataclass
|
|
5
|
+
|
|
6
|
+
Provider = Literal[
|
|
7
|
+
"credentials", "header", "github", "google", "azure-ad", "okta", "auth0", "descope"
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class UserDict(TypedDict):
|
|
12
|
+
id: str
|
|
13
|
+
identifier: str
|
|
14
|
+
metadata: Dict
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Used when logging-in a user
|
|
18
|
+
@dataclass
|
|
19
|
+
class User(DataClassJsonMixin):
|
|
20
|
+
identifier: str
|
|
21
|
+
metadata: Dict = Field(default_factory=dict)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class PersistedUserFields:
|
|
26
|
+
id: str
|
|
27
|
+
createdAt: str
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class PersistedUser(User, PersistedUserFields):
|
|
32
|
+
pass
|
chainlit/user_session.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: chainlit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0rc1
|
|
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
|
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Requires-Dist: aiofiles (>=23.1.0,<24.0.0)
|
|
16
16
|
Requires-Dist: asyncer (>=0.0.2,<0.0.3)
|
|
17
|
+
Requires-Dist: chainlit_client (==0.1.0rc5)
|
|
17
18
|
Requires-Dist: click (>=8.1.3,<9.0.0)
|
|
18
19
|
Requires-Dist: dataclasses_json (>=0.5.7,<0.6.0)
|
|
19
20
|
Requires-Dist: fastapi (>=0.100,<0.101)
|
|
@@ -46,13 +47,7 @@ Description-Content-Type: text/markdown
|
|
|
46
47
|
|
|
47
48
|
Chainlit is an open-source async Python framework that makes it incredibly fast to build Chat GPT like applications with your **own business logic and data**.
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- [💬 Multi Modal chats](https://docs.chainlit.io/chat-experience/elements)
|
|
52
|
-
- [💭 Chain of Thought visualisation](https://docs.chainlit.io/observability-iteration/chain-of-thought)
|
|
53
|
-
- [💾 Data persistence + human feedback](https://docs.chainlit.io/chat-data/overview)
|
|
54
|
-
- [🛝 In context Prompt Playground](https://docs.chainlit.io/observability-iteration/prompt-playground/overview)
|
|
55
|
-
- [👤 Authentication](https://docs.chainlit.io/authentication/overview)
|
|
50
|
+
Contact us [here](https://forms.gle/BX3UNBLmTF75KgZVA) for **Enterprise Support** and to get early access to the **Analytics & Observability** product.
|
|
56
51
|
|
|
57
52
|
https://github.com/Chainlit/chainlit/assets/13104895/8882af90-fdfa-4b24-8200-1ee96c6c7490
|
|
58
53
|
|
|
@@ -85,11 +80,16 @@ Create a new file `demo.py` with the following code:
|
|
|
85
80
|
import chainlit as cl
|
|
86
81
|
|
|
87
82
|
|
|
83
|
+
@cl.step
|
|
84
|
+
def tool():
|
|
85
|
+
return "Response from the tool!"
|
|
86
|
+
|
|
87
|
+
|
|
88
88
|
@cl.on_message # this function will be called every time a user inputs a message in the UI
|
|
89
89
|
async def main(message: cl.Message):
|
|
90
90
|
"""
|
|
91
91
|
This function is called every time a user inputs a message in the UI.
|
|
92
|
-
It sends back an intermediate response from
|
|
92
|
+
It sends back an intermediate response from the tool, followed by the final answer.
|
|
93
93
|
|
|
94
94
|
Args:
|
|
95
95
|
message: The user's message.
|
|
@@ -98,15 +98,11 @@ async def main(message: cl.Message):
|
|
|
98
98
|
None.
|
|
99
99
|
"""
|
|
100
100
|
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
author="Tool 1",
|
|
104
|
-
content=f"Response from tool1",
|
|
105
|
-
parent_id=message.id,
|
|
106
|
-
).send()
|
|
101
|
+
# Call the tool
|
|
102
|
+
tool()
|
|
107
103
|
|
|
108
104
|
# Send the final answer.
|
|
109
|
-
await cl.Message(content=
|
|
105
|
+
await cl.Message(content="This is the final answer").send()
|
|
110
106
|
```
|
|
111
107
|
|
|
112
108
|
Now run it!
|
|
@@ -126,7 +122,6 @@ Chainlit is compatible with all Python programs and libraries. That being said,
|
|
|
126
122
|
- [OpenAI Assistant](https://github.com/Chainlit/cookbook/tree/main/openai-assistant)
|
|
127
123
|
- [Llama Index](https://docs.chainlit.io/integrations/llama-index)
|
|
128
124
|
- [Haystack](https://docs.chainlit.io/integrations/haystack)
|
|
129
|
-
- [Langflow](https://docs.chainlit.io/integrations/langflow)
|
|
130
125
|
|
|
131
126
|
## 🎨 Custom Frontend
|
|
132
127
|
|
|
@@ -145,22 +140,8 @@ To build and connect your own frontend, check out our [Custom Frontend Cookbook]
|
|
|
145
140
|
|
|
146
141
|
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.
|
|
147
142
|
|
|
148
|
-
## 🛣 Roadmap
|
|
149
|
-
|
|
150
|
-
- [x] Selectable chat profiles (at the beginning of a chat)
|
|
151
|
-
- [ ] One click chat sharing
|
|
152
|
-
- New clients:
|
|
153
|
-
- [x] Custom React app
|
|
154
|
-
- [ ] Slack
|
|
155
|
-
- [ ] Discord
|
|
156
|
-
- [ ] Website embbed
|
|
157
|
-
|
|
158
143
|
Tell us what you would like to see added in Chainlit using the Github issues or on [Discord](https://discord.gg/k73SQ3FyUh).
|
|
159
144
|
|
|
160
|
-
## 🏢 Enterprise support
|
|
161
|
-
|
|
162
|
-
For entreprise grade features and self hosting, please visit this [page](https://docs.chainlit.io/cloud/persistence/enterprise) and fill the form.
|
|
163
|
-
|
|
164
145
|
## 💁 Contributing
|
|
165
146
|
|
|
166
147
|
As an open-source initiative in a rapidly evolving domain, we welcome contributions, be it through the addition of new features or the improvement of documentation.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
chainlit/__init__.py,sha256=yz2t0aQP7HV48o5XwSDzcn1UTQDTpbDLOoyQWjyS5oI,8998
|
|
2
|
+
chainlit/__main__.py,sha256=7Vg3w3T3qDuz4KDu5lQhLH6lQ3cYdume7gHH7Z1V97U,87
|
|
3
|
+
chainlit/action.py,sha256=k-GsblVHI4DnDWFyF-RZgq3KfdfAFICFh2OBeU4w8N8,1410
|
|
4
|
+
chainlit/auth.py,sha256=q06SthxJAqCDYZuGOIYaye3CL4o3ldC-NIXASpeZUA8,2681
|
|
5
|
+
chainlit/cache.py,sha256=Bv3dT4eHhE6Fq3c6Do0ZTpiyoXgXYewdxTgpYghEd9g,1361
|
|
6
|
+
chainlit/chat_settings.py,sha256=2ByenmwS8O6jQjDVJjhhbLrBPGA5aY2F7R3VvQQxXPk,877
|
|
7
|
+
chainlit/cli/__init__.py,sha256=aMynTbqbJEvxkoIzDjsdKL6wJ0HFgLfVrbxFkwqp1FU,4733
|
|
8
|
+
chainlit/cli/utils.py,sha256=mE2d9oOk-B2b9ZvDV1zENoDWxjfMriGP7bVwEFduZP4,717
|
|
9
|
+
chainlit/config.py,sha256=2DaQ51jHKHdwAH0yNbB3HkJhccU99eOqDXxvk19A1jU,10577
|
|
10
|
+
chainlit/context.py,sha256=Su3eabnD2sgLNx5IwlxEpG4pev64GLi-GlvbE5Mw7sM,2264
|
|
11
|
+
chainlit/data/__init__.py,sha256=dcmfMBPlzv4D5Vp3lBg4s9cEanx9E_OWmsIlzL4qbdQ,12876
|
|
12
|
+
chainlit/data/acl.py,sha256=hx7Othkx12EitonyZD4iFIRVHwxBmBY2TKdwjPuZMSo,461
|
|
13
|
+
chainlit/element.py,sha256=9dVK7frFjJvmmONWAZTU1LWvim3c4woisy9zX9iEH-s,10010
|
|
14
|
+
chainlit/emitter.py,sha256=97HHD5jI62mtF8FfR_8m4okrm1AqL7jM-zDBqbIfjpE,10693
|
|
15
|
+
chainlit/frontend/dist/assets/index-6aee009a.js,sha256=k_thBwlPbxngnLq6BIWODptjQdLB69AC_t70RSb9xc4,3103190
|
|
16
|
+
chainlit/frontend/dist/assets/index-8942cb2d.css,sha256=iULLLdx-rywLKpSdrJuSZwAF22WLkNdLKypNpaN5PQY,6557
|
|
17
|
+
chainlit/frontend/dist/assets/logo_dark-bc7401f6.svg,sha256=vHQB9g-n5OqOmuH3Fduuc7ZMg0EmMsGyO9cEnYwLbHg,8889
|
|
18
|
+
chainlit/frontend/dist/assets/logo_light-f19fc2ea.svg,sha256=8Z_C6t-0V9QL9ldmLjaLfp2REcGDuaTeNynj6-6muNI,8891
|
|
19
|
+
chainlit/frontend/dist/assets/react-plotly-2f07c02a.js,sha256=SktlbpTd6VvpHSPCRj2JTK79rsQ4y4gFLEk9XC-icaU,3739251
|
|
20
|
+
chainlit/frontend/dist/favicon.svg,sha256=0Cy8x28obT5eWW3nxZRhsEvu6_zMqrqbg0y6hT3D0Q0,6455
|
|
21
|
+
chainlit/frontend/dist/index.html,sha256=x7AoiD4tsnIAs4Y76CX7Na_1CzEPNU3iSk2UINMjmwA,959
|
|
22
|
+
chainlit/haystack/__init__.py,sha256=uZ77YiPy-qleSTi3dQCDO9HE6S6F6GpJWmh7jO4cxXA,217
|
|
23
|
+
chainlit/haystack/callbacks.py,sha256=0tbevNVa5hqN7Num6PGwm_DU_-ZdhfsVp9srKciotNE,4055
|
|
24
|
+
chainlit/hello.py,sha256=LwENQWo5s5r8nNDn4iKSV77vX60Ky5r_qGjQhyi7qlY,416
|
|
25
|
+
chainlit/input_widget.py,sha256=1Z1qn3YwaZ7upqqxZXtbfDxBlVobDjbZ3HtlNOj-U3E,4880
|
|
26
|
+
chainlit/langchain/__init__.py,sha256=zErMw0_3ufSGeF9ye7X0ZX3wDat4mTOx97T40ePDO2g,217
|
|
27
|
+
chainlit/langchain/callbacks.py,sha256=P1w2DRv2G_q5rHEp2nWvLKm6gBUWlA2VQgJB0iUO2XA,24035
|
|
28
|
+
chainlit/langflow/__init__.py,sha256=wxhxdsl1yxdsRyNTgZticxFF_8VFtJJ4OdIy3tnEIyM,817
|
|
29
|
+
chainlit/llama_index/__init__.py,sha256=c7wIUZmKTtZPU9zpdGpKTHctQaBWTuRGqTN0kkIkBcg,218
|
|
30
|
+
chainlit/llama_index/callbacks.py,sha256=BAFyoL2VkoG5pt6_GHMJ58Xu39_T-trhBYL14XVsvWU,5595
|
|
31
|
+
chainlit/logger.py,sha256=wTwRSZsLfXwWy6U4351IgWAm4KCMThgxm9EZpjGUEr4,373
|
|
32
|
+
chainlit/markdown.py,sha256=L2IPPWxIlrhJZcKPfO1akomHdN3sgC2EvC2ilxR8MQs,1624
|
|
33
|
+
chainlit/message.py,sha256=-5GTkSwvzwkeEXyO5jpoz5BDSjn8w5Kf5UKJoUOZXrE,17470
|
|
34
|
+
chainlit/oauth_providers.py,sha256=M-kV0rq4HwhDHvzdVc7YvAV4xPj5ecHvWniMMUTJAOM,15209
|
|
35
|
+
chainlit/playground/__init__.py,sha256=igNRcBgqLKPTjOQtTNhhGNJFmZn-Dl1fHRQzQSjDGTQ,80
|
|
36
|
+
chainlit/playground/config.py,sha256=a6fnIU2IrYQDKU6zHF8qUD3ssUBD9UiTEN10pMxgnGY,998
|
|
37
|
+
chainlit/playground/provider.py,sha256=mO4mC--c4LXOYWBvNWse90iTD3288yd5TVuIeqSVOgg,5173
|
|
38
|
+
chainlit/playground/providers/__init__.py,sha256=L4Y7Udpexm769Jnf-mIeN-YGh6xaaMjF3rPxSfReiN4,225
|
|
39
|
+
chainlit/playground/providers/anthropic.py,sha256=Fcozvo4I_hguOuQbI4XgdR8Y03SNNv9PhHZrVXm_4ZE,3447
|
|
40
|
+
chainlit/playground/providers/huggingface.py,sha256=AmBmIzvfqBjswEI40jifb0OrMQkTk5rXCkGX7nMJ-bk,2130
|
|
41
|
+
chainlit/playground/providers/langchain.py,sha256=paASoTD1JCwOh7sXuajtrDcYuMcWC1AnITa_Co7uQFU,2813
|
|
42
|
+
chainlit/playground/providers/openai.py,sha256=61Rr_JqfrI5x3CoTdQUvcMm_Q2aXwIuD9aHKvfXvlEY,12593
|
|
43
|
+
chainlit/playground/providers/vertexai.py,sha256=TwFyhNmbStUso0ShvoRzOQ5b4l8ErG1szxqjv4IRXE0,3678
|
|
44
|
+
chainlit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
45
|
+
chainlit/secret.py,sha256=0MXq8YxTeL93K8IyAew5UgZmIIw9_yJ_Kg4iML6cdVM,296
|
|
46
|
+
chainlit/server.py,sha256=KdjRGquRdDcimDuCHd0h78t2cVPvqJ82fKWMeBsZUJ0,20672
|
|
47
|
+
chainlit/session.py,sha256=x5Wsid7yO3O6tbQCKLP-cP19wRK-NsnX0bkftL9S8ls,8336
|
|
48
|
+
chainlit/socket.py,sha256=vPdAkSoIEKvGu3LuG7y7JP6IZFgFAk5dPW-t1aK6DB8,9066
|
|
49
|
+
chainlit/step.py,sha256=qwQ7dfduxSMKeLh9yGMiFsqTOZmYiVO732i67EGrUCk,11806
|
|
50
|
+
chainlit/sync.py,sha256=G1n-7-3WgXsN8y1bJkEyws_YwmHZIyDZoZUwhprigag,1235
|
|
51
|
+
chainlit/telemetry.py,sha256=sIZzYk0YEmtWbOS8B5tf6aQfW-uKzwvVtajpbj8bLMw,3210
|
|
52
|
+
chainlit/types.py,sha256=zEuxivoNAZg_3BzcWwGPpqz1xX8AoZQYpyWm9e8ZGTk,3361
|
|
53
|
+
chainlit/user.py,sha256=Cw4uGz0ffivWFszv8W__EHwkvTHQ3Lj9hqpRCPxFujo,619
|
|
54
|
+
chainlit/user_session.py,sha256=nyPx8vSICP8BhpPcW5h9vbHVf9ixj39SrkvJBUI_6zs,1368
|
|
55
|
+
chainlit/utils.py,sha256=3HzhfZ4XJhBIe9sJ_3Lxv3lMH4mFXsi6nLBGqm8Gtdw,2571
|
|
56
|
+
chainlit/version.py,sha256=iosXhlXclBwBqlADFKEilxAC2wWKbtuBKi87AmPi7s8,196
|
|
57
|
+
chainlit-1.0.0rc1.dist-info/METADATA,sha256=wFGDeKL9iepJUmnb1SaBCTHVr8ufZbItACHQcaPmN-U,5508
|
|
58
|
+
chainlit-1.0.0rc1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
59
|
+
chainlit-1.0.0rc1.dist-info/entry_points.txt,sha256=FrkqdjrFl8juSnvBndniyX7XuKojmUwO4ghRh-CFMQc,45
|
|
60
|
+
chainlit-1.0.0rc1.dist-info/RECORD,,
|
chainlit/client/base.py
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
from typing import (
|
|
2
|
-
Any,
|
|
3
|
-
Dict,
|
|
4
|
-
Generic,
|
|
5
|
-
List,
|
|
6
|
-
Literal,
|
|
7
|
-
Mapping,
|
|
8
|
-
Optional,
|
|
9
|
-
TypedDict,
|
|
10
|
-
TypeVar,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
from chainlit.logger import logger
|
|
14
|
-
from chainlit.prompt import Prompt
|
|
15
|
-
from dataclasses_json import DataClassJsonMixin
|
|
16
|
-
from pydantic import BaseModel, Field
|
|
17
|
-
from pydantic.dataclasses import dataclass
|
|
18
|
-
from python_graphql_client import GraphqlClient
|
|
19
|
-
|
|
20
|
-
ElementType = Literal[
|
|
21
|
-
"image", "avatar", "text", "pdf", "tasklist", "audio", "video", "file", "plotly"
|
|
22
|
-
]
|
|
23
|
-
ElementDisplay = Literal["inline", "side", "page"]
|
|
24
|
-
ElementSize = Literal["small", "medium", "large"]
|
|
25
|
-
|
|
26
|
-
Role = Literal["USER", "ADMIN", "OWNER", "ANONYMOUS"]
|
|
27
|
-
Provider = Literal[
|
|
28
|
-
"credentials", "header", "github", "google", "azure-ad", "okta", "auth0", "descope"
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class AppUserDict(TypedDict):
|
|
33
|
-
id: str
|
|
34
|
-
username: str
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# Used when logging-in a user
|
|
38
|
-
@dataclass
|
|
39
|
-
class AppUser(DataClassJsonMixin):
|
|
40
|
-
username: str
|
|
41
|
-
role: Role = "USER"
|
|
42
|
-
tags: List[str] = Field(default_factory=list)
|
|
43
|
-
image: Optional[str] = None
|
|
44
|
-
provider: Optional[Provider] = None
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
@dataclass
|
|
48
|
-
class PersistedAppUserFields:
|
|
49
|
-
id: str
|
|
50
|
-
createdAt: int
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@dataclass
|
|
54
|
-
class PersistedAppUser(AppUser, PersistedAppUserFields):
|
|
55
|
-
pass
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class MessageDict(TypedDict):
|
|
59
|
-
conversationId: Optional[str]
|
|
60
|
-
id: str
|
|
61
|
-
createdAt: Optional[int]
|
|
62
|
-
content: str
|
|
63
|
-
author: str
|
|
64
|
-
prompt: Optional[Prompt]
|
|
65
|
-
language: Optional[str]
|
|
66
|
-
parentId: Optional[str]
|
|
67
|
-
indent: Optional[int]
|
|
68
|
-
authorIsUser: Optional[bool]
|
|
69
|
-
waitForAnswer: Optional[bool]
|
|
70
|
-
isError: Optional[bool]
|
|
71
|
-
humanFeedback: Optional[int]
|
|
72
|
-
disableHumanFeedback: Optional[bool]
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
class ElementDict(TypedDict):
|
|
76
|
-
id: str
|
|
77
|
-
conversationId: Optional[str]
|
|
78
|
-
type: ElementType
|
|
79
|
-
url: str
|
|
80
|
-
objectKey: Optional[str]
|
|
81
|
-
name: str
|
|
82
|
-
display: ElementDisplay
|
|
83
|
-
size: Optional[ElementSize]
|
|
84
|
-
language: Optional[str]
|
|
85
|
-
forIds: Optional[List[str]]
|
|
86
|
-
mime: Optional[str]
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
class ConversationDict(TypedDict):
|
|
90
|
-
id: Optional[str]
|
|
91
|
-
metadata: Optional[Dict]
|
|
92
|
-
createdAt: Optional[int]
|
|
93
|
-
appUser: Optional[AppUserDict]
|
|
94
|
-
messages: List[MessageDict]
|
|
95
|
-
elements: Optional[List[ElementDict]]
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
@dataclass
|
|
99
|
-
class PageInfo:
|
|
100
|
-
hasNextPage: bool
|
|
101
|
-
endCursor: Optional[str]
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
T = TypeVar("T")
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
@dataclass
|
|
108
|
-
class PaginatedResponse(DataClassJsonMixin, Generic[T]):
|
|
109
|
-
pageInfo: PageInfo
|
|
110
|
-
data: List[T]
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
class Pagination(BaseModel):
|
|
114
|
-
first: int
|
|
115
|
-
cursor: Optional[str] = None
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
class ConversationFilter(BaseModel):
|
|
119
|
-
feedback: Optional[Literal[-1, 0, 1]] = None
|
|
120
|
-
username: Optional[str] = None
|
|
121
|
-
search: Optional[str] = None
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
class ChainlitGraphQLClient:
|
|
125
|
-
def __init__(self, api_key: str, chainlit_server: str):
|
|
126
|
-
self.headers = {"content-type": "application/json"}
|
|
127
|
-
if api_key:
|
|
128
|
-
self.headers["x-api-key"] = api_key
|
|
129
|
-
else:
|
|
130
|
-
raise ValueError("Cannot instantiate Cloud Client without CHAINLIT_API_KEY")
|
|
131
|
-
|
|
132
|
-
graphql_endpoint = f"{chainlit_server}/api/graphql"
|
|
133
|
-
self.graphql_client = GraphqlClient(
|
|
134
|
-
endpoint=graphql_endpoint, headers=self.headers
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
async def query(self, query: str, variables: Dict[str, Any] = {}) -> Dict[str, Any]:
|
|
138
|
-
"""
|
|
139
|
-
Execute a GraphQL query.
|
|
140
|
-
|
|
141
|
-
:param query: The GraphQL query string.
|
|
142
|
-
:param variables: A dictionary of variables for the query.
|
|
143
|
-
:return: The response data as a dictionary.
|
|
144
|
-
"""
|
|
145
|
-
return await self.graphql_client.execute_async(query=query, variables=variables)
|
|
146
|
-
|
|
147
|
-
def check_for_errors(self, response: Dict[str, Any], raise_error: bool = False):
|
|
148
|
-
if "errors" in response:
|
|
149
|
-
if raise_error:
|
|
150
|
-
raise Exception(
|
|
151
|
-
f"{response['errors'][0]['message']}. Path: {str(response['errors'][0]['path'])}"
|
|
152
|
-
)
|
|
153
|
-
logger.error(response["errors"][0])
|
|
154
|
-
return True
|
|
155
|
-
return False
|
|
156
|
-
|
|
157
|
-
async def mutation(
|
|
158
|
-
self, mutation: str, variables: Mapping[str, Any] = {}
|
|
159
|
-
) -> Dict[str, Any]:
|
|
160
|
-
"""
|
|
161
|
-
Execute a GraphQL mutation.
|
|
162
|
-
|
|
163
|
-
:param mutation: The GraphQL mutation string.
|
|
164
|
-
:param variables: A dictionary of variables for the mutation.
|
|
165
|
-
:return: The response data as a dictionary.
|
|
166
|
-
"""
|
|
167
|
-
return await self.graphql_client.execute_async(
|
|
168
|
-
query=mutation, variables=variables
|
|
169
|
-
)
|