Pdf 类允许你在聊天机器人 UI 中显示远程或本地托管的 PDF。此类可以接受在线托管的 PDF 的 URL,或本地 PDF 的路径。

属性

name
str

要在 UI 中显示的 PDF 名称。

display
ElementDisplay

确定 PDF 元素在 UI 中的显示方式。选项包括“side”、“inline”或“page”。

url
str

PDF 文件的远程 URL。对于远程 PDF,必须提供 url(对于本地 PDF,必须提供 path 或 content)。

path
str

PDF 的本地文件路径。对于本地 PDF,必须提供 path 或 content(对于远程 PDF,必须提供 url)。

content
bytes

PDF 的文件内容(字节格式)。对于本地 PDF,必须提供 path 或 content(对于远程 PDF,必须提供 url)。

page
int

默认渲染的页面。必须是大于 0 且小于或等于 PDF 总页数的整数。默认值为 1。

示例

内联

import chainlit as cl


@cl.on_chat_start
async def main():
    # Sending a pdf with the local file path
    elements = [
      cl.Pdf(name="pdf1", display="inline", path="./pdf1.pdf", page=1)
    ]

    cl.Message(content="Look at this local pdf!", elements=elements).send()

侧边和页面

消息内容中必须包含 PDF 名称才能创建链接。

import chainlit as cl


@cl.on_chat_start
async def main():
    # Sending a pdf with the local file path
    elements = [
      cl.Pdf(name="pdf1", display="side", path="./pdf1.pdf", page=1)
    ]
    # Reminder: The name of the pdf must be in the content of the message
    await cl.Message(content="Look at this local pdf1!", elements=elements).send()