argilla.webhooks
¶
网络钩子是一种 Web 应用程序在发生某些事件时相互通知的方式。例如,您可能希望在新数据集在 Argilla 中创建时收到通知。
使用示例¶
要监听传入的网络钩子,您可以使用 webhook_listener
装饰器函数来注册一个在接收到 webhook 时调用的函数
from argilla.webhooks import webhook_listener
@webhook_listener(events="dataset.created")
async def my_webhook_listener(dataset):
print(dataset)
要手动创建新的 webhook,请使用客户端和名称实例化 Webhook
对象
webhook = rg.Webhook(
url="https://somehost.com/webhook",
events=["dataset.created"],
description="My webhook"
)
webhook.create()
要检索现有 webhooks 的列表,请使用 client.webhooks
属性
Webhook
¶
基类:Resource
Webhook 资源。它表示一个可用于从 Argilla 服务器接收事件的 webhook。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
url |
str
|
webhook 端点的 URL。 |
必需 |
events |
List[EventType]
|
webhook 订阅的事件。 |
必需 |
description |
Optional[str]
|
webhook 的描述。 |
无
|
_client |
Argilla
|
用于与 Argilla 服务器交互的客户端。 |
无
|
源代码位于 src/argilla/webhooks/_resource.py
webhook_listener(events, description=None, client=None, server=None, raw_event=False)
¶
用于为函数创建 webhook 监听器的装饰器。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
events |
Union[str, List[str]]
|
要监听的事件。 |
必需 |
description |
Optional[str]
|
webhook 的描述。 |
无
|
client |
Optional[Argilla]
|
要使用的 Argilla 客户端。默认为默认客户端。 |
无
|
server |
Optional[FastAPI]
|
要使用的 FastAPI 服务器。默认为默认服务器。 |
无
|
raw_event |
bool
|
是否将原始事件传递给函数。默认为 False。 |
False
|
返回值
名称 | 类型 | 描述 |
---|---|---|
Callable |
Callable
|
被装饰的函数。 |
源代码位于 src/argilla/webhooks/_helpers.py
get_webhook_server()
¶
获取当前的 webhook 服务器。如果它不存在,则会创建一个。
返回值
名称 | 类型 | 描述 |
---|---|---|
FastAPI |
FastAPI
|
webhook 服务器。 |
源代码位于 src/argilla/webhooks/_helpers.py
set_webhook_server(app)
¶
设置 webhook 服务器。这应该只被调用一次。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
app |
FastAPI
|
webhook 服务器。 |
必需 |
源代码位于 src/argilla/webhooks/_helpers.py
WebhookHandler
WebhookHandler 类用于处理传入的 webhook 请求。此类处理请求验证和事件对象创建。
属性
名称 | 类型 | 描述 |
---|---|---|
webhook |
Webhook
|
webhook 对象。 |
源代码位于 src/argilla/webhooks/_handler.py
handle(func, raw_event=False)
¶
此方法处理传入的 webhook 请求并调用提供的函数。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
func |
Callable
|
当接收到 webhook 事件时要调用的函数。 |
必需 |
raw_event |
bool
|
是否将原始事件对象传递给函数。 |
False
|
返回值
源代码位于 src/argilla/webhooks/_handler.py
WebhookEvent
基类:BaseModel
一个 webhook 事件。
属性
名称 | 类型 | 描述 |
---|---|---|
type |
EventType
|
事件的类型。 |
timestamp |
datetime
|
事件的时间戳。 |
data |
dict
|
事件的数据。 |
源代码位于 src/argilla/webhooks/_event.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
parsed(client)
¶
解析 webhook 事件。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
client |
Argilla
|
Argilla 客户端。 |
必需 |
返回值
名称 | 类型 | 描述 |
---|---|---|
Event |
Union[RecordEvent, DatasetEvent, UserResponseEvent, WebhookEvent]
|
解析后的事件。 |
源代码位于 src/argilla/webhooks/_event.py
DatasetEvent
基类:BaseModel
一个解析后的数据集事件。
属性
名称 | 类型 | 描述 |
---|---|---|
type |
EventType
|
事件的类型。 |
timestamp |
datetime
|
事件的时间戳。 |
dataset |
Dataset
|
事件的数据集。 |
源代码位于 src/argilla/webhooks/_event.py
RecordEvent
基类:BaseModel
一个解析后的记录事件。
属性
名称 | 类型 | 描述 |
---|---|---|
type |
EventType
|
事件的类型。 |
timestamp |
datetime
|
事件的时间戳。 |
record |
Record
|
事件的记录。 |
源代码位于 src/argilla/webhooks/_event.py
UserResponseEvent
基类:BaseModel
一个解析后的用户响应事件。
属性
名称 | 类型 | 描述 |
---|---|---|
type |
EventType
|
事件的类型。 |
timestamp |
datetime
|
事件的时间戳。 |
response |
UserResponse
|
事件的用户响应。 |