You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: api-reference/elements/text.mdx
+17-5Lines changed: 17 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,27 @@ title: "Text"
3
3
---
4
4
5
5
The `Text` class allows you to display a text element in the chatbot UI. This class takes a string and creates a text element that can be sent to the UI.
6
+
It supports the markdown syntax for formatting text.
7
+
8
+
You must provide either an url or a path or content bytes.
6
9
7
10
### Attributes
8
11
9
12
<ParamFieldpath="name"type="str">
10
13
The name of the text element to be displayed in the UI.
11
14
</ParamField>
12
15
13
-
<ParamFieldpath="text"type="str">
14
-
The text string that should be displayed as the content of the text element.
When running your own LangChain agent, typically using [langchain_run](/api-reference/langchain/langchain-run), it is essential to provide the appropriate callback handler. This ensures seamless communication between the Chainlit UI and your agent.
6
+
7
+
There are two ways to pass the callback handler:
8
+
9
+
1. Pass the callback handler during runtime. This will apply the handler to all calls made by your agent.
10
+
2. Pass the callback handler to individual components, such as an `llm`, allowing you to control what information is returned to the UI.
11
+
12
+
### Asynchronous Callback Handler
13
+
14
+
The following code example demonstrates how to pass an asynchronous callback handler.
15
+
16
+
```python
17
+
@cl.langchain_run
18
+
asyncdefrun(agent, input_str):
19
+
res =await agent.acall(input_str, callbacks=[cl.AsyncChainlitCallbackHandler()])
20
+
await cl.Message(content=res["text"]).send()
21
+
```
22
+
23
+
Notice the `acall` here, that could also be `arun` or any other async function. Since we are calling the asynchronous implementation of the agent, we need to use the asynchronous callback handler.
24
+
25
+
### Synchronous Callback Handler
26
+
27
+
Alternatively, you can pass a synchronous callback handler, as shown in the example below:
28
+
29
+
```python
30
+
@cl.langchain_run
31
+
asyncdefrun(agent, input_str):
32
+
res =await cl.make_async(agent)(input_str, callbacks=[cl.ChainlitCallbackHandler()])
33
+
await cl.Message(content=res["text"]).send()
34
+
```
35
+
36
+
Since we are calling a long running synchronous function, we need to wrap it in `cl.make_async` to make it asynchronous and not block the event loop.
37
+
The function will still run synchronously in its own thread, hence we use the synchronous callback handler.
38
+
39
+
Choose the appropriate callback handler based on your specific requirements, ensuring seamless interaction between your LangChain agent and the Chainlit UI.
Copy file name to clipboardExpand all lines: api-reference/langchain/langchain-factory.mdx
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,27 @@
1
1
---
2
2
title: "langchain_factory"
3
3
---
4
-
Plug and play decorator for the LangChain library.
4
+
5
+
Plug and play decorator for the LangChain library.
5
6
6
7
The decorated function should instantiate a new LangChain instance (Chain, Agent...). One instance per user session is created and cached. The per user instance is called every time a new message is received.
7
8
8
-
<RequestExample>
9
+
### Parameters
10
+
11
+
<ParamFieldpath="use_async"type="bool">
12
+
Whether to use the async implementation of the agent or not.
0 commit comments