Skip to content

Commit b97b49c

Browse files
authored
Merge pull request Chainlit#3 from tpatel/pdf-viewer
add PDF viewer element
2 parents 64880f7 + d44324b commit b97b49c

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

api-reference/elements/local-image.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ The `LocalImage` class is designed to create and handle local image elements to
3232
### Usage with message scope
3333

3434
```python Code Example
35-
from chainlit import LocalImage
35+
import chainlit as cl
3636

3737
# Sending an image with the local file path
3838
elements = [
39-
LocalImage(name="image1", display="inline", path="./image1.jpg")
39+
cl.LocalImage(name="image1", display="inline", path="./image1.jpg")
4040
]
4141

4242
cl.Message(content="Look at this local image!", elements=elements).send()
@@ -45,15 +45,15 @@ cl.Message(content="Look at this local image!", elements=elements).send()
4545
### Usage without scope
4646

4747
```python Code Example
48-
from chainlit import LocalImage
48+
import chainlit as cl
4949

5050
# Sending an image with the local file path
51-
image1 = LocalImage(name="image1", display="inline", path="./image1.jpg")
51+
image1 = cl.LocalImage(name="image1", display="inline", path="./image1.jpg")
5252
image1.send()
5353

5454
# Sending an image with file content as bytes
5555
with open("./image2.jpg", "rb") as f:
5656
image_content = f.read()
57-
image2 = LocalImage(name="image2", display="inline", content=image_content)
57+
image2 = cl.LocalImage(name="image2", display="inline", content=image_content)
5858
image2.send()
5959
```

api-reference/elements/pdf.mdx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: "PDF viewer"
3+
---
4+
5+
The `Pdf` class allows you to display a PDF hosted remotely or locally in the chatbot UI. This class either takes a URL of a PDF hosted online, or the path of a local PDF.
6+
7+
### Attributes
8+
9+
<ParamField path="name" type="str">
10+
The name of the PDF to be displayed in the UI.
11+
</ParamField>
12+
13+
<ParamField path="display" type="ElementDisplay" optional>
14+
Determines how the PDF element should be displayed in the UI. Choices are
15+
"side" (default), "inline", or "page".
16+
</ParamField>
17+
18+
<ParamField path="url" type="str">
19+
The remote URL of the PDF file. Must provide url for a remote PDF (or either path or content for a local PDF).
20+
</ParamField>
21+
22+
<ParamField path="path" type="str" optional>
23+
The local file path of the PDF. Must provide either path or content for a local PDF (or url for a remote PDF).
24+
</ParamField>
25+
26+
<ParamField path="content" type="bytes" optional>
27+
The file content of the PDF in bytes format. Must provide either path or
28+
content for a local PDF (or url for a remote PDF).
29+
</ParamField>
30+
31+
### Usage with message scope
32+
33+
```python Code Example
34+
import chainlit as cl
35+
36+
# Sending a pdf with the local file path
37+
elements = [
38+
cl.Pdf(name="pdf1", display="inline", path="./pdf1.pdf")
39+
]
40+
41+
cl.Message(content="Look at this local pdf!", elements=elements).send()
42+
```
43+
44+
### Usage without scope
45+
46+
```python Code Example
47+
import chainlit as cl
48+
49+
# Sending a pdf with the remote url
50+
pdf1 = cl.Pdf(name="pdf1", display="inline", url="https://example.com/example.pdf")
51+
pdf1.send()
52+
53+
# Sending a pdf with file content as bytes
54+
with open("./pdf2.pdf", "rb") as f:
55+
pdf_content = f.read()
56+
pdf2 = cl.Pdf(name="pdf2", display="inline", content=pdf_content)
57+
pdf2.send()
58+
```

mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"group": "Elements",
7373
"pages": [
7474
"api-reference/elements/local-image",
75+
"api-reference/elements/pdf",
7576
"api-reference/elements/remote-image",
7677
"api-reference/elements/text"
7778
]

0 commit comments

Comments
 (0)