From 7e3bfc54a59b5e8456a9c9ae8cac45789e1e1aa7 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Thu, 8 Jun 2023 15:57:50 +0200 Subject: [PATCH 1/4] add PDF viewer element --- api-reference/elements/pdf.mdx | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 api-reference/elements/pdf.mdx diff --git a/api-reference/elements/pdf.mdx b/api-reference/elements/pdf.mdx new file mode 100644 index 0000000..fa3d13a --- /dev/null +++ b/api-reference/elements/pdf.mdx @@ -0,0 +1,58 @@ +--- +title: "PDF viewer" +--- + +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. + +### Attributes + + + The name of the PDF to be displayed in the UI. + + + + Determines how the PDF element should be displayed in the UI. Choices are + "side" (default), "inline", or "page". + + + + The remote URL of the PDF file. Must provide url for a remote PDF (or either path or content for a local PDF). + + + + The local file path of the PDF. Must provide either path or content for a local PDF (or url for a remote PDF). + + + + The file content of the PDF in bytes format. Must provide either path or + content for a local PDF (or url for a remote PDF). + + +### Usage with message scope + +```python Code Example +from chainlit import PDF + +# Sending a pdf with the local file path +elements = [ + PDF(name="pdf1", display="inline", path="./pdf1.pdf") +] + +cl.Message(content="Look at this local pdf!", elements=elements).send() +``` + +### Usage without scope + +```python Code Example +from chainlit import PDF + +# Sending a pdf with the remote url +pdf1 = PDF(name="pdf1", display="inline", url="https://example.com/example.pdf") +pdf1.send() + +# Sending a pdf with file content as bytes +with open("./pdf2.pdf", "rb") as f: + pdf_content = f.read() + pdf2 = PDF(name="pdf2", display="inline", content=pdf_content) + pdf2.send() +``` From 7c612318ca838d131a8a9b2bc9e04a9f9d8833af Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Thu, 8 Jun 2023 16:39:28 +0200 Subject: [PATCH 2/4] add missing link --- mint.json | 1 + 1 file changed, 1 insertion(+) diff --git a/mint.json b/mint.json index cad5ea3..560333d 100644 --- a/mint.json +++ b/mint.json @@ -72,6 +72,7 @@ "group": "Elements", "pages": [ "api-reference/elements/local-image", + "api-reference/elements/pdf", "api-reference/elements/remote-image", "api-reference/elements/text" ] From 69e62a36bee03df31adbc51be106846e98506aa2 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Thu, 8 Jun 2023 16:54:57 +0200 Subject: [PATCH 3/4] change import style in element examples --- api-reference/elements/local-image.mdx | 10 +++++----- api-reference/elements/pdf.mdx | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api-reference/elements/local-image.mdx b/api-reference/elements/local-image.mdx index 14ae473..2f98316 100644 --- a/api-reference/elements/local-image.mdx +++ b/api-reference/elements/local-image.mdx @@ -32,11 +32,11 @@ The `LocalImage` class is designed to create and handle local image elements to ### Usage with message scope ```python Code Example -from chainlit import LocalImage +import chainlit as cl # Sending an image with the local file path elements = [ - LocalImage(name="image1", display="inline", path="./image1.jpg") + cl.LocalImage(name="image1", display="inline", path="./image1.jpg") ] 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() ### Usage without scope ```python Code Example -from chainlit import LocalImage +import chainlit as cl # Sending an image with the local file path -image1 = LocalImage(name="image1", display="inline", path="./image1.jpg") +image1 = cl.LocalImage(name="image1", display="inline", path="./image1.jpg") image1.send() # Sending an image with file content as bytes with open("./image2.jpg", "rb") as f: image_content = f.read() - image2 = LocalImage(name="image2", display="inline", content=image_content) + image2 = cl.LocalImage(name="image2", display="inline", content=image_content) image2.send() ``` diff --git a/api-reference/elements/pdf.mdx b/api-reference/elements/pdf.mdx index fa3d13a..82230fc 100644 --- a/api-reference/elements/pdf.mdx +++ b/api-reference/elements/pdf.mdx @@ -31,11 +31,11 @@ The `PDF` class allows you to display a pdf hosted remotely or locally in the ch ### Usage with message scope ```python Code Example -from chainlit import PDF +import chainlit as cl # Sending a pdf with the local file path elements = [ - PDF(name="pdf1", display="inline", path="./pdf1.pdf") + cl.PDF(name="pdf1", display="inline", path="./pdf1.pdf") ] cl.Message(content="Look at this local pdf!", elements=elements).send() @@ -44,15 +44,15 @@ cl.Message(content="Look at this local pdf!", elements=elements).send() ### Usage without scope ```python Code Example -from chainlit import PDF +import chainlit as cl # Sending a pdf with the remote url -pdf1 = PDF(name="pdf1", display="inline", url="https://example.com/example.pdf") +pdf1 = cl.PDF(name="pdf1", display="inline", url="https://example.com/example.pdf") pdf1.send() # Sending a pdf with file content as bytes with open("./pdf2.pdf", "rb") as f: pdf_content = f.read() - pdf2 = PDF(name="pdf2", display="inline", content=pdf_content) + pdf2 = cl.PDF(name="pdf2", display="inline", content=pdf_content) pdf2.send() ``` From d44324bb02277b198f41defed1bff49c44097a58 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Thu, 8 Jun 2023 17:05:06 +0200 Subject: [PATCH 4/4] fix Pdf class casing --- api-reference/elements/pdf.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api-reference/elements/pdf.mdx b/api-reference/elements/pdf.mdx index 82230fc..e5bf1af 100644 --- a/api-reference/elements/pdf.mdx +++ b/api-reference/elements/pdf.mdx @@ -2,7 +2,7 @@ title: "PDF viewer" --- -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. +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. ### Attributes @@ -35,7 +35,7 @@ import chainlit as cl # Sending a pdf with the local file path elements = [ - cl.PDF(name="pdf1", display="inline", path="./pdf1.pdf") + cl.Pdf(name="pdf1", display="inline", path="./pdf1.pdf") ] cl.Message(content="Look at this local pdf!", elements=elements).send() @@ -47,12 +47,12 @@ cl.Message(content="Look at this local pdf!", elements=elements).send() import chainlit as cl # Sending a pdf with the remote url -pdf1 = cl.PDF(name="pdf1", display="inline", url="https://example.com/example.pdf") +pdf1 = cl.Pdf(name="pdf1", display="inline", url="https://example.com/example.pdf") pdf1.send() # Sending a pdf with file content as bytes with open("./pdf2.pdf", "rb") as f: pdf_content = f.read() - pdf2 = cl.PDF(name="pdf2", display="inline", content=pdf_content) + pdf2 = cl.Pdf(name="pdf2", display="inline", content=pdf_content) pdf2.send() ```